diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2006-07-01 18:38:33 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2006-07-01 18:38:33 +0000 |
commit | cffd89ca736e485309cd51ae056f837bd7e683ad (patch) | |
tree | 7ebf13ae5d921d074382d80be66a8d97e7a822e1 /src/backend/optimizer/plan/planmain.c | |
parent | 68628fc38ea7a3c72f6a813b0193d836731d9c10 (diff) | |
download | postgresql-cffd89ca736e485309cd51ae056f837bd7e683ad.tar.gz postgresql-cffd89ca736e485309cd51ae056f837bd7e683ad.zip |
Revise the planner's handling of "pseudoconstant" WHERE clauses, that is
clauses containing no variables and no volatile functions. Such a clause
can be used as a one-time qual in a gating Result plan node, to suppress
plan execution entirely when it is false. Even when the clause is true,
putting it in a gating node wins by avoiding repeated evaluation of the
clause. In previous PG releases, query_planner() would do this for
pseudoconstant clauses appearing at the top level of the jointree, but
there was no ability to generate a gating Result deeper in the plan tree.
To fix it, get rid of the special case in query_planner(), and instead
process pseudoconstant clauses through the normal RestrictInfo qual
distribution mechanism. When a pseudoconstant clause is found attached to
a path node in create_plan(), pull it out and generate a gating Result at
that point. This requires special-casing pseudoconstants in selectivity
estimation and cost_qual_eval, but on the whole it's pretty clean.
It probably even makes the planner a bit faster than before for the normal
case of no pseudoconstants, since removing pull_constant_clauses saves one
useless traversal of the qual tree. Per gripe from Phil Frost.
Diffstat (limited to 'src/backend/optimizer/plan/planmain.c')
-rw-r--r-- | src/backend/optimizer/plan/planmain.c | 35 |
1 files changed, 3 insertions, 32 deletions
diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index bc1438a4672..2ad786ce646 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.93 2006/03/05 15:58:29 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/planmain.c,v 1.94 2006/07/01 18:38:33 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -82,7 +82,6 @@ query_planner(PlannerInfo *root, List *tlist, double tuple_fraction, double *num_groups) { Query *parse = root->parse; - List *constant_quals; List *joinlist; RelOptInfo *final_rel; Path *cheapestpath; @@ -99,27 +98,13 @@ query_planner(PlannerInfo *root, List *tlist, double tuple_fraction, */ if (parse->jointree->fromlist == NIL) { - *cheapest_path = (Path *) create_result_path(NULL, NULL, - (List *) parse->jointree->quals); + *cheapest_path = (Path *) + create_result_path((List *) parse->jointree->quals); *sorted_path = NULL; return; } /* - * Pull out any non-variable WHERE clauses so these can be put in a - * toplevel "Result" node, where they will gate execution of the whole - * plan (the Result will not invoke its descendant plan unless the quals - * are true). Note that any *really* non-variable quals will have been - * optimized away by eval_const_expressions(). What we're mostly - * interested in here is quals that depend only on outer-level vars, - * although if the qual reduces to "WHERE FALSE" this path will also be - * taken. - */ - parse->jointree->quals = (Node *) - pull_constant_clauses((List *) parse->jointree->quals, - &constant_quals); - - /* * Init planner lists to empty, and set up the array to hold RelOptInfos * for "simple" rels. * @@ -324,20 +309,6 @@ query_planner(PlannerInfo *root, List *tlist, double tuple_fraction, } } - /* - * If we have constant quals, add a toplevel Result step to process them. - */ - if (constant_quals) - { - cheapestpath = (Path *) create_result_path(final_rel, - cheapestpath, - constant_quals); - if (sortedpath) - sortedpath = (Path *) create_result_path(final_rel, - sortedpath, - constant_quals); - } - *cheapest_path = cheapestpath; *sorted_path = sortedpath; } |