Re: BUG #16840: Rows not found in table partitioned by hash when not all partitions exists
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-bugs@lists.postgresql.org
Cc: michalalbrycht@gmail.com
Date: 2021-01-27T22:54:23Z
Lists: pgsql-bugs
Attachments
- fix-bug-16840.patch (text/x-diff) patch
I wrote: > Hmm, seems to be a case of faulty partition exclusion, because the > plan isn't scanning anything: Here's a proposed patch for this. The core of the problem is confusion around the number of entries in the PartitionBoundInfoData.indexes array. Each of the three types of partitioning has a different rule for that, despite which we were expecting assorted code to know what to do, and some places got it wrong for hash --- even hash-specific code :-( I propose here to solve that by explicitly storing the number of entries in PartitionBoundInfoData, and thereby removing the need for partition- strategy-independent code to know anything about the rules. I think we can get away with that in the back branches by adding "nindexes" at the end of the struct. This could break extensions that are manufacturing their own PartitionBoundInfoData structs, but it seems unlikely that there are any. Most of the patch just straightforwardly sets or uses the new field. Notably, partition_bounds_equal() and partition_bounds_copy() get significantly simpler and safer. The actual bug fix is in get_matching_hash_bounds() and perform_pruning_combine_step(), where "all partitions" needs to be 0 .. nindexes-1 not 0 .. ndatums-1. (The reason your example fails is that the OR clause should produce "all partitions potentially match", but because of this bug, it's producing a bitmask that doesn't include the partition we need.) regards, tom lane
Commits
-
Fix hash partition pruning with asymmetric partition sets.
- 7f1921cb9228 13.2 landed
- 7c53a80675df 12.6 landed
- 6f94531b0cf8 11.11 landed
- 1d9351a87c9a 14.0 landed