Re: BUG #17540: Prepared statement: PG switches to a generic query plan which is consistently much slower

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Andrei Lepikhov <a(dot)lepikhov(at)postgrespro(dot)ru>
Cc: David Rowley <dgrowleyml(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, william(dot)duclot(at)gmail(dot)com, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #17540: Prepared statement: PG switches to a generic query plan which is consistently much slower
Date: 2023-11-01 02:20:49
Message-ID: CAMbWs4-zYenAVp-fmgtvBtWKoauL8gBqUHctP6rOmny5Ox8SkA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

On Tue, Oct 24, 2023 at 12:25 PM Andrei Lepikhov <a(dot)lepikhov(at)postgrespro(dot)ru>
wrote:

> Setting aside the thread's subject, I am interested in this feature
> because of its connection with the SJE feature and the same issue raised
> [1] during the discussion.

Thanks for taking an interest in this.

I rebased this patch over the SJE commit, and found that it can help
discard redundant IS_NOT_NULL quals added by SJE logic if we've
successfully removed some self-joins on primary keys, as shown by the
regression test plan changes, which IMO makes this patch look more
useful in practice.

> Although the patch is already in a good state, some improvements can be
> made. Look:
> explain (costs off)
> SELECT oid,relname FROM pg_class
> WHERE oid < 5 OR (oid = 1 AND oid IS NULL);
>
> Bitmap Heap Scan on pg_class
> Recheck Cond: ((oid < '5'::oid) OR ((oid = '1'::oid) AND (oid IS
> NULL)))
> -> BitmapOr
> -> Bitmap Index Scan on pg_class_oid_index
> Index Cond: (oid < '5'::oid)
> -> Bitmap Index Scan on pg_class_oid_index
> Index Cond: ((oid = '1'::oid) AND (oid IS NULL))
>
> If we go deeply through the filter, I guess we could replace such buried
> clauses.

Yeah, we can do that by exploring harder on OR clauses. But for now I
think it's more important for this patch to introduce the
'reduce-quals-to-constant' mechanism. As a start I think it'd be better
to keep the logic simple for review. In the future maybe we can extend
it to consider more than just NullTest quals, for example we could also
consider applicable constraint expressions of the given relation.

Thanks
Richard

Attachment Content-Type Size
v7-0001-Reduce-NullTest-quals-to-constant-TRUE-or-FALSE.patch application/octet-stream 32.9 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Andrei Lepikhov 2023-11-01 03:55:45 Re: BUG #18170: Unexpected error: no relation entry for relid 3
Previous Message Tom Lane 2023-10-31 14:51:52 Re: BUG #18173: ERROR: could not identify a comparison function for type unknown

Browse pgsql-hackers by date

  From Date Subject
Next Message shihao zhong 2023-11-01 02:30:33 Re: EXCLUDE COLLATE in CREATE/ALTER TABLE document
Previous Message Chapman Flack 2023-11-01 02:17:24 Re: Extract numeric filed in JSONB more effectively