@@ -77,7 +77,7 @@ static WorkTableScan *create_worktablescan_plan(PlannerInfo *root, Path *best_pa
77
77
List * tlist , List * scan_clauses );
78
78
static ForeignScan * create_foreignscan_plan (PlannerInfo * root , ForeignPath * best_path ,
79
79
List * tlist , List * scan_clauses );
80
- static Plan * create_customscan_plan (PlannerInfo * root ,
80
+ static CustomScan * create_customscan_plan (PlannerInfo * root ,
81
81
CustomPath * best_path ,
82
82
List * tlist , List * scan_clauses );
83
83
static NestLoop * create_nestloop_plan (PlannerInfo * root , NestPath * best_path ,
@@ -86,6 +86,7 @@ static MergeJoin *create_mergejoin_plan(PlannerInfo *root, MergePath *best_path,
86
86
Plan * outer_plan , Plan * inner_plan );
87
87
static HashJoin * create_hashjoin_plan (PlannerInfo * root , HashPath * best_path ,
88
88
Plan * outer_plan , Plan * inner_plan );
89
+ static Node * replace_nestloop_params (PlannerInfo * root , Node * expr );
89
90
static Node * replace_nestloop_params_mutator (Node * node , PlannerInfo * root );
90
91
static void process_subquery_nestloop_params (PlannerInfo * root ,
91
92
List * subplan_params );
@@ -413,10 +414,10 @@ create_scan_plan(PlannerInfo *root, Path *best_path)
413
414
break ;
414
415
415
416
case T_CustomScan :
416
- plan = create_customscan_plan (root ,
417
- (CustomPath * ) best_path ,
418
- tlist ,
419
- scan_clauses );
417
+ plan = ( Plan * ) create_customscan_plan (root ,
418
+ (CustomPath * ) best_path ,
419
+ tlist ,
420
+ scan_clauses );
420
421
break ;
421
422
422
423
default :
@@ -2022,11 +2023,11 @@ create_foreignscan_plan(PlannerInfo *root, ForeignPath *best_path,
2022
2023
*
2023
2024
* Transform a CustomPath into a Plan.
2024
2025
*/
2025
- static Plan *
2026
+ static CustomScan *
2026
2027
create_customscan_plan (PlannerInfo * root , CustomPath * best_path ,
2027
2028
List * tlist , List * scan_clauses )
2028
2029
{
2029
- Plan * plan ;
2030
+ CustomScan * cplan ;
2030
2031
RelOptInfo * rel = best_path -> path .parent ;
2031
2032
2032
2033
/*
@@ -2045,23 +2046,35 @@ create_customscan_plan(PlannerInfo *root, CustomPath *best_path,
2045
2046
* Invoke custom plan provider to create the Plan node represented by the
2046
2047
* CustomPath.
2047
2048
*/
2048
- plan = best_path -> methods -> PlanCustomPath (root , rel , best_path , tlist ,
2049
- scan_clauses );
2049
+ cplan = (CustomScan * ) best_path -> methods -> PlanCustomPath (root ,
2050
+ rel ,
2051
+ best_path ,
2052
+ tlist ,
2053
+ scan_clauses );
2054
+ Assert (IsA (cplan , CustomScan ));
2050
2055
2051
2056
/*
2052
- * NOTE: unlike create_foreignscan_plan(), it is the responsibility of the
2053
- * custom plan provider to replace outer-relation variables with nestloop
2054
- * params, because we cannot know what expression trees may be held in
2055
- * private fields.
2057
+ * Copy cost data from Path to Plan; no need to make custom-plan providers
2058
+ * do this
2056
2059
*/
2060
+ copy_path_costsize (& cplan -> scan .plan , & best_path -> path );
2057
2061
2058
2062
/*
2059
- * Copy cost data from Path to Plan; no need to make custom-plan providers
2060
- * do this
2063
+ * Replace any outer-relation variables with nestloop params in the qual
2064
+ * and custom_exprs expressions. We do this last so that the custom-plan
2065
+ * provider doesn't have to be involved. (Note that parts of custom_exprs
2066
+ * could have come from join clauses, so doing this beforehand on the
2067
+ * scan_clauses wouldn't work.)
2061
2068
*/
2062
- copy_path_costsize (plan , & best_path -> path );
2069
+ if (best_path -> path .param_info )
2070
+ {
2071
+ cplan -> scan .plan .qual = (List * )
2072
+ replace_nestloop_params (root , (Node * ) cplan -> scan .plan .qual );
2073
+ cplan -> custom_exprs = (List * )
2074
+ replace_nestloop_params (root , (Node * ) cplan -> custom_exprs );
2075
+ }
2063
2076
2064
- return plan ;
2077
+ return cplan ;
2065
2078
}
2066
2079
2067
2080
@@ -2598,7 +2611,7 @@ create_hashjoin_plan(PlannerInfo *root,
2598
2611
* root->curOuterRels are replaced by Params, and entries are added to
2599
2612
* root->curOuterParams if not already present.
2600
2613
*/
2601
- Node *
2614
+ static Node *
2602
2615
replace_nestloop_params (PlannerInfo * root , Node * expr )
2603
2616
{
2604
2617
/* No setup needed for tree walk, so away we go */
0 commit comments