summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/subselect.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-09-12 22:12:09 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-09-12 22:12:09 +0000
commit9bb342811bf6a93a574a648c5848feedbaaef8f2 (patch)
treeecc60f3017cc58695c4c96ebf6d11669e3de6900 /src/backend/optimizer/plan/subselect.c
parent5f1b32ddf826550d65dd6e84b965b6a98589ad19 (diff)
Rewrite the planner's handling of materialized plan types so that there is
an explicit model of rescan costs being different from first-time costs. The costing of Material nodes in particular now has some visible relationship to the actual runtime behavior, where before it was essentially fantasy. This also fixes up a couple of places where different materialized plan types were treated differently for no very good reason (probably just oversights). A couple of the regression tests are affected, because the planner now chooses to put the other relation on the inside of a nestloop-with-materialize. So far as I can see both changes are sane, and the planner is now more consistently following the expectation that it should prefer to materialize the smaller of two relations. Per a recent discussion with Robert Haas.
Diffstat (limited to 'src/backend/optimizer/plan/subselect.c')
-rw-r--r--src/backend/optimizer/plan/subselect.c30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index e56c0755d02..78809474a3b 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -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.152 2009/07/16 06:33:43 petere Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.153 2009/09/12 22:12:04 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -15,6 +15,7 @@
#include "catalog/pg_operator.h"
#include "catalog/pg_type.h"
+#include "executor/executor.h"
#include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
@@ -564,33 +565,16 @@ build_subplan(PlannerInfo *root, Plan *plan, List *rtable,
splan->useHashTable = true;
/*
- * Otherwise, we have the option to tack a MATERIAL node onto the top
+ * Otherwise, we have the option to tack a Material node onto the top
* of the subplan, to reduce the cost of reading it repeatedly. This
* is pointless for a direct-correlated subplan, since we'd have to
* recompute its results each time anyway. For uncorrelated/undirect
- * correlated subplans, we add MATERIAL unless the subplan's top plan
+ * correlated subplans, we add Material unless the subplan's top plan
* node would materialize its output anyway.
*/
- else if (splan->parParam == NIL)
- {
- bool use_material;
-
- switch (nodeTag(plan))
- {
- case T_Material:
- case T_FunctionScan:
- case T_CteScan:
- case T_WorkTableScan:
- case T_Sort:
- use_material = false;
- break;
- default:
- use_material = true;
- break;
- }
- if (use_material)
- plan = materialize_finished_plan(plan);
- }
+ else if (splan->parParam == NIL &&
+ !ExecMaterializesOutput(nodeTag(plan)))
+ plan = materialize_finished_plan(plan);
result = (Node *) splan;
isInitPlan = false;