Re: pg_stat_statements and "IN" conditions

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Sergei Kornilov <sk(at)zsrv(dot)org>, yasuo(dot)honda(at)gmail(dot)com, tgl(at)sss(dot)pgh(dot)pa(dot)us, smithpb2250(at)gmail(dot)com, vignesh21(at)gmail(dot)com, michael(at)paquier(dot)xyz, nathandbossart(at)gmail(dot)com, stark(dot)cfm(at)gmail(dot)com, geidav(dot)pg(at)gmail(dot)com, marcos(at)f10(dot)com(dot)br, robertmhaas(at)gmail(dot)com, david(at)pgmasters(dot)net, pgsql-hackers(at)postgresql(dot)org, pavel(dot)trukhanov(at)gmail(dot)com, Sutou Kouhei <kou(at)clear-code(dot)com>
Subject: Re: pg_stat_statements and "IN" conditions
Date: 2025-02-11 18:00:27
Message-ID: CAA5RZ0v6h-ohXTV6wWsHN1TKW5XHOkfu+0TpTKXauYfYfhPaeg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I do not have an explanation from the patch yet, but I have a test
that appears to show unexpected results. I only tested a few datatypes,
but from what I observe, some merge as expected and others do not;
i.e. int columns merge correctly but bigint do not.

"""
show pg_stat_statements.query_id_const_merge ;
create table foo (col_int int, col_smallint smallint, col_bigint
bigint, col_float float, col_text text, col_varchar varchar);
select from foo where col_int in (1, 2, 3);
select from foo where col_int in (1, 2, 3, 4);
select from foo where col_int in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
select from foo where col_smallint in (1, 2, 3);
select from foo where col_smallint in (1, 2, 3, 4);
select from foo where col_bigint in (1, 2, 3);
select from foo where col_bigint in (1, 2, 3, 4);
select from foo where col_bigint in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
select from foo where col_float in (1, 2, 3);
select from foo where col_float in (1, 2, 3, 4);
select query, queryid, calls from pg_stat_statements where query like
'select from foo where%' order by 1 desc ;
"""

postgres=# show pg_stat_statements.query_id_const_merge ;
pg_stat_statements.query_id_const_merge
-----------------------------------------
on
(1 row)

....
.......
..........

postgres=# select query, queryid, calls from pg_stat_statements where
query like 'select from foo where%' order by 1 desc ;
query
| queryid | calls
-------------------------------------------------------------------------------+----------------------+-------
select from foo where col_smallint in (...)
| -2065640271713949220 | 2
select from foo where col_int in (...)
| 2911888824129257715 | 3
select from foo where col_float in ($1, $2, $3, $4)
| -6847088148705359339 | 1
select from foo where col_float in ($1, $2, $3)
| 1631437678183488606 | 1
select from foo where col_bigint in ($1, $2, $3, $4, $5, $6, $7, $8,
$9, $10) | 3174053975478689499 | 1
select from foo where col_bigint in ($1, $2, $3, $4)
| -5236067031911646410 | 1
select from foo where col_bigint in ($1, $2, $3)
| -5529594240898645457 | 1
(7 rows)

---

Sami

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Matthias van de Meent 2025-02-11 18:03:11 Re: Expanding HOT updates for expression and partial indexes
Previous Message Jeff Davis 2025-02-11 18:00:14 Re: Proposal: "query_work_mem" GUC, to distribute working memory to the query's individual operators