@@ -29,19 +29,19 @@ static void sort_inner_and_outer(PlannerInfo *root, RelOptInfo *joinrel,
29
29
RelOptInfo * outerrel , RelOptInfo * innerrel ,
30
30
List * restrictlist , List * mergeclause_list ,
31
31
JoinType jointype , SpecialJoinInfo * sjinfo ,
32
- Relids param_source_rels , Relids extra_lateral_rels );
32
+ Relids param_source_rels );
33
33
static void match_unsorted_outer (PlannerInfo * root , RelOptInfo * joinrel ,
34
34
RelOptInfo * outerrel , RelOptInfo * innerrel ,
35
35
List * restrictlist , List * mergeclause_list ,
36
36
JoinType jointype , SpecialJoinInfo * sjinfo ,
37
37
SemiAntiJoinFactors * semifactors ,
38
- Relids param_source_rels , Relids extra_lateral_rels );
38
+ Relids param_source_rels );
39
39
static void hash_inner_and_outer (PlannerInfo * root , RelOptInfo * joinrel ,
40
40
RelOptInfo * outerrel , RelOptInfo * innerrel ,
41
41
List * restrictlist ,
42
42
JoinType jointype , SpecialJoinInfo * sjinfo ,
43
43
SemiAntiJoinFactors * semifactors ,
44
- Relids param_source_rels , Relids extra_lateral_rels );
44
+ Relids param_source_rels );
45
45
static List * select_mergejoin_clauses (PlannerInfo * root ,
46
46
RelOptInfo * joinrel ,
47
47
RelOptInfo * outerrel ,
@@ -87,7 +87,6 @@ add_paths_to_joinrel(PlannerInfo *root,
87
87
bool mergejoin_allowed = true;
88
88
SemiAntiJoinFactors semifactors ;
89
89
Relids param_source_rels = NULL ;
90
- Relids extra_lateral_rels = NULL ;
91
90
ListCell * lc ;
92
91
93
92
/*
@@ -153,59 +152,14 @@ add_paths_to_joinrel(PlannerInfo *root,
153
152
}
154
153
155
154
/*
156
- * However, when a LATERAL subquery is involved, we have to be a bit
157
- * laxer, because there will simply not be any paths for the joinrel that
158
- * aren't parameterized by whatever the subquery is parameterized by,
159
- * unless its parameterization is resolved within the joinrel. Hence, add
160
- * to param_source_rels anything that is laterally referenced in either
161
- * input and is not in the join already.
155
+ * However, when a LATERAL subquery is involved, there will simply not be
156
+ * any paths for the joinrel that aren't parameterized by whatever the
157
+ * subquery is parameterized by, unless its parameterization is resolved
158
+ * within the joinrel. So we might as well allow additional dependencies
159
+ * on whatever residual lateral dependencies the joinrel will have.
162
160
*/
163
- foreach (lc , root -> lateral_info_list )
164
- {
165
- LateralJoinInfo * ljinfo = (LateralJoinInfo * ) lfirst (lc );
166
-
167
- if (bms_is_subset (ljinfo -> lateral_rhs , joinrel -> relids ))
168
- param_source_rels = bms_join (param_source_rels ,
169
- bms_difference (ljinfo -> lateral_lhs ,
170
- joinrel -> relids ));
171
- }
172
-
173
- /*
174
- * Another issue created by LATERAL references is that PlaceHolderVars
175
- * that need to be computed at this join level might contain lateral
176
- * references to rels not in the join, meaning that the paths for the join
177
- * would need to be marked as parameterized by those rels, independently
178
- * of all other considerations. Set extra_lateral_rels to the set of such
179
- * rels. This will not affect our decisions as to which paths to
180
- * generate; we merely add these rels to their required_outer sets.
181
- */
182
- foreach (lc , root -> placeholder_list )
183
- {
184
- PlaceHolderInfo * phinfo = (PlaceHolderInfo * ) lfirst (lc );
185
-
186
- /* PHVs without lateral refs can be skipped over quickly */
187
- if (phinfo -> ph_lateral == NULL )
188
- continue ;
189
- /* Is it due to be evaluated at this join, and not in either input? */
190
- if (bms_is_subset (phinfo -> ph_eval_at , joinrel -> relids ) &&
191
- !bms_is_subset (phinfo -> ph_eval_at , outerrel -> relids ) &&
192
- !bms_is_subset (phinfo -> ph_eval_at , innerrel -> relids ))
193
- {
194
- /* Yes, remember its lateral rels */
195
- extra_lateral_rels = bms_add_members (extra_lateral_rels ,
196
- phinfo -> ph_lateral );
197
- }
198
- }
199
-
200
- /*
201
- * Make sure extra_lateral_rels doesn't list anything within the join, and
202
- * that it's NULL if empty. (This allows us to use bms_add_members to add
203
- * it to required_outer below, while preserving the property that
204
- * required_outer is exactly NULL if empty.)
205
- */
206
- extra_lateral_rels = bms_del_members (extra_lateral_rels , joinrel -> relids );
207
- if (bms_is_empty (extra_lateral_rels ))
208
- extra_lateral_rels = NULL ;
161
+ param_source_rels = bms_add_members (param_source_rels ,
162
+ joinrel -> lateral_relids );
209
163
210
164
/*
211
165
* 1. Consider mergejoin paths where both relations must be explicitly
@@ -215,7 +169,7 @@ add_paths_to_joinrel(PlannerInfo *root,
215
169
sort_inner_and_outer (root , joinrel , outerrel , innerrel ,
216
170
restrictlist , mergeclause_list , jointype ,
217
171
sjinfo ,
218
- param_source_rels , extra_lateral_rels );
172
+ param_source_rels );
219
173
220
174
/*
221
175
* 2. Consider paths where the outer relation need not be explicitly
@@ -228,7 +182,7 @@ add_paths_to_joinrel(PlannerInfo *root,
228
182
match_unsorted_outer (root , joinrel , outerrel , innerrel ,
229
183
restrictlist , mergeclause_list , jointype ,
230
184
sjinfo , & semifactors ,
231
- param_source_rels , extra_lateral_rels );
185
+ param_source_rels );
232
186
233
187
#ifdef NOT_USED
234
188
@@ -247,7 +201,7 @@ add_paths_to_joinrel(PlannerInfo *root,
247
201
match_unsorted_inner (root , joinrel , outerrel , innerrel ,
248
202
restrictlist , mergeclause_list , jointype ,
249
203
sjinfo , & semifactors ,
250
- param_source_rels , extra_lateral_rels );
204
+ param_source_rels );
251
205
#endif
252
206
253
207
/*
@@ -259,7 +213,7 @@ add_paths_to_joinrel(PlannerInfo *root,
259
213
hash_inner_and_outer (root , joinrel , outerrel , innerrel ,
260
214
restrictlist , jointype ,
261
215
sjinfo , & semifactors ,
262
- param_source_rels , extra_lateral_rels );
216
+ param_source_rels );
263
217
}
264
218
265
219
/*
@@ -353,7 +307,6 @@ try_nestloop_path(PlannerInfo *root,
353
307
SpecialJoinInfo * sjinfo ,
354
308
SemiAntiJoinFactors * semifactors ,
355
309
Relids param_source_rels ,
356
- Relids extra_lateral_rels ,
357
310
Path * outer_path ,
358
311
Path * inner_path ,
359
312
List * restrict_clauses ,
@@ -382,9 +335,13 @@ try_nestloop_path(PlannerInfo *root,
382
335
383
336
/*
384
337
* Independently of that, add parameterization needed for any
385
- * PlaceHolderVars that need to be computed at the join.
338
+ * PlaceHolderVars that need to be computed at the join. We can handle
339
+ * that just by adding joinrel->lateral_relids; that might include some
340
+ * rels that are already in required_outer, but no harm done. (Note that
341
+ * lateral_relids is exactly NULL if empty, so this will not break the
342
+ * property that required_outer is too.)
386
343
*/
387
- required_outer = bms_add_members (required_outer , extra_lateral_rels );
344
+ required_outer = bms_add_members (required_outer , joinrel -> lateral_relids );
388
345
389
346
/*
390
347
* Do a precheck to quickly eliminate obviously-inferior paths. We
@@ -434,7 +391,6 @@ try_mergejoin_path(PlannerInfo *root,
434
391
JoinType jointype ,
435
392
SpecialJoinInfo * sjinfo ,
436
393
Relids param_source_rels ,
437
- Relids extra_lateral_rels ,
438
394
Path * outer_path ,
439
395
Path * inner_path ,
440
396
List * restrict_clauses ,
@@ -464,7 +420,7 @@ try_mergejoin_path(PlannerInfo *root,
464
420
* Independently of that, add parameterization needed for any
465
421
* PlaceHolderVars that need to be computed at the join.
466
422
*/
467
- required_outer = bms_add_members (required_outer , extra_lateral_rels );
423
+ required_outer = bms_add_members (required_outer , joinrel -> lateral_relids );
468
424
469
425
/*
470
426
* If the given paths are already well enough ordered, we can skip doing
@@ -523,7 +479,6 @@ try_hashjoin_path(PlannerInfo *root,
523
479
SpecialJoinInfo * sjinfo ,
524
480
SemiAntiJoinFactors * semifactors ,
525
481
Relids param_source_rels ,
526
- Relids extra_lateral_rels ,
527
482
Path * outer_path ,
528
483
Path * inner_path ,
529
484
List * restrict_clauses ,
@@ -550,7 +505,7 @@ try_hashjoin_path(PlannerInfo *root,
550
505
* Independently of that, add parameterization needed for any
551
506
* PlaceHolderVars that need to be computed at the join.
552
507
*/
553
- required_outer = bms_add_members (required_outer , extra_lateral_rels );
508
+ required_outer = bms_add_members (required_outer , joinrel -> lateral_relids );
554
509
555
510
/*
556
511
* See comments in try_nestloop_path(). Also note that hashjoin paths
@@ -630,7 +585,6 @@ clause_sides_match_join(RestrictInfo *rinfo, RelOptInfo *outerrel,
630
585
* 'jointype' is the type of join to do
631
586
* 'sjinfo' is extra info about the join for selectivity estimation
632
587
* 'param_source_rels' are OK targets for parameterization of result paths
633
- * 'extra_lateral_rels' are additional parameterization for result paths
634
588
*/
635
589
static void
636
590
sort_inner_and_outer (PlannerInfo * root ,
@@ -641,8 +595,7 @@ sort_inner_and_outer(PlannerInfo *root,
641
595
List * mergeclause_list ,
642
596
JoinType jointype ,
643
597
SpecialJoinInfo * sjinfo ,
644
- Relids param_source_rels ,
645
- Relids extra_lateral_rels )
598
+ Relids param_source_rels )
646
599
{
647
600
Path * outer_path ;
648
601
Path * inner_path ;
@@ -772,7 +725,6 @@ sort_inner_and_outer(PlannerInfo *root,
772
725
jointype ,
773
726
sjinfo ,
774
727
param_source_rels ,
775
- extra_lateral_rels ,
776
728
outer_path ,
777
729
inner_path ,
778
730
restrictlist ,
@@ -818,7 +770,6 @@ sort_inner_and_outer(PlannerInfo *root,
818
770
* 'sjinfo' is extra info about the join for selectivity estimation
819
771
* 'semifactors' contains valid data if jointype is SEMI or ANTI
820
772
* 'param_source_rels' are OK targets for parameterization of result paths
821
- * 'extra_lateral_rels' are additional parameterization for result paths
822
773
*/
823
774
static void
824
775
match_unsorted_outer (PlannerInfo * root ,
@@ -830,8 +781,7 @@ match_unsorted_outer(PlannerInfo *root,
830
781
JoinType jointype ,
831
782
SpecialJoinInfo * sjinfo ,
832
783
SemiAntiJoinFactors * semifactors ,
833
- Relids param_source_rels ,
834
- Relids extra_lateral_rels )
784
+ Relids param_source_rels )
835
785
{
836
786
JoinType save_jointype = jointype ;
837
787
bool nestjoinOK ;
@@ -961,7 +911,6 @@ match_unsorted_outer(PlannerInfo *root,
961
911
sjinfo ,
962
912
semifactors ,
963
913
param_source_rels ,
964
- extra_lateral_rels ,
965
914
outerpath ,
966
915
inner_cheapest_total ,
967
916
restrictlist ,
@@ -987,7 +936,6 @@ match_unsorted_outer(PlannerInfo *root,
987
936
sjinfo ,
988
937
semifactors ,
989
938
param_source_rels ,
990
- extra_lateral_rels ,
991
939
outerpath ,
992
940
innerpath ,
993
941
restrictlist ,
@@ -1002,7 +950,6 @@ match_unsorted_outer(PlannerInfo *root,
1002
950
sjinfo ,
1003
951
semifactors ,
1004
952
param_source_rels ,
1005
- extra_lateral_rels ,
1006
953
outerpath ,
1007
954
matpath ,
1008
955
restrictlist ,
@@ -1058,7 +1005,6 @@ match_unsorted_outer(PlannerInfo *root,
1058
1005
jointype ,
1059
1006
sjinfo ,
1060
1007
param_source_rels ,
1061
- extra_lateral_rels ,
1062
1008
outerpath ,
1063
1009
inner_cheapest_total ,
1064
1010
restrictlist ,
@@ -1157,7 +1103,6 @@ match_unsorted_outer(PlannerInfo *root,
1157
1103
jointype ,
1158
1104
sjinfo ,
1159
1105
param_source_rels ,
1160
- extra_lateral_rels ,
1161
1106
outerpath ,
1162
1107
innerpath ,
1163
1108
restrictlist ,
@@ -1203,7 +1148,6 @@ match_unsorted_outer(PlannerInfo *root,
1203
1148
jointype ,
1204
1149
sjinfo ,
1205
1150
param_source_rels ,
1206
- extra_lateral_rels ,
1207
1151
outerpath ,
1208
1152
innerpath ,
1209
1153
restrictlist ,
@@ -1238,7 +1182,6 @@ match_unsorted_outer(PlannerInfo *root,
1238
1182
* 'sjinfo' is extra info about the join for selectivity estimation
1239
1183
* 'semifactors' contains valid data if jointype is SEMI or ANTI
1240
1184
* 'param_source_rels' are OK targets for parameterization of result paths
1241
- * 'extra_lateral_rels' are additional parameterization for result paths
1242
1185
*/
1243
1186
static void
1244
1187
hash_inner_and_outer (PlannerInfo * root ,
@@ -1249,8 +1192,7 @@ hash_inner_and_outer(PlannerInfo *root,
1249
1192
JoinType jointype ,
1250
1193
SpecialJoinInfo * sjinfo ,
1251
1194
SemiAntiJoinFactors * semifactors ,
1252
- Relids param_source_rels ,
1253
- Relids extra_lateral_rels )
1195
+ Relids param_source_rels )
1254
1196
{
1255
1197
bool isouterjoin = IS_OUTER_JOIN (jointype );
1256
1198
List * hashclauses ;
@@ -1324,7 +1266,6 @@ hash_inner_and_outer(PlannerInfo *root,
1324
1266
sjinfo ,
1325
1267
semifactors ,
1326
1268
param_source_rels ,
1327
- extra_lateral_rels ,
1328
1269
cheapest_total_outer ,
1329
1270
cheapest_total_inner ,
1330
1271
restrictlist ,
@@ -1344,7 +1285,6 @@ hash_inner_and_outer(PlannerInfo *root,
1344
1285
sjinfo ,
1345
1286
semifactors ,
1346
1287
param_source_rels ,
1347
- extra_lateral_rels ,
1348
1288
cheapest_total_outer ,
1349
1289
cheapest_total_inner ,
1350
1290
restrictlist ,
@@ -1357,7 +1297,6 @@ hash_inner_and_outer(PlannerInfo *root,
1357
1297
sjinfo ,
1358
1298
semifactors ,
1359
1299
param_source_rels ,
1360
- extra_lateral_rels ,
1361
1300
cheapest_startup_outer ,
1362
1301
cheapest_total_inner ,
1363
1302
restrictlist ,
@@ -1382,7 +1321,6 @@ hash_inner_and_outer(PlannerInfo *root,
1382
1321
sjinfo ,
1383
1322
semifactors ,
1384
1323
param_source_rels ,
1385
- extra_lateral_rels ,
1386
1324
cheapest_startup_outer ,
1387
1325
cheapest_total_inner ,
1388
1326
restrictlist ,
@@ -1420,7 +1358,6 @@ hash_inner_and_outer(PlannerInfo *root,
1420
1358
sjinfo ,
1421
1359
semifactors ,
1422
1360
param_source_rels ,
1423
- extra_lateral_rels ,
1424
1361
outerpath ,
1425
1362
innerpath ,
1426
1363
restrictlist ,
0 commit comments