Header And Logo

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

Functions

tlist.c File Reference

#include "postgres.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/tlist.h"
Include dependency graph for tlist.c:

Go to the source code of this file.

Functions

TargetEntrytlist_member (Node *node, List *targetlist)
TargetEntrytlist_member_ignore_relabel (Node *node, List *targetlist)
Listflatten_tlist (List *tlist, PVCAggregateBehavior aggbehavior, PVCPlaceHolderBehavior phbehavior)
Listadd_to_flat_tlist (List *tlist, List *exprs)
Listget_tlist_exprs (List *tlist, bool includeJunk)
bool tlist_same_exprs (List *tlist1, List *tlist2)
bool tlist_same_datatypes (List *tlist, List *colTypes, bool junkOK)
bool tlist_same_collations (List *tlist, List *colCollations, bool junkOK)
TargetEntryget_sortgroupref_tle (Index sortref, List *targetList)
TargetEntryget_sortgroupclause_tle (SortGroupClause *sgClause, List *targetList)
Nodeget_sortgroupclause_expr (SortGroupClause *sgClause, List *targetList)
Listget_sortgrouplist_exprs (List *sgClauses, List *targetList)
Oidextract_grouping_ops (List *groupClause)
AttrNumberextract_grouping_cols (List *groupClause, List *tlist)
bool grouping_is_sortable (List *groupClause)
bool grouping_is_hashable (List *groupClause)

Function Documentation

List* add_to_flat_tlist ( List tlist,
List exprs 
)

Definition at line 112 of file tlist.c.

References copyObject(), lappend(), lfirst, list_length(), makeTargetEntry(), NULL, and tlist_member().

Referenced by flatten_tlist(), grouping_planner(), make_subplanTargetList(), and make_windowInputTargetList().

{
    int         next_resno = list_length(tlist) + 1;
    ListCell   *lc;

    foreach(lc, exprs)
    {
        Node       *expr = (Node *) lfirst(lc);

        if (!tlist_member(expr, tlist))
        {
            TargetEntry *tle;

            tle = makeTargetEntry(copyObject(expr),     /* copy needed?? */
                                  next_resno++,
                                  NULL,
                                  false);
            tlist = lappend(tlist, tle);
        }
    }
    return tlist;
}

AttrNumber* extract_grouping_cols ( List groupClause,
List tlist 
)

Definition at line 378 of file tlist.c.

References get_sortgroupclause_tle(), lfirst, list_length(), palloc(), and TargetEntry::resno.

Referenced by grouping_planner(), and make_union_unique().

{
    AttrNumber *grpColIdx;
    int         numCols = list_length(groupClause);
    int         colno = 0;
    ListCell   *glitem;

    grpColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols);

    foreach(glitem, groupClause)
    {
        SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem);
        TargetEntry *tle = get_sortgroupclause_tle(groupcl, tlist);

        grpColIdx[colno++] = tle->resno;
    }

    return grpColIdx;
}

Oid* extract_grouping_ops ( List groupClause  ) 

Definition at line 352 of file tlist.c.

References Assert, SortGroupClause::eqop, lfirst, list_length(), OidIsValid, and palloc().

Referenced by get_column_info_for_window(), grouping_planner(), and make_union_unique().

{
    int         numCols = list_length(groupClause);
    int         colno = 0;
    Oid        *groupOperators;
    ListCell   *glitem;

    groupOperators = (Oid *) palloc(sizeof(Oid) * numCols);

    foreach(glitem, groupClause)
    {
        SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem);

        groupOperators[colno] = groupcl->eqop;
        Assert(OidIsValid(groupOperators[colno]));
        colno++;
    }

    return groupOperators;
}

List* flatten_tlist ( List tlist,
PVCAggregateBehavior  aggbehavior,
PVCPlaceHolderBehavior  phbehavior 
)

Definition at line 89 of file tlist.c.

References add_to_flat_tlist(), list_free(), NIL, and pull_var_clause().

{
    List       *vlist = pull_var_clause((Node *) tlist,
                                        aggbehavior,
                                        phbehavior);
    List       *new_tlist;

    new_tlist = add_to_flat_tlist(NIL, vlist);
    list_free(vlist);
    return new_tlist;
}

Node* get_sortgroupclause_expr ( SortGroupClause sgClause,
List targetList 
)
TargetEntry* get_sortgroupclause_tle ( SortGroupClause sgClause,
List targetList 
)
List* get_sortgrouplist_exprs ( List sgClauses,
List targetList 
)

Definition at line 323 of file tlist.c.

References get_sortgroupclause_expr(), lappend(), and lfirst.

Referenced by query_planner().

{
    List       *result = NIL;
    ListCell   *l;

    foreach(l, sgClauses)
    {
        SortGroupClause *sortcl = (SortGroupClause *) lfirst(l);
        Node       *sortexpr;

        sortexpr = get_sortgroupclause_expr(sortcl, targetList);
        result = lappend(result, sortexpr);
    }
    return result;
}

TargetEntry* get_sortgroupref_tle ( Index  sortref,
List targetList 
)

Definition at line 276 of file tlist.c.

References elog, ERROR, lfirst, and TargetEntry::ressortgroupref.

Referenced by convert_subquery_pathkeys(), get_sortgroupclause_tle(), prepare_sort_from_pathkeys(), and transformDistinctOnClause().

{
    ListCell   *l;

    foreach(l, targetList)
    {
        TargetEntry *tle = (TargetEntry *) lfirst(l);

        if (tle->ressortgroupref == sortref)
            return tle;
    }

    elog(ERROR, "ORDER/GROUP BY expression not found in targetlist");
    return NULL;                /* keep compiler quiet */
}

