Skip to content

Commit 79b2e52

Browse files
committed
Remove quick path in ExecInitPartitionInfo for equal tupdescs
I added this "optimization" on top of Amit Langote's 158b7bc, but the quick path is never taken because the partition uses a different pg_type oid than its parent table (causing equalTupleDescs to return false). Changing that requires more analysis and is too considered dangerous at this point in the cycle, so revert it. We might make it work someday, but not for pg11. Discussion: https://postgr.es/m/825031be-942c-8c24-6163-13c27f217a3d@lab.ntt.co.jp
1 parent 2d62517 commit 79b2e52

File tree

1 file changed

+68
-85
lines changed

1 file changed

+68
-85
lines changed

src/backend/executor/execPartition.c

Lines changed: 68 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
313313
MemoryContext oldContext;
314314
AttrNumber *part_attnos = NULL;
315315
bool found_whole_row;
316-
bool equalTupdescs;
317316

318317
/*
319318
* We locked all the partitions in ExecSetupPartitionTupleRouting
@@ -361,10 +360,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
361360
(node != NULL &&
362361
node->onConflictAction != ONCONFLICT_NONE));
363362

364-
/* if tuple descs are identical, we don't need to map the attrs */
365-
equalTupdescs = equalTupleDescs(RelationGetDescr(partrel),
366-
RelationGetDescr(firstResultRel));
367-
368363
/*
369364
* Build WITH CHECK OPTION constraints for the partition. Note that we
370365
* didn't build the withCheckOptionList for partitions within the planner,
@@ -405,21 +400,18 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
405400
/*
406401
* Convert Vars in it to contain this partition's attribute numbers.
407402
*/
408-
if (!equalTupdescs)
409-
{
410-
part_attnos =
411-
convert_tuples_by_name_map(RelationGetDescr(partrel),
412-
RelationGetDescr(firstResultRel),
413-
gettext_noop("could not convert row type"));
414-
wcoList = (List *)
415-
map_variable_attnos((Node *) wcoList,
416-
firstVarno, 0,
417-
part_attnos,
418-
RelationGetDescr(firstResultRel)->natts,
419-
RelationGetForm(partrel)->reltype,
420-
&found_whole_row);
421-
/* We ignore the value of found_whole_row. */
422-
}
403+
part_attnos =
404+
convert_tuples_by_name_map(RelationGetDescr(partrel),
405+
RelationGetDescr(firstResultRel),
406+
gettext_noop("could not convert row type"));
407+
wcoList = (List *)
408+
map_variable_attnos((Node *) wcoList,
409+
firstVarno, 0,
410+
part_attnos,
411+
RelationGetDescr(firstResultRel)->natts,
412+
RelationGetForm(partrel)->reltype,
413+
&found_whole_row);
414+
/* We ignore the value of found_whole_row. */
423415

