mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef list
provided by Andrew.
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.149 2009/04/25 16:44:56 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.150 2009/06/11 14:48:59 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -56,9 +56,9 @@ static Node *build_subplan(PlannerInfo *root, Plan *plan, List *rtable,
|
||||
SubLinkType subLinkType, Node *testexpr,
|
||||
bool adjust_testexpr, bool unknownEqFalse);
|
||||
static List *generate_subquery_params(PlannerInfo *root, List *tlist,
|
||||
List **paramIds);
|
||||
List **paramIds);
|
||||
static List *generate_subquery_vars(PlannerInfo *root, List *tlist,
|
||||
Index varno);
|
||||
Index varno);
|
||||
static Node *convert_testexpr(PlannerInfo *root,
|
||||
Node *testexpr,
|
||||
List *subst_nodes);
|
||||
@ -308,7 +308,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery, SubLinkType subLinkType,
|
||||
* path/costsize.c.
|
||||
*
|
||||
* XXX If an ANY subplan is uncorrelated, build_subplan may decide to hash
|
||||
* its output. In that case it would've been better to specify full
|
||||
* its output. In that case it would've been better to specify full
|
||||
* retrieval. At present, however, we can only check hashability after
|
||||
* we've made the subplan :-(. (Determining whether it'll fit in work_mem
|
||||
* is the really hard part.) Therefore, we don't want to be too
|
||||
@ -338,11 +338,11 @@ make_subplan(PlannerInfo *root, Query *orig_subquery, SubLinkType subLinkType,
|
||||
/*
|
||||
* If it's a correlated EXISTS with an unimportant targetlist, we might be
|
||||
* able to transform it to the equivalent of an IN and then implement it
|
||||
* by hashing. We don't have enough information yet to tell which way
|
||||
* is likely to be better (it depends on the expected number of executions
|
||||
* of the EXISTS qual, and we are much too early in planning the outer
|
||||
* query to be able to guess that). So we generate both plans, if
|
||||
* possible, and leave it to the executor to decide which to use.
|
||||
* by hashing. We don't have enough information yet to tell which way is
|
||||
* likely to be better (it depends on the expected number of executions of
|
||||
* the EXISTS qual, and we are much too early in planning the outer query
|
||||
* to be able to guess that). So we generate both plans, if possible, and
|
||||
* leave it to the executor to decide which to use.
|
||||
*/
|
||||
if (simple_exists && IsA(result, SubPlan))
|
||||
{
|
||||
@ -368,7 +368,7 @@ make_subplan(PlannerInfo *root, Query *orig_subquery, SubLinkType subLinkType,
|
||||
/* Now we can check if it'll fit in work_mem */
|
||||
if (subplan_is_hashable(plan))
|
||||
{
|
||||
SubPlan *hashplan;
|
||||
SubPlan *hashplan;
|
||||
AlternativeSubPlan *asplan;
|
||||
|
||||
/* OK, convert to SubPlan format. */
|
||||
@ -437,7 +437,7 @@ build_subplan(PlannerInfo *root, Plan *plan, List *rtable,
|
||||
|
||||
if (pitem->abslevel == root->query_level)
|
||||
{
|
||||
Node *arg;
|
||||
Node *arg;
|
||||
|
||||
/*
|
||||
* The Var or Aggref has already been adjusted to have the correct
|
||||
@ -447,8 +447,8 @@ build_subplan(PlannerInfo *root, Plan *plan, List *rtable,
|
||||
arg = copyObject(pitem->item);
|
||||
|
||||
/*
|
||||
* If it's an Aggref, its arguments might contain SubLinks,
|
||||
* which have not yet been processed. Do that now.
|
||||
* If it's an Aggref, its arguments might contain SubLinks, which
|
||||
* have not yet been processed. Do that now.
|
||||
*/
|
||||
if (IsA(arg, Aggref))
|
||||
arg = SS_process_sublinks(root, arg, false);
|
||||
@ -714,7 +714,7 @@ generate_subquery_vars(PlannerInfo *root, List *tlist, Index varno)
|
||||
/*
|
||||
* convert_testexpr: convert the testexpr given by the parser into
|
||||
* actually executable form. This entails replacing PARAM_SUBLINK Params
|
||||
* with Params or Vars representing the results of the sub-select. The
|
||||
* with Params or Vars representing the results of the sub-select. The
|
||||
* nodes to be substituted are passed in as the List result from
|
||||
* generate_subquery_params or generate_subquery_vars.
|
||||
*
|
||||
@ -794,8 +794,8 @@ static bool
|
||||
testexpr_is_hashable(Node *testexpr)
|
||||
{
|
||||
/*
|
||||
* The testexpr must be a single OpExpr, or an AND-clause containing
|
||||
* only OpExprs.
|
||||
* The testexpr must be a single OpExpr, or an AND-clause containing only
|
||||
* OpExprs.
|
||||
*
|
||||
* The combining operators must be hashable and strict. The need for
|
||||
* hashability is obvious, since we want to use hashing. Without
|
||||
@ -892,8 +892,8 @@ SS_process_ctes(PlannerInfo *root)
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy the source Query node. Probably not necessary, but let's
|
||||
* keep this similar to make_subplan.
|
||||
* Copy the source Query node. Probably not necessary, but let's keep
|
||||
* this similar to make_subplan.
|
||||
*/
|
||||
subquery = (Query *) copyObject(cte->ctequery);
|
||||
|
||||
@ -907,7 +907,7 @@ SS_process_ctes(PlannerInfo *root)
|
||||
&subroot);
|
||||
|
||||
/*
|
||||
* Make a SubPlan node for it. This is just enough unlike
|
||||
* Make a SubPlan node for it. This is just enough unlike
|
||||
* build_subplan that we can't share code.
|
||||
*
|
||||
* Note plan_id, plan_name, and cost fields are set further down.
|
||||
@ -925,8 +925,8 @@ SS_process_ctes(PlannerInfo *root)
|
||||
|
||||
/*
|
||||
* Make parParam and args lists of param IDs and expressions that
|
||||
* current query level will pass to this child plan. Even though
|
||||
* this is an initplan, there could be side-references to earlier
|
||||
* current query level will pass to this child plan. Even though this
|
||||
* is an initplan, there could be side-references to earlier
|
||||
* initplan's outputs, specifically their CTE output parameters.
|
||||
*/
|
||||
tmpset = bms_copy(plan->extParam);
|
||||
@ -948,8 +948,8 @@ SS_process_ctes(PlannerInfo *root)
|
||||
bms_free(tmpset);
|
||||
|
||||
/*
|
||||
* Assign a param to represent the query output. We only really
|
||||
* care about reserving a parameter ID number.
|
||||
* Assign a param to represent the query output. We only really care
|
||||
* about reserving a parameter ID number.
|
||||
*/
|
||||
prm = generate_new_param(root, INTERNALOID, -1);
|
||||
splan->setParam = list_make1_int(prm->paramid);
|
||||
@ -1028,9 +1028,9 @@ convert_ANY_sublink_to_join(PlannerInfo *root, SubLink *sublink,
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* The test expression must contain some Vars of the parent query,
|
||||
* else it's not gonna be a join. (Note that it won't have Vars
|
||||
* referring to the subquery, rather Params.)
|
||||
* The test expression must contain some Vars of the parent query, else
|
||||
* it's not gonna be a join. (Note that it won't have Vars referring to
|
||||
* the subquery, rather Params.)
|
||||
*/
|
||||
upper_varnos = pull_varnos(sublink->testexpr);
|
||||
if (bms_is_empty(upper_varnos))
|
||||
@ -1126,10 +1126,10 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
|
||||
subselect = (Query *) copyObject(subselect);
|
||||
|
||||
/*
|
||||
* See if the subquery can be simplified based on the knowledge that
|
||||
* it's being used in EXISTS(). If we aren't able to get rid of its
|
||||
* targetlist, we have to fail, because the pullup operation leaves
|
||||
* us with noplace to evaluate the targetlist.
|
||||
* See if the subquery can be simplified based on the knowledge that it's
|
||||
* being used in EXISTS(). If we aren't able to get rid of its
|
||||
* targetlist, we have to fail, because the pullup operation leaves us
|
||||
* with noplace to evaluate the targetlist.
|
||||
*/
|
||||
if (!simplify_EXISTS_query(subselect))
|
||||
return NULL;
|
||||
@ -1175,13 +1175,13 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
|
||||
* to the inner (necessarily true). Therefore this is a lot easier than
|
||||
* what pull_up_subqueries has to go through.
|
||||
*
|
||||
* In fact, it's even easier than what convert_ANY_sublink_to_join has
|
||||
* to do. The machinations of simplify_EXISTS_query ensured that there
|
||||
* is nothing interesting in the subquery except an rtable and jointree,
|
||||
* and even the jointree FromExpr no longer has quals. So we can just
|
||||
* append the rtable to our own and use the FromExpr in our jointree.
|
||||
* But first, adjust all level-zero varnos in the subquery to account
|
||||
* for the rtable merger.
|
||||
* In fact, it's even easier than what convert_ANY_sublink_to_join has to
|
||||
* do. The machinations of simplify_EXISTS_query ensured that there is
|
||||
* nothing interesting in the subquery except an rtable and jointree, and
|
||||
* even the jointree FromExpr no longer has quals. So we can just append
|
||||
* the rtable to our own and use the FromExpr in our jointree. But first,
|
||||
* adjust all level-zero varnos in the subquery to account for the rtable
|
||||
* merger.
|
||||
*/
|
||||
rtoffset = list_length(parse->rtable);
|
||||
OffsetVarNodes((Node *) subselect, rtoffset, 0);
|
||||
@ -1198,8 +1198,8 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
|
||||
/*
|
||||
* Now that the WHERE clause is adjusted to match the parent query
|
||||
* environment, we can easily identify all the level-zero rels it uses.
|
||||
* The ones <= rtoffset belong to the upper query; the ones > rtoffset
|
||||
* do not.
|
||||
* The ones <= rtoffset belong to the upper query; the ones > rtoffset do
|
||||
* not.
|
||||
*/
|
||||
clause_varnos = pull_varnos(whereClause);
|
||||
upper_varnos = NULL;
|
||||
@ -1212,8 +1212,8 @@ convert_EXISTS_sublink_to_join(PlannerInfo *root, SubLink *sublink,
|
||||
Assert(!bms_is_empty(upper_varnos));
|
||||
|
||||
/*
|
||||
* Now that we've got the set of upper-level varnos, we can make the
|
||||
* last check: only available_rels can be referenced.
|
||||
* Now that we've got the set of upper-level varnos, we can make the last
|
||||
* check: only available_rels can be referenced.
|
||||
*/
|
||||
if (!bms_is_subset(upper_varnos, available_rels))
|
||||
return NULL;
|
||||
@ -1308,7 +1308,7 @@ simplify_EXISTS_query(Query *query)
|
||||
*
|
||||
* On success, the modified subselect is returned, and we store a suitable
|
||||
* upper-level test expression at *testexpr, plus a list of the subselect's
|
||||
* output Params at *paramIds. (The test expression is already Param-ified
|
||||
* output Params at *paramIds. (The test expression is already Param-ified
|
||||
* and hence need not go through convert_testexpr, which is why we have to
|
||||
* deal with the Param IDs specially.)
|
||||
*
|
||||
@ -1365,32 +1365,32 @@ convert_EXISTS_to_ANY(PlannerInfo *root, Query *subselect,
|
||||
/*
|
||||
* Clean up the WHERE clause by doing const-simplification etc on it.
|
||||
* Aside from simplifying the processing we're about to do, this is
|
||||
* important for being able to pull chunks of the WHERE clause up into
|
||||
* the parent query. Since we are invoked partway through the parent's
|
||||
* important for being able to pull chunks of the WHERE clause up into the
|
||||
* parent query. Since we are invoked partway through the parent's
|
||||
* preprocess_expression() work, earlier steps of preprocess_expression()
|
||||
* wouldn't get applied to the pulled-up stuff unless we do them here.
|
||||
* For the parts of the WHERE clause that get put back into the child
|
||||
* query, this work is partially duplicative, but it shouldn't hurt.
|
||||
* wouldn't get applied to the pulled-up stuff unless we do them here. For
|
||||
* the parts of the WHERE clause that get put back into the child query,
|
||||
* this work is partially duplicative, but it shouldn't hurt.
|
||||
*
|
||||
* Note: we do not run flatten_join_alias_vars. This is OK because
|
||||
* any parent aliases were flattened already, and we're not going to
|
||||
* pull any child Vars (of any description) into the parent.
|
||||
* Note: we do not run flatten_join_alias_vars. This is OK because any
|
||||
* parent aliases were flattened already, and we're not going to pull any
|
||||
* child Vars (of any description) into the parent.
|
||||
*
|
||||
* Note: passing the parent's root to eval_const_expressions is technically
|
||||
* wrong, but we can get away with it since only the boundParams (if any)
|
||||
* are used, and those would be the same in a subroot.
|
||||
* Note: passing the parent's root to eval_const_expressions is
|
||||
* technically wrong, but we can get away with it since only the
|
||||
* boundParams (if any) are used, and those would be the same in a
|
||||
* subroot.
|
||||
*/
|
||||
whereClause = eval_const_expressions(root, whereClause);
|
||||
whereClause = (Node *) canonicalize_qual((Expr *) whereClause);
|
||||
whereClause = (Node *) make_ands_implicit((Expr *) whereClause);
|
||||
|
||||
/*
|
||||
* We now have a flattened implicit-AND list of clauses, which we
|
||||
* try to break apart into "outervar = innervar" hash clauses.
|
||||
* Anything that can't be broken apart just goes back into the
|
||||
* newWhere list. Note that we aren't trying hard yet to ensure
|
||||
* that we have only outer or only inner on each side; we'll check
|
||||
* that if we get to the end.
|
||||
* We now have a flattened implicit-AND list of clauses, which we try to
|
||||
* break apart into "outervar = innervar" hash clauses. Anything that
|
||||
* can't be broken apart just goes back into the newWhere list. Note that
|
||||
* we aren't trying hard yet to ensure that we have only outer or only
|
||||
* inner on each side; we'll check that if we get to the end.
|
||||
*/
|
||||
leftargs = rightargs = opids = newWhere = NIL;
|
||||
foreach(lc, (List *) whereClause)
|
||||
@ -1400,8 +1400,8 @@ convert_EXISTS_to_ANY(PlannerInfo *root, Query *subselect,
|
||||
if (IsA(expr, OpExpr) &&
|
||||
hash_ok_operator(expr))
|
||||
{
|
||||
Node *leftarg = (Node *) linitial(expr->args);
|
||||
Node *rightarg = (Node *) lsecond(expr->args);
|
||||
Node *leftarg = (Node *) linitial(expr->args);
|
||||
Node *rightarg = (Node *) lsecond(expr->args);
|
||||
|
||||
if (contain_vars_of_level(leftarg, 1))
|
||||
{
|
||||
@ -1459,15 +1459,15 @@ convert_EXISTS_to_ANY(PlannerInfo *root, Query *subselect,
|
||||
|
||||
/*
|
||||
* And there can't be any child Vars in the stuff we intend to pull up.
|
||||
* (Note: we'd need to check for child Aggs too, except we know the
|
||||
* child has no aggs at all because of simplify_EXISTS_query's check.
|
||||
* The same goes for window functions.)
|
||||
* (Note: we'd need to check for child Aggs too, except we know the child
|
||||
* has no aggs at all because of simplify_EXISTS_query's check. The same
|
||||
* goes for window functions.)
|
||||
*/
|
||||
if (contain_vars_of_level((Node *) leftargs, 0))
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Also reject sublinks in the stuff we intend to pull up. (It might be
|
||||
* Also reject sublinks in the stuff we intend to pull up. (It might be
|
||||
* possible to support this, but doesn't seem worth the complication.)
|
||||
*/
|
||||
if (contain_subplans((Node *) leftargs))
|
||||
@ -1485,11 +1485,10 @@ convert_EXISTS_to_ANY(PlannerInfo *root, Query *subselect,
|
||||
subselect->jointree->quals = (Node *) make_ands_explicit(newWhere);
|
||||
|
||||
/*
|
||||
* Build a new targetlist for the child that emits the expressions
|
||||
* we need. Concurrently, build a testexpr for the parent using
|
||||
* Params to reference the child outputs. (Since we generate Params
|
||||
* directly here, there will be no need to convert the testexpr in
|
||||
* build_subplan.)
|
||||
* Build a new targetlist for the child that emits the expressions we
|
||||
* need. Concurrently, build a testexpr for the parent using Params to
|
||||
* reference the child outputs. (Since we generate Params directly here,
|
||||
* there will be no need to convert the testexpr in build_subplan.)
|
||||
*/
|
||||
tlist = testlist = paramids = NIL;
|
||||
resno = 1;
|
||||
@ -1625,10 +1624,10 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't recurse into the arguments of an outer aggregate here.
|
||||
* Any SubLinks in the arguments have to be dealt with at the outer
|
||||
* query level; they'll be handled when build_subplan collects the
|
||||
* Aggref into the arguments to be passed down to the current subplan.
|
||||
* Don't recurse into the arguments of an outer aggregate here. Any
|
||||
* SubLinks in the arguments have to be dealt with at the outer query
|
||||
* level; they'll be handled when build_subplan collects the Aggref into
|
||||
* the arguments to be passed down to the current subplan.
|
||||
*/
|
||||
if (IsA(node, Aggref))
|
||||
{
|
||||
@ -1655,7 +1654,7 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
|
||||
* is needed for a bare List.)
|
||||
*
|
||||
* Anywhere within the top-level AND/OR clause structure, we can tell
|
||||
* make_subplan() that NULL and FALSE are interchangeable. So isTopQual
|
||||
* make_subplan() that NULL and FALSE are interchangeable. So isTopQual
|
||||
* propagates down in both cases. (Note that this is unlike the meaning
|
||||
* of "top level qual" used in most other places in Postgres.)
|
||||
*/
|
||||
@ -1702,8 +1701,8 @@ process_sublinks_mutator(Node *node, process_sublinks_context *context)
|
||||
}
|
||||
|
||||
/*
|
||||
* If we recurse down through anything other than an AND or OR node,
|
||||
* we are definitely not at top qual level anymore.
|
||||
* If we recurse down through anything other than an AND or OR node, we
|
||||
* are definitely not at top qual level anymore.
|
||||
*/
|
||||
locContext.isTopQual = false;
|
||||
|
||||
@ -1759,8 +1758,8 @@ SS_finalize_plan(PlannerInfo *root, Plan *plan, bool attach_initplans)
|
||||
/*
|
||||
* Now determine the set of params that are validly referenceable in this
|
||||
* query level; to wit, those available from outer query levels plus the
|
||||
* output parameters of any initPlans. (We do not include output
|
||||
* parameters of regular subplans. Those should only appear within the
|
||||
* output parameters of any initPlans. (We do not include output
|
||||
* parameters of regular subplans. Those should only appear within the
|
||||
* testexpr of SubPlan nodes, and are taken care of locally within
|
||||
* finalize_primnode.)
|
||||
*
|
||||
@ -1809,7 +1808,7 @@ SS_finalize_plan(PlannerInfo *root, Plan *plan, bool attach_initplans)
|
||||
if (attach_initplans)
|
||||
{
|
||||
plan->initPlan = root->init_plans;
|
||||
root->init_plans = NIL; /* make sure they're not attached twice */
|
||||
root->init_plans = NIL; /* make sure they're not attached twice */
|
||||
|
||||
/* allParam must include all these params */
|
||||
plan->allParam = bms_add_members(plan->allParam, initExtParam);
|
||||
@ -2043,9 +2042,9 @@ finalize_plan(PlannerInfo *root, Plan *plan, Bitmapset *valid_params)
|
||||
|
||||
/*
|
||||
* Note: by definition, extParam and allParam should have the same value
|
||||
* in any plan node that doesn't have child initPlans. We set them
|
||||
* equal here, and later SS_finalize_plan will update them properly
|
||||
* in node(s) that it attaches initPlans to.
|
||||
* in any plan node that doesn't have child initPlans. We set them equal
|
||||
* here, and later SS_finalize_plan will update them properly in node(s)
|
||||
* that it attaches initPlans to.
|
||||
*
|
||||
* For speed at execution time, make sure extParam/allParam are actually
|
||||
* NULL if they are empty sets.
|
||||
@ -2095,7 +2094,7 @@ finalize_primnode(Node *node, finalize_primnode_context *context)
|
||||
|
||||
/*
|
||||
* Remove any param IDs of output parameters of the subplan that were
|
||||
* referenced in the testexpr. These are not interesting for
|
||||
* referenced in the testexpr. These are not interesting for
|
||||
* parameter change signaling since we always re-evaluate the subplan.
|
||||
* Note that this wouldn't work too well if there might be uses of the
|
||||
* same param IDs elsewhere in the plan, but that can't happen because
|
||||
@ -2167,9 +2166,9 @@ SS_make_initplan_from_plan(PlannerInfo *root, Plan *plan,
|
||||
root->parse->rtable);
|
||||
|
||||
/*
|
||||
* Create a SubPlan node and add it to the outer list of InitPlans.
|
||||
* Note it has to appear after any other InitPlans it might depend on
|
||||
* (see comments in ExecReScan).
|
||||
* Create a SubPlan node and add it to the outer list of InitPlans. Note
|
||||
* it has to appear after any other InitPlans it might depend on (see
|
||||
* comments in ExecReScan).
|
||||
*/
|
||||
node = makeNode(SubPlan);
|
||||
node->subLinkType = EXPR_SUBLINK;
|
||||
|
Reference in New Issue
Block a user