aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planmain.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/plan/planmain.c')
-rw-r--r--src/backend/optimizer/plan/planmain.c52
1 files changed, 14 insertions, 38 deletions
diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c
index a919914f944..42a98945a38 100644
--- a/src/backend/optimizer/plan/planmain.c
+++ b/src/backend/optimizer/plan/planmain.c
@@ -30,10 +30,6 @@
#include "utils/selfuncs.h"
-/* Local functions */
-static void canonicalize_all_pathkeys(PlannerInfo *root);
-
-
/*
* query_planner
* Generate a path (that is, a simplified plan) for a basic query,
@@ -55,6 +51,8 @@ static void canonicalize_all_pathkeys(PlannerInfo *root);
* tuple_fraction is the fraction of tuples we expect will be retrieved
* limit_tuples is a hard limit on number of tuples to retrieve,
* or -1 if no limit
+ * qp_callback is a function to compute query_pathkeys once it's safe to do so
+ * qp_extra is optional extra data to pass to qp_callback
*
* Output parameters:
* *cheapest_path receives the overall-cheapest path for the query
@@ -63,18 +61,11 @@ static void canonicalize_all_pathkeys(PlannerInfo *root);
* *num_groups receives the estimated number of groups, or 1 if query
* does not use grouping
*
- * Note: the PlannerInfo node also includes a query_pathkeys field, which is
- * both an input and an output of query_planner(). The input value signals
- * query_planner that the indicated sort order is wanted in the final output
- * plan. But this value has not yet been "canonicalized", since the needed
- * info does not get computed until we scan the qual clauses. We canonicalize
- * it as soon as that task is done. (The main reason query_pathkeys is a
- * PlannerInfo field and not a passed parameter is that the low-level routines
- * in indxpath.c need to see it.)
- *
- * Note: the PlannerInfo node includes other pathkeys fields besides
- * query_pathkeys, all of which need to be canonicalized once the info is
- * available. See canonicalize_all_pathkeys.
+ * Note: the PlannerInfo node also includes a query_pathkeys field, which
+ * tells query_planner the sort order that is desired in the final output
+ * plan. This value is *not* available at call time, but is computed by
+ * qp_callback once we have completed merging the query's equivalence classes.
+ * (We cannot construct canonical pathkeys until that's done.)
*
* tuple_fraction is interpreted as follows:
* 0: expect all tuples to be retrieved (normal case)
@@ -89,6 +80,7 @@ static void canonicalize_all_pathkeys(PlannerInfo *root);
void
query_planner(PlannerInfo *root, List *tlist,
double tuple_fraction, double limit_tuples,
+ query_pathkeys_callback qp_callback, void *qp_extra,
Path **cheapest_path, Path **sorted_path,
double *num_groups)
{
@@ -118,11 +110,11 @@ query_planner(PlannerInfo *root, List *tlist,
*sorted_path = NULL;
/*
- * We still are required to canonicalize any pathkeys, in case it's
- * something like "SELECT 2+2 ORDER BY 1".
+ * We still are required to call qp_callback, in case it's something
+ * like "SELECT 2+2 ORDER BY 1".
*/
root->canon_pathkeys = NIL;
- canonicalize_all_pathkeys(root);
+ (*qp_callback) (root, qp_extra);
return;
}
@@ -205,10 +197,10 @@ query_planner(PlannerInfo *root, List *tlist,
/*
* We have completed merging equivalence sets, so it's now possible to
- * convert previously generated pathkeys (in particular, the requested
- * query_pathkeys) to canonical form.
+ * generate pathkeys in canonical form; so compute query_pathkeys and
+ * other pathkeys fields in PlannerInfo.
*/
- canonicalize_all_pathkeys(root);
+ (*qp_callback) (root, qp_extra);
/*
* Examine any "placeholder" expressions generated during subquery pullup.
@@ -429,19 +421,3 @@ query_planner(PlannerInfo *root, List *tlist,
*cheapest_path = cheapestpath;
*sorted_path = sortedpath;
}
-
-
-/*
- * canonicalize_all_pathkeys
- * Canonicalize all pathkeys that were generated before entering
- * query_planner and then stashed in PlannerInfo.
- */
-static void
-canonicalize_all_pathkeys(PlannerInfo *root)
-{
- root->query_pathkeys = canonicalize_pathkeys(root, root->query_pathkeys);
- root->group_pathkeys = canonicalize_pathkeys(root, root->group_pathkeys);
- root->window_pathkeys = canonicalize_pathkeys(root, root->window_pathkeys);
- root->distinct_pathkeys = canonicalize_pathkeys(root, root->distinct_pathkeys);
- root->sort_pathkeys = canonicalize_pathkeys(root, root->sort_pathkeys);
-}