Re: BUG #18344: Pruning tables partitioned by bool range fails with invalid strategy

From: Tender Wang <tndrwang(at)gmail(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Amit Langote <amitlan(at)postgresql(dot)org>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, exclusion(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18344: Pruning tables partitioned by bool range fails with invalid strategy
Date: 2024-02-19 08:21:11
Message-ID: CAHewXNk=SMDNGw5vwuUr33q9jnSmK4J4jaxTMs-UJiK7Bm_=eg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

David Rowley <dgrowleyml(at)gmail(dot)com> 于2024年2月19日周一 07:49写道:

> On Mon, 19 Feb 2024 at 05:25, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> >
> > David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> > > We can do the same for BooleanTests. Given a clause such as: "partkey
> > > IS NOT false", we can just generate the clause "partkey IS true OR
> > > partkey IS NULL" and recursively generate steps for that.
> >
> > +1 ... sounds clean and clearly correct.
>
> Here's a more complete patch for this. I included some tests for LIST
> and RANGE partitioned tables. I did manual testing for HASH, and was
> on the fence about covering that too.
>
> I did try the following using the table from the tests:
>
> select * from boolrangep where a is not true and not b and c = 25 and
> a is not null;
>
> When will be effectively transformed into:
>
> select * from boolrangep where (a is false or a is null) and not b and
> c = 25 and a is not null;
>
> It seems that's unable to prune the NULL partition but that mostly
> seems to be due to a limitation of the current design. I'm not sure
> it's worth going to any additional trouble to make that work. It
> seems a bit unlikely, especially so given how long the BooleanTest
> pruning stuff was broken for before anyone noticed.
>
> > > I'm tempted to go a bit further in master only and add support for
> > > bool IS NOT UNKNOWN and bool IS UNKNOWN using the same method.
> >
> > These are the same as IS NOT NULL and IS NULL, so I don't see the
> > need for an OR?
>
> Uh, yeah. True. That makes it even more simple. Just use
> PARTCLAUSE_MATCH_NULLNESS.
>
> David
>

After git apply fix_partprune_BooleanTests.patch on master, I got below
warnings:

partprune.c: In function ‘match_clause_to_partition_key’:
../../../src/include/nodes/nodes.h:221:25: warning: initialization of
‘BooleanTest *’ {aka ‘struct BooleanTest *’} from incompatible pointer type
‘Expr *’ {aka ‘struct Expr *’} [-Wincompatible-pointer-types]
221 | #define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj))
| ^
partprune.c:1824:32: note: in expansion of macro ‘copyObject’
1824 | BooleanTest *new_booltest = copyObject(clause);

Maybe this: BooleanTest *new_booltest = (BooleanTest *) copyObject(clause);

--
Tender Wang
OpenPie: https://en.openpie.com/

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Masahiko Sawada 2024-02-19 09:12:23 Re: Potential data loss due to race condition during logical replication slot creation
Previous Message Andrew Dunstan 2024-02-19 01:02:50 Re: BUG #18350: Modifying predefined roles' unlimited connections for VA STIG cybersecurity checklist