summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2009-11-15 02:45:35 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2009-11-15 02:45:35 +0000
commitcaf9c830d9d1180ab693f8a6eb205f5862174158 (patch)
treea9a6d4d79bedc2a62e87cd7eeea1bffa18e1836b /src/include
parent29faadcd2780f74550d6a983a81bc6bad3967bd6 (diff)
downloadpostgresql-caf9c830d9d1180ab693f8a6eb205f5862174158.tar.gz
Improve planning of Materialize nodes inserted atop the inner input of a
mergejoin to shield it from doing mark/restore and refetches. Put an explicit flag in MergePath so we can centralize the logic that knows about this, and add costing logic that considers using Materialize even when it's not forced by the previously-existing considerations. This is in response to a discussion back in August that suggested that materializing an inner indexscan can be helpful when the refetch percentage is high enough.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/nodes/relation.h20
-rw-r--r--src/include/optimizer/cost.h3
2 files changed, 17 insertions, 6 deletions
diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h
index 59f83e8562..d54770eabc 100644
--- a/src/include/nodes/relation.h
+++ b/src/include/nodes/relation.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.178 2009/10/26 02:26:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/nodes/relation.h,v 1.179 2009/11/15 02:45:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -835,6 +835,14 @@ typedef JoinPath NestPath;
/*
* A mergejoin path has these fields.
*
+ * Unlike other path types, a MergePath node doesn't represent just a single
+ * run-time plan node: it can represent up to four. Aside from the MergeJoin
+ * node itself, there can be a Sort node for the outer input, a Sort node
+ * for the inner input, and/or a Material node for the inner input. We could
+ * represent these nodes by separate path nodes, but considering how many
+ * different merge paths are investigated during a complex join problem,
+ * it seems better to avoid unnecessary palloc overhead.
+ *
* path_mergeclauses lists the clauses (in the form of RestrictInfos)
* that will be used in the merge.
*
@@ -846,15 +854,19 @@ typedef JoinPath NestPath;
* outersortkeys (resp. innersortkeys) is NIL if the outer path
* (resp. inner path) is already ordered appropriately for the
* mergejoin. If it is not NIL then it is a PathKeys list describing
- * the ordering that must be created by an explicit sort step.
+ * the ordering that must be created by an explicit Sort node.
+ *
+ * materialize_inner is TRUE if a Material node should be placed atop the
+ * inner input. This may appear with or without an inner Sort step.
*/
typedef struct MergePath
{
JoinPath jpath;
List *path_mergeclauses; /* join clauses to be used for merge */
- List *outersortkeys; /* keys for explicit sort, if any */
- List *innersortkeys; /* keys for explicit sort, if any */
+ List *outersortkeys; /* keys for explicit sort, if any */
+ List *innersortkeys; /* keys for explicit sort, if any */
+ bool materialize_inner; /* add Materialize to inner? */
} MergePath;
/*
diff --git a/src/include/optimizer/cost.h b/src/include/optimizer/cost.h
index f862979c08..041b7e8f9d 100644
--- a/src/include/optimizer/cost.h
+++ b/src/include/optimizer/cost.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.98 2009/09/12 22:12:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/cost.h,v 1.99 2009/11/15 02:45:35 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -84,7 +84,6 @@ extern void cost_recursive_union(Plan *runion, Plan *nrterm, Plan *rterm);
extern void cost_sort(Path *path, PlannerInfo *root,
List *pathkeys, Cost input_cost, double tuples, int width,
double limit_tuples);
-extern bool sort_exceeds_work_mem(Sort *sort);
extern void cost_material(Path *path,
Cost input_startup_cost, Cost input_total_cost,
double tuples, int width);