Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit edd4473

Browse files
committed
Be lazier about partition tuple routing.
It's not necessary to fully initialize the executor data structures for partitions to which no tuples are ever routed. Consider, for example, an INSERT statement that inserts only one row: it only cares about the partition to which that one row is routed. The new function ExecInitPartitionInfo performs the initialization in question only when a particular partition is about to receive a tuple. This includes creating, validating, and saving a pointer to the ResultRelInfo, setting up for speculative insertions, translating WCOs and initializing the resulting expressions, translating returning lists and building the appropriate projection information, and setting up a tuple conversion map. One thing that's not deferred is locking the child partitions; that seems desirable but would need more thought. Still, testing shows that this makes single-row inserts significantly faster on a table with many partitions without harming the bulk-insert case. Amit Langote, reviewed by Etsuro Fujita, with a few changes by me Discussion: http://postgr.es/m/8975331d-d961-cbdd-f862-fdd3d97dc2d0@lab.ntt.co.jp
1 parent 810e7e2 commit edd4473

File tree

4 files changed

+279
-232
lines changed

4 files changed

+279
-232
lines changed

src/backend/commands/copy.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,7 @@ CopyFrom(CopyState cstate)
24692469
PartitionTupleRouting *proute;
24702470

24712471
proute = cstate->partition_tuple_routing =
2472-
ExecSetupPartitionTupleRouting(NULL, cstate->rel, 1, estate);
2472+
ExecSetupPartitionTupleRouting(NULL, cstate->rel);
24732473

24742474
/*
24752475
* If we are capturing transition tuples, they may need to be
@@ -2606,6 +2606,14 @@ CopyFrom(CopyState cstate)
26062606
*/
26072607
saved_resultRelInfo = resultRelInfo;
26082608
resultRelInfo = proute->partitions[leaf_part_index];
2609+
if (resultRelInfo == NULL)
2610+
{
2611+
resultRelInfo = ExecInitPartitionInfo(NULL,
2612+
saved_resultRelInfo,
2613+
proute, estate,
2614+
leaf_part_index);
2615+
Assert(resultRelInfo != NULL);
2616+
}
26092617

26102618
/* We do not yet have a way to insert into a foreign partition */
26112619
if (resultRelInfo->ri_FdwRoutine)

0 commit comments

Comments
 (0)