Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

joininfo.h File Reference

#include "nodes/relation.h"
Include dependency graph for joininfo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool have_relevant_joinclause (PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
void add_join_clause_to_rels (PlannerInfo *root, RestrictInfo *restrictinfo, Relids join_relids)
void remove_join_clause_from_rels (PlannerInfo *root, RestrictInfo *restrictinfo, Relids join_relids)

Function Documentation

void add_join_clause_to_rels ( PlannerInfo root,
RestrictInfo restrictinfo,
Relids  join_relids 
)

Definition at line 95 of file joininfo.c.

References bms_copy(), bms_first_member(), bms_free(), find_base_rel(), RelOptInfo::joininfo, and lappend().

Referenced by distribute_restrictinfo_to_rels().

{
    Relids      tmprelids;
    int         cur_relid;

    tmprelids = bms_copy(join_relids);
    while ((cur_relid = bms_first_member(tmprelids)) >= 0)
    {
        RelOptInfo *rel = find_base_rel(root, cur_relid);

        rel->joininfo = lappend(rel->joininfo, restrictinfo);
    }
    bms_free(tmprelids);
}

bool have_relevant_joinclause ( PlannerInfo root,
RelOptInfo rel1,
RelOptInfo rel2 
)

Definition at line 36 of file joininfo.c.

References bms_overlap(), RelOptInfo::has_eclass_joins, have_relevant_eclass_joinclause(), RelOptInfo::joininfo, lfirst, list_length(), RelOptInfo::relids, and RestrictInfo::required_relids.

Referenced by desirable_join(), has_legal_joinclause(), join_search_one_level(), and make_rels_by_clause_joins().

{
    bool        result = false;
    List       *joininfo;
    Relids      other_relids;
    ListCell   *l;

    /*
     * We could scan either relation's joininfo list; may as well use the
     * shorter one.
     */
    if (list_length(rel1->joininfo) <= list_length(rel2->joininfo))
    {
        joininfo = rel1->joininfo;
        other_relids = rel2->relids;
    }
    else
    {
        joininfo = rel2->joininfo;
        other_relids = rel1->relids;
    }

    foreach(l, joininfo)
    {
        RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);

        if (bms_overlap(other_relids, rinfo->required_relids))
        {
            result = true;
            break;
        }
    }

    /*
     * We also need to check the EquivalenceClass data structure, which might
     * contain relationships not emitted into the joininfo lists.
     */
    if (!result && rel1->has_eclass_joins && rel2->has_eclass_joins)
        result = have_relevant_eclass_joinclause(root, rel1, rel2);

    return result;
}

void remove_join_clause_from_rels ( PlannerInfo root,
RestrictInfo restrictinfo,
Relids  join_relids 
)

Definition at line 124 of file joininfo.c.

References Assert, bms_copy(), bms_first_member(), bms_free(), find_base_rel(), RelOptInfo::joininfo, list_delete_ptr(), and list_member_ptr().

Referenced by remove_rel_from_query().

{
    Relids      tmprelids;
    int         cur_relid;

    tmprelids = bms_copy(join_relids);
    while ((cur_relid = bms_first_member(tmprelids)) >= 0)
    {
        RelOptInfo *rel = find_base_rel(root, cur_relid);

        /*
         * Remove the restrictinfo from the list.  Pointer comparison is
         * sufficient.
         */
        Assert(list_member_ptr(rel->joininfo, restrictinfo));
        rel->joininfo = list_delete_ptr(rel->joininfo, restrictinfo);
    }
    bms_free(tmprelids);
}