Re: [HACKERS] Partition-wise join for join between (declaratively)partitioned tables - Mailing list pgsql-hackers
From | Amit Langote |
---|---|
Subject | Re: [HACKERS] Partition-wise join for join between (declaratively)partitioned tables |
Date | |
Msg-id | d2f1cdcb-ebb4-76c5-e471-79348ca5d7a7@lab.ntt.co.jp Whole thread Raw |
In response to | Re: [HACKERS] Partition-wise join for join between (declaratively)partitioned tables (Robert Haas <robertmhaas@gmail.com>) |
Responses |
Re: [HACKERS] Partition-wise join for join between (declaratively)partitioned tables
Re: [HACKERS] Partition-wise join for join between (declaratively)partitioned tables Re: [HACKERS] Partition-wise join for join between (declaratively)partitioned tables |
List | pgsql-hackers |
On 2017/09/08 4:04, Robert Haas wrote: > On Tue, Sep 5, 2017 at 7:01 AM, Ashutosh Bapat > <ashutosh.bapat@enterprisedb.com> wrote: >> accumulate_append_subpath() is executed for every path instead of >> every relation, so changing it would collect the same list multiple >> times. Instead, I found the old way of associating all intermediate >> partitions with the root partitioned relation work better. Here's the >> updated patch set. > > When I tried out patch 0001, it crashed repeatedly during 'make check' > because of an assertion failure in get_partitioned_child_rels. It > seemed to me that the way the patch was refactoring > expand_inherited_rtentry involved more code rearrangement than > necessary, so I reverted all the code rearrangement and just kept the > functional changes, and all the crashes went away. (That refactoring > also failed to initialize has_child properly.) When I tried the attached patch, it doesn't seem to expand partitioning inheritance in step-wise manner as the patch's title says. I think the rewritten patch forgot to include Ashutosh's changes to expand_single_inheritance_child() whereby the AppendRelInfo of the child will be marked with the direct parent instead of always the root parent. I updated the patch to include just those changes. I'm not sure about one of the Ashutosh's changes whereby the child PlanRowMark is also passed to expand_partitioned_rtentry() to use as the parent PlanRowMark. I think the child RTE, child RT index and child Relation are fine, because they are necessary for creating AppendRelInfos in a desired way for later planning steps. But PlanRowMarks are not processed within the planner afterwards and do not need to be marked with the immediate parent-child association in the same way that AppendRelInfos need to be. I also included the changes to add_paths_to_append_rel() from my patch on the "path toward faster partition pruning" thread. We'd need that change, because while add_paths_to_append_rel() is called for all partitioned table RTEs in a given partition tree, expand_inherited_rtentry() would have set up a PartitionedChildRelInfo only for the root parent, so get_partitioned_child_rels() would not find the same for non-root partitioned table rels and crash failing the Assert. The changes I made are such that we call get_partitioned_child_rels() only for the parent rels that are known to correspond root partitioned tables (or as you pointed out on the thread, "the table named in the query" as opposed those added to the query as result of inheritance expansion). In addition to the relkind check on the input RTE, it would seem that checking that the reloptkind is RELOPT_BASEREL would be enough. But actually not, because if a partitioned table is accessed in a UNION ALL query, reloptkind even for the root partitioned table (the table named in the query) would be RELOPT_OTHER_MEMBER_REL. The only way to confirm that the input rel is actually the root partitioned table is to check whether its parent rel is not RTE_RELATION, because the parent in case of UNION ALL Append is a RTE_SUBQUERY RT entry. > One thing I notice is that if I rip out the changes to initsplan.c, > the new regression test still passes. If it's possible to write a > test that fails without those changes, I think it would be a good idea > to include one in the patch. That's certainly one of the subtler > parts of this patch, IMHO. Back when this (step-wise expansion of partition inheritance) used to be a patch in the original declarative partitioning patch series, Ashutosh had reported a test query [1] that would fail getting a plan, for which we came up with the initsplan.c changes in this patch as the solution: ERROR: could not devise a query plan for the given query I tried that query again without the initsplan.c changes and somehow the same error does not occur anymore. It's strange because without the initsplan.c changes, there is no way for partitions lower in the tree than the first level to get the direct_lateral_relids and lateral_relids from the root parent rel. Maybe, Ashutosh has a way to devise the failing query again. I also confirmed that the partition-pruning patch set works fine with this patch instead of the patch on that thread with the same functionality, which I will now drop from that patch set. Sorry about the wasted time. Thanks, Amit [1] https://www.postgresql.org/message-id/CAFjFpReZF34MDbY95xoATi0xVj2mAry4-LHBWVBayOc8gj%3Diqg%40mail.gmail.com -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers
Attachment
pgsql-hackers by date: