mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Fix state reversal after partition tuple routing
We make some changes to ModifyTableState and the EState it uses whenever we route tuples to partitions; but we weren't restoring properly in all cases, possibly causing crashes when partitions with different tuple descriptors are targeted by tuples inserted in the same command. Refactor some code, creating ExecPrepareTupleRouting, to encapsulate the needed state changing logic, and have it invoked one level above its current place (ie. put it in ExecModifyTable instead of ExecInsert); this makes it all more readable. Add a test case to exercise this. We don't support having views as partitions; and since only views can have INSTEAD OF triggers, there is no point in testing for INSTEAD OF when processing insertions into a partitioned table. Remove code that appears to support this (but which is actually never relevant.) In passing, fix location of some very confusing comments in ModifyTableState. Reported-by: Amit Langote Author: Etsuro Fujita, Amit Langote Discussion: https://postgr/es/m/0473bf5c-57b1-f1f7-3d58-455c2230bc5f@lab.ntt.co.jp
This commit is contained in:
@ -2633,13 +2633,12 @@ CopyFrom(CopyState cstate)
|
||||
if (cstate->transition_capture != NULL)
|
||||
{
|
||||
if (resultRelInfo->ri_TrigDesc &&
|
||||
(resultRelInfo->ri_TrigDesc->trig_insert_before_row ||
|
||||
resultRelInfo->ri_TrigDesc->trig_insert_instead_row))
|
||||
resultRelInfo->ri_TrigDesc->trig_insert_before_row)
|
||||
{
|
||||
/*
|
||||
* If there are any BEFORE or INSTEAD triggers on the
|
||||
* partition, we'll have to be ready to convert their
|
||||
* result back to tuplestore format.
|
||||
* If there are any BEFORE triggers on the partition,
|
||||
* we'll have to be ready to convert their result back to
|
||||
* tuplestore format.
|
||||
*/
|
||||
cstate->transition_capture->tcs_original_insert_tuple = NULL;
|
||||
cstate->transition_capture->tcs_map =
|
||||
@ -2768,12 +2767,13 @@ CopyFrom(CopyState cstate)
|
||||
* tuples inserted by an INSERT command.
|
||||
*/
|
||||
processed++;
|
||||
}
|
||||
|
||||
if (saved_resultRelInfo)
|
||||
{
|
||||
resultRelInfo = saved_resultRelInfo;
|
||||
estate->es_result_relation_info = resultRelInfo;
|
||||
}
|
||||
/* Restore the saved ResultRelInfo */
|
||||
if (saved_resultRelInfo)
|
||||
{
|
||||
resultRelInfo = saved_resultRelInfo;
|
||||
estate->es_result_relation_info = resultRelInfo;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user