Re: Partition-wise join for join between (declaratively) partitioned tables
Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
On Tue, Sep 12, 2017 at 1:16 PM, Amit Langote <Langote_Amit_f8@lab.ntt.co.jp> wrote: > On 2017/09/11 21:07, Ashutosh Bapat wrote: >> On Mon, Sep 11, 2017 at 5:19 PM, Robert Haas <robertmhaas@gmail.com> wrote: >>> On Mon, Sep 11, 2017 at 6:45 AM, Ashutosh Bapat >>> <ashutosh.bapat@enterprisedb.com> wrote: >>>> So, all partitioned partitions are getting locked correctly. Am I >>>> missing something? >>> >>> That's not a valid test. In that scenario, you're going to hold all >>> the locks acquired by the planner, all the locks acquired by the >>> rewriter, and all the locks acquired by the executor, but when using >>> prepared queries, it's possible to execute the plan after the planner >>> and rewriter locks are no longer held. >> >> I see the same thing when I use prepare and execute > > So I looked at this a bit closely and came to the conclusion that we may > not need to keep partitioned table RT indexes in the > (Merge)Append.partitioned_rels after all, as far as execution-time locking > is concerned. > > Consider two cases: > > 1. Plan is created and executed in the same transaction > > In this case, locks taken on the partitioned tables by the planner will > suffice. > > 2. Plan is executed in a different transaction from the one in which it > was created (a cached plan) > > In this case, AcquireExecutorLocks will lock all the relations in > PlannedStmt.rtable, which must include all partitioned tables of all > partition trees involved in the query. Of those, it will lock the tables > whose RT indexes appear in PlannedStmt.nonleafResultRelations with > RowExclusiveLock mode. PlannedStmt.nonleafResultRelations is a global > list of all partitioned table RT indexes obtained by concatenating > partitioned_rels lists of all ModifyTable nodes involved in the query > (set_plan_refs does that). We need to distinguish nonleafResultRelations, > because we need to take the stronger lock on a given table before any > weaker one if it happens to appear in the query as a non-result relation > too, to avoid lock strength upgrade deadlock hazard. > > Moreover, because all the tables from plannedstmt->rtable, including the > partitioned tables, will be added to PlannedStmt.relationsOids, any > invalidation events affecting the partitioned tables (for example, > add/remove a partition) will cause the plan involving partitioned tables > to be recreated. > > In none of this do we rely on the partitioned table RT indexes appearing > in the (Merge)Append node itself. Maybe, we should just remove > partitioned_rels from (Merge)AppendPath and (Merge)Append node in a > separate patch and move on. > > Thoughts? Yes, I did the same analysis (to which I refer in my earlier reply to you). I too think we should just remove partitioned_rels from Append paths. But then the question is those are then transferred to ModifyTable node in create_modifytable_plan() and use it for something else. What should we do about that code? I don't think we are really using that list from ModifyTable node as well, so may be we could remove it from there as well. What do you think? Does that mean partitioned_rels isn't used at all in the code? -- Best Wishes, Ashutosh Bapat EnterpriseDB Corporation The Postgres Database Company
Commits
-
Add test for partitionwise join involving default partition.
- 4513d3a4be0b 12.0 landed
-
Rewrite the code that applies scan/join targets to paths.
- 11cf92f6e2e1 11.0 cited
-
Fix code related to partitioning schemes for dropped columns.
- cf7ab13bfb45 11.0 landed
-
Copy information from the relcache instead of pointing to it.
- 45866c75507f 11.0 landed
-
Basic partition-wise join functionality.
- f49842d1ee31 11.0 landed
-
Associate partitioning information with each RelOptInfo.
- 9140cf8269b0 11.0 landed
-
Expand partitioned table RTEs level by level, without flattening.
- 0a480502b092 11.0 landed
-
Set partitioned_rels appropriately when UNION ALL is used.
- 448aa36e8b96 10.0 landed
- 1555566d9ee1 11.0 landed
-
Remove dedicated B-tree root-split record types.
- 0c504a80cf2e 11.0 cited
-
Assorted preparatory refactoring for partition-wise join.
- e139f1953f29 11.0 cited
-
Teach adjust_appendrel_attrs(_multilevel) to do multiple translations.
- 480f1f4329f1 11.0 cited
-
Avoid unnecessary single-child Append nodes.
- d57929afc706 11.0 cited
-
Revisit handling of UNION ALL subqueries with non-Var output columns.
- dd4134ea56cb 9.2.0 cited