expanding inheritance in partition bound order
Amit Langote <langote_amit_f8@lab.ntt.co.jp>
From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2017-08-04T07:38:46Z
Lists: pgsql-hackers
Attachments
- 0001-Add-get_all_partition_oids-and-get_partition_oids-v1.patch (text/plain) patch v1-0001
- 0002-Decouple-RelationGetPartitionDispatchInfo-from-execu-v1.patch (text/plain) patch v1-0002
The current way to expand inherited tables, including partitioned tables, is to use either find_all_inheritors() or find_inheritance_children() depending on the context. They return child table OIDs in the (ascending) order of those OIDs, which means the callers that need to lock the child tables can do so without worrying about the possibility of deadlock in some concurrent execution of that piece of code. That's good. For partitioned tables, there is a possibility of returning child table (partition) OIDs in the partition bound order, which in addition to preventing the possibility of deadlocks during concurrent locking, seems potentially useful for other caller-specific optimizations. For example, tuple-routing code can utilize that fact to implement binary-search based partition-searching algorithm. For one more example, refer to the "UPDATE partition key" thread where it's becoming clear that it would be nice if the planner had put the partitions in bound order in the ModifyTable that it creates for UPDATE of partitioned tables [1]. So attached are two WIP patches: 0001 implements two interface functions: List *get_all_partition_oids(Oid, LOCKMODE) List *get_partition_oids(Oid, LOCKMODE) that resemble find_all_inheritors() and find_inheritance_children(), respectively, but expect that users call them only for partitioned tables. Needless to mention, OIDs are returned with canonical order determined by that of the partition bounds and they way partition tree structure is traversed (top-down, breadth-first-left-to-right). Patch replaces all the calls of the old interface functions with the respective new ones for partitioned table parents. That means expand_inherited_rtentry (among others) now calls get_all_partition_oids() if the RTE is for a partitioned table and find_all_inheritors() otherwise. In its implementation, get_all_partition_oids() calls RelationGetPartitionDispatchInfo(), which is useful to generate the result list in the desired partition bound order. But the current interface and implementation of RelationGetPartitionDispatchInfo() needs some rework, because it's too closely coupled with the executor's tuple routing code. Applying just 0001 will satisfy the requirements stated in [1], but it won't look pretty as is for too long. So, 0002 is a patch to refactor RelationGetPartitionDispatchInfo() and relevant data structures. For example, PartitionDispatchData has now been simplified to contain only the partition key, partition descriptor and indexes array, whereas previously it also stored the relation descriptor, partition key execution state, tuple table slot, tuple conversion map which are required for tuple-routing. RelationGetPartitionDispatchInfo() no longer generates those things, but returns just enough information so that a caller can generate and manage those things by itself. This simplification makes it less cumbersome to call RelationGetPartitionDispatchInfo() in other places. Thanks, Amit [1] https://www.postgresql.org/message-id/CA%2BTgmoajC0J50%3D2FqnZLvB10roY%2B68HgFWhso%3DV_StkC6PWujQ%40mail.gmail.com
Commits
-
Make RelationGetPartitionDispatchInfo expand depth-first.
- 77b6b5e9ceca 11.0 landed
-
Expand partitioned tables in PartDesc order.
- 30833ba154e0 11.0 landed
-
Don't lock tables in RelationGetPartitionDispatchInfo.
- 7c0ca2900f7c 10.0 landed
- 54cde0c4c058 11.0 landed
-
Speed up dropping tables with many partitions.
- c1e0e7e1d790 10.0 cited