On 11 December 2017 at 22:23, Ashutosh Bapat <ashutosh.ba...@enterprisedb.com> wrote: > I think this didn't work with inheritance before partition-wise join > as well for the same reason.
Yeah, I was just demonstrating a reason that the plans are not identical from querying a partitioned table when partition pruning eliminates all but one partition vs directly querying that single partition. I've been attaching some regression test changes which demonstrate some other subtle differences along with each version of the patch. I just wanted to be open with these subtle differences that I've encountered while working on this. > Probably, we could do it if unique paths (sorted paths which can be > unique-ified) bubble up the Append hierarchy. We already have code in > add_paths_to_append_rel() to create sorted paths when even a single > child has an index on it. Sometime in the future, I'd like to see some sort of UniqueKeys List in RelOptInfo which is initially populated by using looking at the unique indexes during build_simple_rel(). The idea is that these UniqueKeys would get propagated into RELOPT_JOINRELs when the join condition matches a set of unique keys on the other side of the join. e.g. If the outer side of the join had a UniqueKey matching the join condition then we could take all of the UniqueKeys from the RelOptInfo for the inner side of the join (and vice versa). This infrastructure would allow us to no-op a DISTINCT when the RelOptInfo has targetlist items which completely cover at least one UniqueKey set, or not bother performing a sort for a GROUP BY when the GROUP BY clause is covered by a UniqueKey. To fix the case we're discussing, we can also propagate those UniqueKeys to an AppendPath with a single subpath similar to how I'm propagating the PathKeys for the same case in this patch, that way the unique join code would find the UniqueKeys instead of what it does today and not find any unique indexes on the partitioned table. -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services