Re: Query plans not identical for `id in(1,2,3)` and `(id=1 or id=2 or id=3)` - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: Query plans not identical for `id in(1,2,3)` and `(id=1 or id=2 or id=3)`
Date
Msg-id 8f0fefa7-54ce-4bca-a1ef-84a70f0b7663@gmx.net
Whole thread Raw
In response to Query plans not identical for `id in(1,2,3)` and `(id=1 or id=2 or id=3)`  (Ilya Basin <basinilya@gmail.com>)
Responses Re: Query plans not identical for `id in(1,2,3)` and `(id=1 or id=2 or id=3)`  (Ilya Basin <basinilya@gmail.com>)
List pgsql-general
Ilya Basin schrieb am 09.03.2024 um 20:08:
> Hi List.
>
> I have a list of bigint keys and I need to retrieve rows by these keys. Normally, I would split this list into pages
ofsize 900 and perform several `SELECT ... WHERE key in($1,$2,...)`. However, the proprietary ORM we use can only
producethis SQL: `SELECT ... WHERE (key=$1 or key=$2 or ...)`. Surprisingly, PostgreSQL planner treats these two SQLs
differently:
>
> - ```select * FROM "audittrail$referencelogline" where id in ( 1 , 2 , 3 )```
>
> Index Scan
> https://i.stack.imgur.com/dr8oz.png
>
> - ```select * FROM "audittrail$referencelogline" where id = 1 or id = 2 or id = 3```
>
> A lot of "Bitmap Index Scan" for each value
> https://i.stack.imgur.com/dnErs.png
>
> Is it possible to configure PostgreSQL 12.16 to treat the second query as the first?

Can you convince your obfuscation layer to send an array value (containing all IDs) and change the query to:

     select * FROM "audittrail$referencelogline" where id = any(?)




pgsql-general by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: Query plans not identical for `id in(1,2,3)` and `(id=1 or id=2 or id=3)`
Next
From: sud
Date:
Subject: Re: Question related to partitioning with pg_partman