RANGE partition pruning can still exclude the default partition - #412
pg-hub-mirror[bot] wants to merge 1 commit into
Conversation
Some code added in 489247b tried to prune the DEFAULT partition when the next partition had a MINVALUE clause and likewise when the final partition to scan had a MAXVALUE clause for the final partition key in the pruning step. This code was incorrect as it could prune the default partition incorrectly in cases such as: p: PARTITION BY RANGE (a, b) p1: FOR VALUES FROM (13, 0) TO (19, MAXVALUE) pd: DEFAULT SELECT * FROM t WHERE a = 32 AND b >= -7; Here the pruning step for a = 32 and b >= -7 would see that only the default partition needs to be scan, but it would then see that the partition prior to the default had a MAXVALUE bound then prune away the default thinking that it needn't be scanned. This could result in incorrect results. Fix this by moving the code that looks for the MAXVALUE bound into the code handling BTEqualStrategyNumber so that when we're pruning with a prefix of the partition keys, we check if the bound for the offset we've calculated lands on a partition where the next partition key is bounded with MAXVALUE. If so we don't include the default partition. This leaves only the case of the first partition key. We handle that by modifying the existing code that was checking the last key covered by the given values. Author: Ewan Young <kdbase.hack@gmail.com> Reviewed-by: Tender Wang <tndrwang@gmail.com> Reviewed-by: David Rowley <dgrowleyml@gmail.com> Discussion: https://postgr.es/m/CAON2xHO=sqdqp=z8zWkybnWp0AuvefnAi2ez2vOYWrhXB6hHWQ@mail.gmail.com
|
Ewan Young <kdbase(dot)hack(at)gmail(dot)com> via pgsql-hackers · original email Thanks for the review and for tightening this up.
|
|
David Rowley <dgrowleyml(at)gmail(dot)com> via pgsql-hackers · original email On Fri, 18 Sept 2026 at 15:01, Ewan Young <kdbase(dot)hack(at)gmail(dot)com> wrote:
|
pgsql-hackersCAApHDvpmBPangWn_GGYQL=SiWNJ-MDkms23SgSVxeNdgas1SBQ@mail.gmail.comPatch files:
On Thu, 6 Aug 2026 at 22:47, Ewan Young <kdbase(dot)hack(at)gmail(dot)com> wrote: