summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/pathnode.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/util/pathnode.c
parent68628fc38ea7a3c72f6a813b0193d836731d9c10 (diff)
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/util/pathnode.c')
-rw-r--r--src/backend/optimizer/util/pathnode.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c
index f8270074142..c0363d2405d 100644
--- a/src/backend/optimizer/util/pathnode.c
+++ b/src/backend/optimizer/util/pathnode.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.128 2006/06/06 17:59:57 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/pathnode.c,v 1.129 2006/07/01 18:38:33 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -667,36 +667,29 @@ create_append_path(RelOptInfo *rel, List *subpaths)
/*
* create_result_path
- * Creates a path corresponding to a Result plan, returning the
- * pathnode.
+ * Creates a path representing a Result-and-nothing-else plan.
+ * This is only used for the case of a query with an empty jointree.
*/
ResultPath *
-create_result_path(RelOptInfo *rel, Path *subpath, List *constantqual)
+create_result_path(List *quals)
{
ResultPath *pathnode = makeNode(ResultPath);
pathnode->path.pathtype = T_Result;
- pathnode->path.parent = rel; /* may be NULL */
-
- if (subpath)
- pathnode->path.pathkeys = subpath->pathkeys;
- else
- pathnode->path.pathkeys = NIL;
-
- pathnode->subpath = subpath;
- pathnode->constantqual = constantqual;
+ pathnode->path.parent = NULL;
+ pathnode->path.pathkeys = NIL;
+ pathnode->quals = quals;
/* Ideally should define cost_result(), but I'm too lazy */
- if (subpath)
- {
- pathnode->path.startup_cost = subpath->startup_cost;
- pathnode->path.total_cost = subpath->total_cost;
- }
- else
- {
- pathnode->path.startup_cost = 0;
- pathnode->path.total_cost = cpu_tuple_cost;
- }
+ pathnode->path.startup_cost = 0;
+ pathnode->path.total_cost = cpu_tuple_cost;
+ /*
+ * In theory we should include the qual eval cost as well, but
+ * at present that doesn't accomplish much except duplicate work that
+ * will be done again in make_result; since this is only used for
+ * degenerate cases, nothing interesting will be done with the path
+ * cost values...
+ */
return pathnode;
}