aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/createplan.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r--src/backend/optimizer/plan/createplan.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 8d15c8ede90..f461586e08c 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -102,7 +102,8 @@ static List *order_qual_clauses(PlannerInfo *root, List *clauses);
static void copy_path_costsize(Plan *dest, Path *src);
static void copy_plan_costsize(Plan *dest, Plan *src);
static SeqScan *make_seqscan(List *qptlist, List *qpqual, Index scanrelid);
-static SampleScan *make_samplescan(List *qptlist, List *qpqual, Index scanrelid);
+static SampleScan *make_samplescan(List *qptlist, List *qpqual, Index scanrelid,
+ TableSampleClause *tsc);
static IndexScan *make_indexscan(List *qptlist, List *qpqual, Index scanrelid,
Oid indexid, List *indexqual, List *indexqualorig,
List *indexorderby, List *indexorderbyorig,
@@ -1148,7 +1149,7 @@ create_seqscan_plan(PlannerInfo *root, Path *best_path,
/*
* create_samplescan_plan
- * Returns a samplecan plan for the base relation scanned by 'best_path'
+ * Returns a samplescan plan for the base relation scanned by 'best_path'
* with restriction clauses 'scan_clauses' and targetlist 'tlist'.
*/
static SampleScan *
@@ -1157,11 +1158,15 @@ create_samplescan_plan(PlannerInfo *root, Path *best_path,
{
SampleScan *scan_plan;
Index scan_relid = best_path->parent->relid;
+ RangeTblEntry *rte;
+ TableSampleClause *tsc;
- /* it should be a base rel with tablesample clause... */
+ /* it should be a base rel with a tablesample clause... */
Assert(scan_relid > 0);
- Assert(best_path->parent->rtekind == RTE_RELATION);
- Assert(best_path->pathtype == T_SampleScan);
+ rte = planner_rt_fetch(scan_relid, root);
+ Assert(rte->rtekind == RTE_RELATION);
+ tsc = rte->tablesample;
+ Assert(tsc != NULL);
/* Sort clauses into best execution order */
scan_clauses = order_qual_clauses(root, scan_clauses);
@@ -1174,13 +1179,16 @@ create_samplescan_plan(PlannerInfo *root, Path *best_path,
{
scan_clauses = (List *)
replace_nestloop_params(root, (Node *) scan_clauses);
+ tsc = (TableSampleClause *)
+ replace_nestloop_params(root, (Node *) tsc);
}
scan_plan = make_samplescan(tlist,
scan_clauses,
- scan_relid);
+ scan_relid,
+ tsc);
- copy_path_costsize(&scan_plan->plan, best_path);
+ copy_path_costsize(&scan_plan->scan.plan, best_path);
return scan_plan;
}
@@ -2161,9 +2169,9 @@ create_customscan_plan(PlannerInfo *root, CustomPath *best_path,
ListCell *lc;
/* Recursively transform child paths. */
- foreach (lc, best_path->custom_paths)
+ foreach(lc, best_path->custom_paths)
{
- Plan *plan = create_plan_recurse(root, (Path *) lfirst(lc));
+ Plan *plan = create_plan_recurse(root, (Path *) lfirst(lc));
custom_plans = lappend(custom_plans, plan);
}
@@ -3437,17 +3445,19 @@ make_seqscan(List *qptlist,
static SampleScan *
make_samplescan(List *qptlist,
List *qpqual,
- Index scanrelid)
+ Index scanrelid,
+ TableSampleClause *tsc)
{
SampleScan *node = makeNode(SampleScan);
- Plan *plan = &node->plan;
+ Plan *plan = &node->scan.plan;
/* cost should be inserted by caller */
plan->targetlist = qptlist;
plan->qual = qpqual;
plan->lefttree = NULL;
plan->righttree = NULL;
- node->scanrelid = scanrelid;
+ node->scan.scanrelid = scanrelid;
+ node->tablesample = tsc;
return node;
}