Re: BUG #16840: Rows not found in table partitioned by hash when not all partitions exists

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: michalalbrycht(at)gmail(dot)com
Subject: Re: BUG #16840: Rows not found in table partitioned by hash when not all partitions exists
Date: 2021-01-27 22:54:23
Message-ID: 2503822.1611788063@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Attachment Content-Type Size
fix-bug-16840.patch text/x-diff 19.9 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2021-01-28 05:48:48 BUG #16841: psql -- \d tablename , displays "Error : column c.relhasoids does not exit"
Previous Message David G. Johnston 2021-01-27 22:33:37 Re: Inconsistent application of [, ...] in documentation