71 Node *testexpr,
List *testexpr_paramids,
122 if (
plan->targetlist)
164 Node *testexpr,
bool isTopQual)
167 bool simple_exists =
false;
168 double tuple_fraction;
210 tuple_fraction = 1.0;
213 tuple_fraction = 0.5;
215 tuple_fraction = 0.0;
222 tuple_fraction, NULL);
225 plan_params =
root->plan_params;
239 subroot, plan_params,
240 subLinkType, subLinkId,
241 testexpr,
NIL, isTopQual);
264 &newtestexpr, ¶mIds);
272 plan_params =
root->plan_params;
291 subroot, plan_params,
303 result = (
Node *) asplan;
304 root->hasAlternativeSubPlans =
true;
322 Node *testexpr,
List *testexpr_paramids,
335 splan->subLinkType = subLinkType;
336 splan->testexpr = NULL;
339 &
splan->firstColCollation);
340 splan->useHashTable =
false;
341 splan->unknownEqFalse = unknownEqFalse;
342 splan->parallel_safe =
plan->parallel_safe;
351 foreach(lc, plan_params)
393 result = (
Node *) prm;
408 result = (
Node *) prm;
420 elog(
ERROR,
"could not find array type for datatype %s",
428 result = (
Node *) prm;
492 if (testexpr && testexpr_paramids ==
NIL)
505 splan->testexpr = testexpr;
506 splan->paramIds = testexpr_paramids;
520 splan->useHashTable =
true;
558 if (
splan->parParam ==
NIL && !isInitPlan && !
splan->useHashTable)
564 isInitPlan ?
"InitPlan" :
"SubPlan",
599 result =
lappend(result, param);
649 context.subst_nodes = subst_nodes;
712 double subquery_size;
720 subquery_size =
plan->plan_rows *
736 double subquery_size;
744 subquery_size = path->
rows *
837 if (opid == ARRAY_EQ_OP ||
838 opid == RECORD_EQ_OP)
853 elog(
ERROR,
"cache lookup failed for operator %u", opid);
855 if (!optup->oprcanhash || !
func_strict(optup->oprcode))
884 foreach(lc,
root->parse->cteList)
899 if (cte->cterefcount == 0 && cmdType ==
CMD_SELECT)
939 cte->cterefcount == 1)) &&
940 !cte->cterecursive &&
943 (cte->cterefcount <= 1 ||
967 cte->cterecursive, 0.0, NULL);
974 if (
root->plan_params)
975 elog(
ERROR,
"unexpected outer reference in CTE query");
994 splan->testexpr = NULL;
997 &
splan->firstColCollation);
998 splan->useHashTable =
false;
999 splan->unknownEqFalse =
false;
1005 splan->parallel_safe =
false;
1108 rte->self_reference &&
1198 rte->security_barrier =
false;
1203 rte->self_reference =
false;
1204 rte->coltypes =
NIL;
1205 rte->coltypmods =
NIL;
1206 rte->colcollations =
NIL;
1262 List *subquery_vars;
1265 Relids sub_ref_outer_relids;
1321 rte = nsitem->p_rte;
1329 rtr->rtindex = rtindex;
1349 result->
larg = NULL;
1351 result->usingClause =
NIL;
1352 result->join_using_alias = NULL;
1353 result->
quals = quals;
1354 result->alias = NULL;
1369 bool under_not,
Relids available_rels)
1475 upper_varnos = NULL;
1479 if (varno <= rtoffset)
1497 subselect->
rtable, subselect->rteperminfos);
1505 result->
larg = NULL;
1511 result->usingClause =
NIL;
1512 result->join_using_alias = NULL;
1513 result->
quals = whereClause;
1514 result->alias = NULL;
1553 query->hasWindowFuncs ||
1554 query->hasTargetSRFs ||
1555 query->hasModifyingCTE ||
1586 limit = (
Const *) node;
1588 if (!limit->constisnull &&
DatumGetInt64(limit->constvalue) <= 0)
1607 query->hasDistinctOn =
false;
1613 foreach(lc, query->
rtable)
1624 Assert(query->hasGroupRTE);
1626 query->hasGroupRTE =
false;
1728 leftargs = rightargs = opids = opcollations = newWhere =
NIL;
1729 foreach(lc, (
List *) whereClause)
1741 leftargs =
lappend(leftargs, leftarg);
1742 rightargs =
lappend(rightargs, rightarg);
1744 opcollations =
lappend_oid(opcollations, expr->inputcollid);
1758 leftargs =
lappend(leftargs, rightarg);
1759 rightargs =
lappend(rightargs, leftarg);
1761 opcollations =
lappend_oid(opcollations, expr->inputcollid);
1769 newWhere =
lappend(newWhere, expr);
1775 if (leftargs ==
NIL)
1790 if (
root->parse->hasAggs &&
1828 tlist = testlist = paramids =
NIL;
1830 forfour(lc, leftargs, rc, rightargs, oc, opids, cc, opcollations)
1857 *paramIds = paramids;
1902 if (((
Var *) node)->varlevelsup > 0)
1913 if (((
Aggref *) node)->agglevelsup > 0)
1993 if (((
Aggref *) node)->agglevelsup > 0)
2041 newargs =
lappend(newargs, newarg);
2062 newargs =
lappend(newargs, newarg);
2101 if (
root->glob->paramExecTypes ==
NIL)
2110 outer_params = NULL;
2111 for (proot =
root->parent_root; proot != NULL; proot = proot->parent_root)
2135 root->outer_params = outer_params;
2156 bool unsafe_initplans;
2168 &initplan_cost, &unsafe_initplans);
2179 if (unsafe_initplans)
2187 if (unsafe_initplans)
2218 Cost *initplan_cost_p,
2219 bool *unsafe_initplans_p)
2222 bool unsafe_initplans;
2231 unsafe_initplans =
false;
2232 foreach(lc, init_plans)
2238 unsafe_initplans =
true;
2240 *initplan_cost_p = initplan_cost;
2241 *unsafe_initplans_p = unsafe_initplans;
2317 int locally_added_param;
2329 locally_added_param = -1;
2330 nestloop_params = NULL;
2337 initExtParam = initSetParam = NULL;
2338 foreach(l,
plan->initPlan)
2353 valid_params =
bms_union(valid_params, initSetParam);
2370 if (
plan->parallel_aware)
2372 if (gather_param < 0)
2373 elog(
ERROR,
"parallel-aware plan node is not below a Gather");
2410 case T_IndexOnlyScan:
2424 case T_BitmapIndexScan:
2434 case T_BitmapHeapScan:
2446 case T_TidRangeScan:
2452 case T_SubqueryScan:
2461 if (gather_param >= 0)
2465 subquery_params, NULL);
2476 case T_FunctionScan:
2498 rtfunc->funcparams = funccontext.
paramids;
2510 case T_TableFuncScan:
2540 elog(
ERROR,
"could not find plan for CteScan referencing plan ID %d",
2558 case T_WorkTableScan:
2565 case T_NamedTuplestoreScan:
2614 locally_added_param = mtplan->
epqParam;
2616 locally_added_param);
2618 locally_added_param);
2730 case T_RecursiveUnion:
2734 locally_added_param);
2742 locally_added_param);
2744 locally_added_param);
2779 locally_added_param = ((
Gather *)
plan)->rescan_param;
2780 if (locally_added_param >= 0)
2783 locally_added_param);
2790 Assert(gather_param < 0);
2792 gather_param = locally_added_param;
2800 if (locally_added_param >= 0)
2803 locally_added_param);
2810 Assert(gather_param < 0);
2812 gather_param = locally_added_param;
2825 case T_IncrementalSort:
2833 elog(
ERROR,
"unrecognized node type: %d",
2845 if (nestloop_params)
2851 bms_union(nestloop_params, valid_params),
2874 if (locally_added_param >= 0)
2877 locally_added_param);
2883 elog(
ERROR,
"plan should not reference subplan's variable");
2901 return plan->allParam;
2917 int paramid = ((
Param *) node)->paramid;
2937 if (aggparam != NULL)
3019 Oid resulttype,
int32 resulttypmod,
3020 Oid resultcollation)
3023 resulttypmod, resultcollation);
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
void bms_free(Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
#define Assert(condition)
#define OidIsValid(objectId)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
bool contain_subplans(Node *clause)
bool contain_volatile_functions(Node *clause)
bool contain_exec_param(Node *clause, List *param_ids)
void cost_subplan(PlannerInfo *root, SubPlan *subplan, Plan *plan)
Plan * materialize_finished_plan(Plan *subplan)
Plan * create_plan(PlannerInfo *root, Path *best_path)
bool ExecMaterializesOutput(NodeTag plantype)
#define HeapTupleIsValid(tuple)
#define SizeofHeapTupleHeader
List * lappend(List *list, void *datum)
List * list_concat(List *list1, const List *list2)
List * list_delete_cell(List *list, ListCell *cell)
List * list_copy(const List *oldlist)
List * lappend_int(List *list, int datum)
List * lappend_oid(List *list, Oid datum)
bool op_hashjoinable(Oid opno, Oid inputtype)
bool func_strict(Oid funcid)
Oid get_promoted_array_type(Oid typid)
Oid get_commutator(Oid opno)
Alias * makeAlias(const char *aliasname, List *colnames)
Expr * make_orclause(List *orclauses)
Expr * make_ands_explicit(List *andclauses)
Var * makeVarFromTargetEntry(int varno, TargetEntry *tle)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Expr * make_andclause(List *andclauses)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Expr * make_opclause(Oid opno, Oid opresulttype, bool opretset, Expr *leftop, Expr *rightop, Oid opcollid, Oid inputcollid)
List * make_ands_implicit(Expr *clause)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Oid exprCollation(const Node *expr)
#define expression_tree_mutator(n, m, c)
static bool is_andclause(const void *clause)
static bool is_orclause(const void *clause)
#define query_tree_walker(q, w, c, f)
#define QTW_EXAMINE_RTES_AFTER
#define expression_tree_walker(n, w, c)
#define QTW_EXAMINE_RTES_BEFORE
size_t get_hash_memory_limit(void)
#define IsA(nodeptr, _type_)
#define castNode(_type_, nodeptr)
Param * replace_outer_merge_support(PlannerInfo *root, MergeSupportFunc *msf)
Param * generate_new_exec_param(PlannerInfo *root, Oid paramtype, int32 paramtypmod, Oid paramcollation)
Param * replace_outer_agg(PlannerInfo *root, Aggref *agg)
Param * replace_outer_grouping(PlannerInfo *root, GroupingFunc *grp)
Param * replace_outer_var(PlannerInfo *root, Var *var)
Param * replace_outer_placeholdervar(PlannerInfo *root, PlaceHolderVar *phv)
int assign_special_exec_param(PlannerInfo *root)
ParseState * make_parsestate(ParseState *parentParseState)
ParseNamespaceItem * addRangeTableEntryForSubquery(ParseState *pstate, Query *subquery, Alias *alias, bool lateral, bool inFromCl)
#define planner_subplan_get_plan(root, subplan)
#define lfirst_node(type, lc)
static int list_length(const List *l)
#define linitial_node(type, l)
static void * list_nth(const List *list, int n)
static ListCell * list_nth_cell(const List *list, int n)
#define forfour(cell1, list1, cell2, list2, cell3, list3, cell4, list4)
#define list_make1_int(x1)
#define list_make2(x1, x2)
FormData_pg_operator * Form_pg_operator
Path * get_cheapest_fractional_path(RelOptInfo *rel, double tuple_fraction)
PlannerInfo * subquery_planner(PlannerGlobal *glob, Query *parse, PlannerInfo *parent_root, bool hasRecursion, double tuple_fraction, SetOperationStmt *setops)
static int64 DatumGetInt64(Datum X)
static Datum ObjectIdGetDatum(Oid X)
void replace_empty_jointree(Query *parse)
Expr * canonicalize_qual(Expr *qual, bool is_check)
char * psprintf(const char *fmt,...)
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
RelOptInfo * fetch_upper_rel(PlannerInfo *root, UpperRelationKind kind, Relids relids)
void OffsetVarNodes(Node *node, int offset, int sublevels_up)
void CombineRangeTables(List **dst_rtable, List **dst_perminfos, List *src_rtable, List *src_perminfos)
bool contain_aggs_of_level(Node *node, int levelsup)
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
Param * find_minmax_agg_replacement_param(PlannerInfo *root, Aggref *aggref)
CTEMaterialize ctematerialized
struct Path * cheapest_total_path
JoinExpr * convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink, Relids available_rels)
static bool contain_dml_walker(Node *node, void *context)
static bool testexpr_is_hashable(Node *testexpr, List *param_ids)
Node * SS_process_sublinks(PlannerInfo *root, Node *expr, bool isQual)
void SS_process_ctes(PlannerInfo *root)
void SS_identify_outer_params(PlannerInfo *root)
static bool finalize_agg_primnode(Node *node, finalize_primnode_context *context)
static bool contain_outer_selfref(Node *node)
static List * generate_subquery_vars(PlannerInfo *root, List *tlist, Index varno)
Node * SS_replace_correlation_vars(PlannerInfo *root, Node *expr)
static bool contain_dml(Node *node)
void SS_finalize_plan(PlannerInfo *root, Plan *plan)
static Query * convert_EXISTS_to_ANY(PlannerInfo *root, Query *subselect, Node **testexpr, List **paramIds)
static Node * process_sublinks_mutator(Node *node, process_sublinks_context *context)
struct process_sublinks_context process_sublinks_context
static Node * replace_correlation_vars_mutator(Node *node, PlannerInfo *root)
static bool test_opexpr_is_hashable(OpExpr *testexpr, List *param_ids)
static List * generate_subquery_params(PlannerInfo *root, List *tlist, List **paramIds)
static Node * convert_testexpr(PlannerInfo *root, Node *testexpr, List *subst_nodes)
static bool subpath_is_hashable(Path *path)
static Node * make_subplan(PlannerInfo *root, Query *orig_subquery, SubLinkType subLinkType, int subLinkId, Node *testexpr, bool isTopQual)
static bool contain_outer_selfref_walker(Node *node, Index *depth)
struct convert_testexpr_context convert_testexpr_context
static bool hash_ok_operator(OpExpr *expr)
static void inline_cte(PlannerInfo *root, CommonTableExpr *cte)
static bool subplan_is_hashable(Plan *plan)
static bool simplify_EXISTS_query(PlannerInfo *root, Query *query)
struct finalize_primnode_context finalize_primnode_context
static bool finalize_primnode(Node *node, finalize_primnode_context *context)
static void get_first_col_type(Plan *plan, Oid *coltype, int32 *coltypmod, Oid *colcollation)
static bool inline_cte_walker(Node *node, inline_cte_walker_context *context)
void SS_attach_initplans(PlannerInfo *root, Plan *plan)
JoinExpr * convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink, bool under_not, Relids available_rels)
void SS_compute_initplan_cost(List *init_plans, Cost *initplan_cost_p, bool *unsafe_initplans_p)
void SS_charge_for_initplans(PlannerInfo *root, RelOptInfo *final_rel)
static Node * convert_testexpr_mutator(Node *node, convert_testexpr_context *context)
Param * SS_make_initplan_output_param(PlannerInfo *root, Oid resulttype, int32 resulttypmod, Oid resultcollation)
struct inline_cte_walker_context inline_cte_walker_context
static Node * build_subplan(PlannerInfo *root, Plan *plan, Path *path, PlannerInfo *subroot, List *plan_params, SubLinkType subLinkType, int subLinkId, Node *testexpr, List *testexpr_paramids, bool unknownEqFalse)
void SS_make_initplan_from_plan(PlannerInfo *root, PlannerInfo *subroot, Plan *plan, Param *prm)
static Bitmapset * finalize_plan(PlannerInfo *root, Plan *plan, int gather_param, Bitmapset *valid_params, Bitmapset *scan_params)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
bool contain_vars_of_level(Node *node, int levelsup)
bool contain_var_clause(Node *node)
Relids pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup)
Relids pull_varnos(PlannerInfo *root, Node *node)