@@ -209,22 +209,22 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
209
209
/* Proceed iff relation 'rel' is partitioned */
210
210
if ((prel = get_pathman_relation_info (rte -> relid )) != NULL )
211
211
{
212
- ListCell * lc ;
213
- Oid * children ;
214
- List * ranges ,
215
- * wrappers ,
216
- * rel_part_clauses = NIL ;
212
+ Relation parent_rel ; /* parent's relation (heap */
213
+ Oid * children ; /* selected children oids */
214
+ List * ranges , /* a list of IndexRanges */
215
+ * wrappers , /* a list of WrapperNodes */
216
+ * rel_part_clauses = NIL ; /* clauses with part. column */
217
217
PathKey * pathkeyAsc = NULL ,
218
218
* pathkeyDesc = NULL ;
219
- double paramsel = 1.0 ;
219
+ double paramsel = 1.0 ; /* default part selectivity */
220
220
WalkerContext context ;
221
+ ListCell * lc ;
221
222
int i ;
222
223
223
224
if (prel -> parttype == PT_RANGE )
224
225
{
225
226
/*
226
- * Get pathkeys for ascending and descending sort by partition
227
- * column
227
+ * Get pathkeys for ascending and descending sort by partitioned column.
228
228
*/
229
229
List * pathkeys ;
230
230
Var * var ;
@@ -273,13 +273,12 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
273
273
ranges = irange_list_intersect (ranges , wrap -> rangeset );
274
274
}
275
275
276
- /*
277
- * Expand simple_rte_array and simple_rel_array
278
- */
276
+ /* Get number of selected partitions */
279
277
len = irange_list_length (ranges );
280
278
if (prel -> enable_parent )
281
- len ++ ;
279
+ len ++ ; /* add parent too */
282
280
281
+ /* Expand simple_rte_array and simple_rel_array */
283
282
if (len > 0 )
284
283
{
285
284
/* Expand simple_rel_array and simple_rte_array */
@@ -306,26 +305,32 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
306
305
root -> simple_rte_array = new_rte_array ;
307
306
}
308
307
309
- /* Add parent if needed */
308
+ /* Parent has already been locked by rewriter */
309
+ parent_rel = heap_open (rte -> relid , NoLock );
310
+
311
+ /* Add parent if asked to */
310
312
if (prel -> enable_parent )
311
- append_child_relation (root , rti , 0 , rte -> relid , NULL );
313
+ append_child_relation (root , parent_rel , rti , 0 , rte -> relid , NULL );
312
314
313
315
/*
314
- * Iterate all indexes in rangeset and append corresponding child
315
- * relations.
316
+ * Iterate all indexes in rangeset and append corresponding child relations.
316
317
*/
317
318
foreach (lc , ranges )
318
319
{
319
320
IndexRange irange = lfirst_irange (lc );
320
321
321
322
for (i = irange .ir_lower ; i <= irange .ir_upper ; i ++ )
322
- append_child_relation (root , rti , i , children [i ], wrappers );
323
+ append_child_relation (root , parent_rel , rti , i , children [i ], wrappers );
323
324
}
324
325
325
- /* Clear old path list */
326
- list_free ( rel -> pathlist );
326
+ /* Now close parent relation */
327
+ heap_close ( parent_rel , NoLock );
327
328
329
+ /* Clear path list and make it point to NIL */
330
+ list_free_deep (rel -> pathlist );
328
331
rel -> pathlist = NIL ;
332
+
333
+ /* Generate new paths using the rels we've just added */
329
334
set_append_rel_pathlist (root , rel , rti , pathkeyAsc , pathkeyDesc );
330
335
set_append_rel_size_compat (root , rel , rti );
331
336
@@ -342,6 +347,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
342
347
if (!clause_contains_params ((Node * ) rel_part_clauses ))
343
348
return ;
344
349
350
+ /* Generate Runtime[Merge]Append paths if needed */
345
351
foreach (lc , rel -> pathlist )
346
352
{
347
353
AppendPath * cur_path = (AppendPath * ) lfirst (lc );
0 commit comments