| From: | Manu <manuelreyesbravo(at)gmail(dot)com> |
|---|---|
| To: | Sehrope Sarkuni <sehrope(at)jackdb(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: Bug: ATTACH PARTITION can leave rows violating default partition constraint |
| Date: | 2026-10-06 22:24:34 |
| Message-ID: | 179132547485.924312.12482354023369760390@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Sehrope,
> QueuePartitionConstraintValidation() in tablecmds.c stores only the first
> element of the implicit-AND list it is handed. [...] When the new bound
> is a LIST bound that includes NULL, the negation of the bound has two
> conjuncts, so only the IS NOT NULL test is ever checked.
I reproduced this on master (10b6e2a3d66), and the analysis matches what I
see. With the patch the ATTACH is correctly rejected, and make check
passes (239/239).
While confirming it I ran a few more shapes against master, and the bug is
a little wider than the single-column case in the test: it also leaves
orphan rows when the partition key spans several columns, and when the
default partition is itself partitioned (the row ends up in the
sub-default and the same pruning hides it). Both are the same root cause
-- the NULL-inclusive LIST bound is what makes the negation a two-conjunct
AND -- and both are fixed by the patch, since make_ands_explicit() in the
shared function validates the whole conjunction regardless of the bound's
shape. The cases I tried, for the record:
- single-column LIST, IN (v, NULL): leaks on master, fixed.
- multi-column table, LIST on one column + NULL: leaks on master, fixed.
- default partition that is itself partitioned: leaks on master, fixed
(the row lands in the sub-default).
- single-column and composite RANGE bounds: already rejected, unchanged.
- a valid ATTACH into a NULL-inclusive default: still succeeds, no
over-rejection.
Given that, it might be worth adding a multi-column or a sub-partitioned
case next to the one you have, so the wider shape is covered as well --
though the fix is at the root, so a single case does guard it.
The patch looks correct to me.
Regards,
Manu
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nikolay Samokhvalov | 2026-10-06 22:37:12 | Re: postgres_fdw: transaction mode inheritance corner cases |
| Previous Message | Zsolt Parragi | 2026-10-06 22:06:26 | Re: [Patch] New pg_stat_tablespace view |