424416
foreach(ll, wcoList)
425417
{
@@ -464,25 +456,22 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
464456
*/
465457
returningList = linitial(node->returningLists);
466458

467-
if (!equalTupdescs)
468-
{
469-
/*
470-
* Convert Vars in it to contain this partition's attribute numbers.
471-
*/
472-
if (part_attnos == NULL)
473-
part_attnos =
474-
convert_tuples_by_name_map(RelationGetDescr(partrel),
475-
RelationGetDescr(firstResultRel),
476-
gettext_noop("could not convert row type"));
477-
returningList = (List *)
478-
map_variable_attnos((Node *) returningList,
479-
firstVarno, 0,
480-
part_attnos,
481-
RelationGetDescr(firstResultRel)->natts,
482-
RelationGetForm(partrel)->reltype,
483-
&found_whole_row);
484-
/* We ignore the value of found_whole_row. */
485-
}
459+
/*
460+
* Convert Vars in it to contain this partition's attribute numbers.
461+
*/
462+
if (part_attnos == NULL)
463+
part_attnos =
464+
convert_tuples_by_name_map(RelationGetDescr(partrel),
465+
RelationGetDescr(firstResultRel),
466+
gettext_noop("could not convert row type"));
467+
returningList = (List *)
468+
map_variable_attnos((Node *) returningList,
469+
firstVarno, 0,
470+
part_attnos,
471+
RelationGetDescr(firstResultRel)->natts,
472+
RelationGetForm(partrel)->reltype,
473+
&found_whole_row);
474+
/* We ignore the value of found_whole_row. */
486475

487476
leaf_part_rri->ri_returningList = returningList;
488477

@@ -583,33 +572,30 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
583572
* target relation (firstVarno).
584573
*/
585574
onconflset = (List *) copyObject((Node *) node->onConflictSet);
586-
if (!equalTupdescs)
587-
{
588-
if (part_attnos == NULL)
589-
part_attnos =
590-
convert_tuples_by_name_map(RelationGetDescr(partrel),
591-
RelationGetDescr(firstResultRel),
592-
gettext_noop("could not convert row type"));
593-
onconflset = (List *)
594-
map_variable_attnos((Node *) onconflset,
595-
INNER_VAR, 0,
596-
part_attnos,
597-
RelationGetDescr(firstResultRel)->natts,
598-
RelationGetForm(partrel)->reltype,
599-
&found_whole_row);
600-
/* We ignore the value of found_whole_row. */
601-
onconflset = (List *)
602-
map_variable_attnos((Node *) onconflset,
603-
firstVarno, 0,
604-
part_attnos,
605-
RelationGetDescr(firstResultRel)->natts,
606-
RelationGetForm(partrel)->reltype,
607-
&found_whole_row);
608-
/* We ignore the value of found_whole_row. */
609-
610-
/* Finally, adjust this tlist to match the partition. */
611-
onconflset = adjust_partition_tlist(onconflset, map);
612-
}
575+
if (part_attnos == NULL)
576+
part_attnos =
577+
convert_tuples_by_name_map(RelationGetDescr(partrel),
578+
RelationGetDescr(firstResultRel),
579+
gettext_noop("could not convert row type"));
580+
onconflset = (List *)
581+
map_variable_attnos((Node *) onconflset,
582+
INNER_VAR, 0,
583+
part_attnos,
584+
RelationGetDescr(firstResultRel)->natts,
585+
RelationGetForm(partrel)->reltype,
586+
&found_whole_row);
587+
/* We ignore the value of found_whole_row. */
588+
onconflset = (List *)
589+
map_variable_attnos((Node *) onconflset,
590+
firstVarno, 0,
591+
part_attnos,
592+
RelationGetDescr(firstResultRel)->natts,
593+
RelationGetForm(partrel)->reltype,
594+
&found_whole_row);
595+
/* We ignore the value of found_whole_row. */
596+
597+
/* Finally, adjust this tlist to match the partition. */
598+
onconflset = adjust_partition_tlist(onconflset, map);
613599

614600
/*
615601
* Build UPDATE SET's projection info. The user of this
@@ -637,25 +623,22 @@ ExecInitPartitionInfo(ModifyTableState *mtstate,
637623
List *clause;
638624

639625
clause = copyObject((List *) node->onConflictWhere);
640-
if (!equalTupdescs)
641-
{
642-
clause = (List *)
643-
map_variable_attnos((Node *) clause,
644-
INNER_VAR, 0,
645-
part_attnos,
646-
RelationGetDescr(firstResultRel)->natts,
647-
RelationGetForm(partrel)->reltype,
648-
&found_whole_row);
649-
/* We ignore the value of found_whole_row. */
650-
clause = (List *)
651-
map_variable_attnos((Node *) clause,
652-
firstVarno, 0,
653-
part_attnos,
654-
RelationGetDescr(firstResultRel)->natts,
655-
RelationGetForm(partrel)->reltype,
656-
&found_whole_row);
657-
/* We ignore the value of found_whole_row. */
658-
}
626+
clause = (List *)
627+
map_variable_attnos((Node *) clause,
628+
INNER_VAR, 0,
629+
part_attnos,
630+
RelationGetDescr(firstResultRel)->natts,
631+
RelationGetForm(partrel)->reltype,
632+
&found_whole_row);
633+
/* We ignore the value of found_whole_row. */
634+
clause = (List *)
635+
map_variable_attnos((Node *) clause,
636+
firstVarno, 0,
637+
part_attnos,
638+
RelationGetDescr(firstResultRel)->natts,
639+
RelationGetForm(partrel)->reltype,
640+
&found_whole_row);
641+
/* We ignore the value of found_whole_row. */
659642
leaf_part_rri->ri_onConflict->oc_WhereClause =
660643
ExecInitQual((List *) clause, &mtstate->ps);
661644
}

0 commit comments

Comments
 (0)