aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/allpaths.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2006-07-01 18:38:33 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2006-07-01 18:38:33 +0000
commitcffd89ca736e485309cd51ae056f837bd7e683ad (patch)
tree7ebf13ae5d921d074382d80be66a8d97e7a822e1 /src/backend/optimizer/path/allpaths.c
parent68628fc38ea7a3c72f6a813b0193d836731d9c10 (diff)
downloadpostgresql-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/path/allpaths.c')
-rw-r--r--src/backend/optimizer/path/allpaths.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index de82c3df8d0..ad55360a853 100644
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.146 2006/05/02 04:34:18 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.147 2006/07/01 18:38:32 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -446,7 +446,9 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
* There are several cases where we cannot push down clauses. Restrictions
* involving the subquery are checked by subquery_is_pushdown_safe().
* Restrictions on individual clauses are checked by
- * qual_is_pushdown_safe().
+ * qual_is_pushdown_safe(). Also, we don't want to push down
+ * pseudoconstant clauses; better to have the gating node above the
+ * subquery.
*
* Non-pushed-down clauses will get evaluated as qpquals of the
* SubqueryScan node.
@@ -466,7 +468,8 @@ set_subquery_pathlist(PlannerInfo *root, RelOptInfo *rel,
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
Node *clause = (Node *) rinfo->clause;
- if (qual_is_pushdown_safe(subquery, rti, clause, differentTypes))
+ if (!rinfo->pseudoconstant &&
+ qual_is_pushdown_safe(subquery, rti, clause, differentTypes))
{
/* Push it down */
subquery_push_qual(subquery, rte, rti, clause);
@@ -1066,7 +1069,6 @@ print_path(PlannerInfo *root, Path *path, int indent)
break;
case T_ResultPath:
ptype = "Result";
- subpath = ((ResultPath *) path)->subpath;
break;
case T_MaterialPath:
ptype = "Material";