32#define IS_SRF_CALL(node) \
33 ((IsA(node, FuncExpr) && ((FuncExpr *) (node))->funcretset) || \
34 (IsA(node, OpExpr) && ((OpExpr *) (node))->opretset))
69 List **targets_contain_srfs,
70 bool is_grouping_target);
92 foreach(temp, targetlist)
115 foreach(temp, targetlist)
125 var->vartype == tlvar->vartype)
181 if (tle->resjunk && !includeJunk)
235 forboth(lc1, tlist1, lc2, tlist2)
273 if (curColType == NULL)
277 curColType =
lnext(colTypes, curColType);
280 if (curColType != NULL)
307 if (curColColl == NULL)
311 curColColl =
lnext(colCollations, curColColl);
314 if (curColColl != NULL)
333 forboth(ld, dest_tlist, ls, src_tlist)
339 dest_tle->resname = src_tle->resname;
341 dest_tle->resorigtbl = src_tle->resorigtbl;
342 dest_tle->resorigcol = src_tle->resorigcol;
343 dest_tle->resjunk = src_tle->resjunk;
358 foreach(l, targetList)
366 elog(
ERROR,
"ORDER/GROUP BY expression not found in targetlist");
406 foreach(l, sgClauses)
412 result =
lappend(result, sortexpr);
443 elog(
ERROR,
"ORDER/GROUP BY expression not found in list");
481 foreach(glitem, groupClause)
485 groupOperators[colno] = groupcl->
eqop;
490 return groupOperators;
507 foreach(glitem, groupClause)
515 return grpCollations;
532 foreach(glitem, groupClause)
537 grpColIdx[colno++] = tle->
resno;
553 foreach(glitem, groupClause)
573 foreach(glitem, groupClause)
577 if (!groupcl->hashable)
640 foreach(lc, target->
exprs)
649 if (target->sortgrouprefs)
675 if (src->sortgrouprefs)
680 memcpy(dst->sortgrouprefs, src->sortgrouprefs, nbytes);
709 if (target->sortgrouprefs)
714 target->sortgrouprefs = (
Index *)
716 target->sortgrouprefs[nexprs - 1] = sortgroupref;
718 else if (sortgroupref)
724 target->sortgrouprefs[nexprs - 1] = sortgroupref;
789 if (target->sortgrouprefs == NULL)
793 foreach(lc, target->
exprs)
798 if (target->sortgrouprefs[
i])
809 if (expr &&
IsA(expr,
Var))
821 elog(
ERROR,
"ORDER/GROUP BY expression not found in targetlist");
824 elog(
ERROR,
"targetlist item has multiple sortgroupref labels");
847 List **targets,
List **targets_contain_srfs)
850 targets, targets_contain_srfs,
870 List **targets,
List **targets_contain_srfs)
873 targets, targets_contain_srfs,
944 List **targets,
List **targets_contain_srfs,
945 bool is_grouping_target)
949 bool need_extra_projection;
950 List *prev_level_tlist;
963 if (target == input_target)
993 need_extra_projection =
false;
997 foreach(lc, target->
exprs)
1025 need_extra_projection =
false;
1034 need_extra_projection =
true;
1054 if (need_extra_projection)
1076 *targets = *targets_contain_srfs =
NIL;
1077 prev_level_tlist =
NIL;
1114 foreach(lcx, input_srfs)
1128 *targets =
lappend(*targets, ntarget);
1129 *targets_contain_srfs =
lappend_int(*targets_contain_srfs,
1130 (level_srfs !=
NIL));
1133 prev_level_tlist = ntarget->
exprs;
1146 Node *sanitized_node = node;
1295 foreach(lc, target->
exprs)
1308 if (target->sortgrouprefs == NULL)
1310 target->sortgrouprefs = (
Index *)
Bitmapset * bms_make_singleton(int x)
#define OidIsValid(objectId)
PathTarget * set_pathtarget_cost_width(PlannerInfo *root, PathTarget *target)
bool equal(const void *a, const void *b)
#define palloc_object(type)
#define palloc_array(type, count)
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * list_copy(const List *oldlist)
List * lappend_int(List *list, int datum)
bool list_member(const List *list, const void *datum)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
void * repalloc(void *pointer, Size size)
void * palloc0(Size size)
Oid exprType(const Node *expr)
Oid exprCollation(const Node *expr)
#define expression_tree_walker(n, w, c)
#define IsA(nodeptr, _type_)
#define get_pathtarget_sortgroupref(target, colno)
static int list_length(const List *l)
#define forboth(cell1, list1, cell2, list2)
#define forthree(cell1, list1, cell2, list2, cell3, list3)
#define for_each_cell(cell, lst, initcell)
static ListCell * list_nth_cell(const List *list, int n)
static ListCell * list_head(const List *l)
static ListCell * lnext(const List *l, const ListCell *c)
#define list_make1_int(x1)
Node * remove_nulling_relids(Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
VolatileFunctionStatus has_volatile_expr
List * current_input_srfs
List * input_target_exprs
List * current_input_vars
void split_pathtarget_at_srfs_grouping(PlannerInfo *root, PathTarget *target, PathTarget *input_target, List **targets, List **targets_contain_srfs)
bool tlist_same_collations(List *tlist, List *colCollations, bool junkOK)
Oid * extract_grouping_ops(List *groupClause)
TargetEntry * tlist_member(Expr *node, List *targetlist)
bool tlist_same_exprs(List *tlist1, List *tlist2)
void apply_tlist_labeling(List *dest_tlist, List *src_tlist)
SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses)
SortGroupClause * get_sortgroupref_clause(Index sortref, List *clauses)
void apply_pathtarget_labeling_to_tlist(List *tlist, PathTarget *target)
#define IS_SRF_CALL(node)
bool grouping_is_sortable(List *groupClause)
PathTarget * make_pathtarget_from_tlist(List *tlist)
static void split_pathtarget_at_srfs_extended(PlannerInfo *root, PathTarget *target, PathTarget *input_target, List **targets, List **targets_contain_srfs, bool is_grouping_target)
List * make_tlist_from_pathtarget(PathTarget *target)
PathTarget * copy_pathtarget(PathTarget *src)
static void add_sp_item_to_pathtarget(PathTarget *target, split_pathtarget_item *item)
static bool split_pathtarget_walker(Node *node, split_pathtarget_context *context)
AttrNumber * extract_grouping_cols(List *groupClause, List *tlist)
TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList)
void add_new_columns_to_pathtarget(PathTarget *target, List *exprs)
static void add_sp_items_to_pathtarget(PathTarget *target, List *items)
PathTarget * create_empty_pathtarget(void)
List * get_sortgrouplist_exprs(List *sgClauses, List *targetList)
TargetEntry * get_sortgroupref_tle(Index sortref, List *targetList)
List * add_to_flat_tlist(List *tlist, List *exprs)
int count_nonjunk_tlist_entries(List *tlist)
List * get_tlist_exprs(List *tlist, bool includeJunk)
void add_new_column_to_pathtarget(PathTarget *target, Expr *expr)
void split_pathtarget_at_srfs(PlannerInfo *root, PathTarget *target, PathTarget *input_target, List **targets, List **targets_contain_srfs)
bool grouping_is_hashable(List *groupClause)
Oid * extract_grouping_collations(List *groupClause, List *tlist)
static TargetEntry * tlist_member_match_var(Var *var, List *targetlist)
void add_column_to_pathtarget(PathTarget *target, Expr *expr, Index sortgroupref)
Node * get_sortgroupclause_expr(SortGroupClause *sgClause, List *targetList)
bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)