List* get_tlist_exprs ( List tlist,
bool  includeJunk 
)

Definition at line 143 of file tlist.c.

References TargetEntry::expr, lappend(), lfirst, and TargetEntry::resjunk.

Referenced by recurse_set_operations().

{
    List       *result = NIL;
    ListCell   *l;

    foreach(l, tlist)
    {
        TargetEntry *tle = (TargetEntry *) lfirst(l);

        if (tle->resjunk && !includeJunk)
            continue;

        result = lappend(result, tle->expr);
    }
    return result;
}

bool grouping_is_hashable ( List groupClause  ) 

Definition at line 424 of file tlist.c.

References SortGroupClause::hashable, and lfirst.

Referenced by choose_hashed_distinct(), choose_hashed_grouping(), choose_hashed_setop(), and generate_recursion_plan().

{
    ListCell   *glitem;

    foreach(glitem, groupClause)
    {
        SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem);

        if (!groupcl->hashable)
            return false;
    }
    return true;
}

bool grouping_is_sortable ( List groupClause  ) 

Definition at line 404 of file tlist.c.

References lfirst, OidIsValid, and SortGroupClause::sortop.

Referenced by choose_hashed_distinct(), choose_hashed_grouping(), choose_hashed_setop(), make_pathkeys_for_window(), and standard_qp_callback().

{
    ListCell   *glitem;

    foreach(glitem, groupClause)
    {
        SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem);

        if (!OidIsValid(groupcl->sortop))
            return false;
    }
    return true;
}

TargetEntry* tlist_member ( Node node,
List targetlist 
)

Definition at line 32 of file tlist.c.

References equal(), TargetEntry::expr, and lfirst.

Referenced by add_to_flat_tlist(), create_unique_plan(), locate_grouping_columns(), preprocess_targetlist(), and search_indexed_tlist_for_non_var().

{
    ListCell   *temp;

    foreach(temp, targetlist)
    {
        TargetEntry *tlentry = (TargetEntry *) lfirst(temp);

        if (equal(node, tlentry->expr))
            return tlentry;
    }
    return NULL;
}

TargetEntry* tlist_member_ignore_relabel ( Node node,
List targetlist 
)

Definition at line 53 of file tlist.c.

References arg, equal(), TargetEntry::expr, IsA, and lfirst.

Referenced by prepare_sort_from_pathkeys().

{
    ListCell   *temp;

    while (node && IsA(node, RelabelType))
        node = (Node *) ((RelabelType *) node)->arg;

    foreach(temp, targetlist)
    {
        TargetEntry *tlentry = (TargetEntry *) lfirst(temp);
        Expr       *tlexpr = tlentry->expr;

        while (tlexpr && IsA(tlexpr, RelabelType))
            tlexpr = ((RelabelType *) tlexpr)->arg;

        if (equal(node, tlexpr))
            return tlentry;
    }
    return NULL;
}

bool tlist_same_collations ( List tlist,
List colCollations,
bool  junkOK 
)

Definition at line 241 of file tlist.c.

References TargetEntry::expr, exprCollation(), lfirst, lfirst_oid, list_head(), lnext, NULL, and TargetEntry::resjunk.

Referenced by recurse_set_operations().

{
    ListCell   *l;
    ListCell   *curColColl = list_head(colCollations);

    foreach(l, tlist)
    {
        TargetEntry *tle = (TargetEntry *) lfirst(l);

        if (tle->resjunk)
        {
            if (!junkOK)
                return false;
        }
        else
        {
            if (curColColl == NULL)
                return false;   /* tlist longer than colCollations */
            if (exprCollation((Node *) tle->expr) != lfirst_oid(curColColl))
                return false;
            curColColl = lnext(curColColl);
        }
    }
    if (curColColl != NULL)
        return false;           /* tlist shorter than colCollations */
    return true;
}

bool tlist_same_datatypes ( List tlist,
List colTypes,
bool  junkOK 
)

Definition at line 207 of file tlist.c.

References TargetEntry::expr, exprType(), lfirst, lfirst_oid, list_head(), lnext, NULL, and TargetEntry::resjunk.

Referenced by is_simple_union_all_recurse(), and recurse_set_operations().

{
    ListCell   *l;
    ListCell   *curColType = list_head(colTypes);

    foreach(l, tlist)
    {
        TargetEntry *tle = (TargetEntry *) lfirst(l);

        if (tle->resjunk)
        {
            if (!junkOK)
                return false;
        }
        else
        {
            if (curColType == NULL)
                return false;   /* tlist longer than colTypes */
            if (exprType((Node *) tle->expr) != lfirst_oid(curColType))
                return false;
            curColType = lnext(curColType);
        }
    }
    if (curColType != NULL)
        return false;           /* tlist shorter than colTypes */
    return true;
}

bool tlist_same_exprs ( List tlist1,
List tlist2 
)

Definition at line 177 of file tlist.c.

References equal(), TargetEntry::expr, forboth, lfirst, and list_length().

Referenced by create_unique_plan(), and grouping_planner().

{
    ListCell   *lc1,
               *lc2;

    if (list_length(tlist1) != list_length(tlist2))
        return false;           /* not same length, so can't match */

    forboth(lc1, tlist1, lc2, tlist2)
    {
        TargetEntry *tle1 = (TargetEntry *) lfirst(lc1);
        TargetEntry *tle2 = (TargetEntry *) lfirst(lc2);

        if (!equal(tle1->expr, tle2->expr))
            return false;
    }

    return true;
}