Re: [[BUG] pg_stat_statements crashes with var and non-var expressions in IN clause

zengman <zengman@halodbtech.com>

From: zengman <zengman@halodbtech.com>
To: Sami Imseih <samimseih@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@lists.postgresql.org>, Michael Paquier <michael@paquier.xyz>
Date: 2026-01-13T08:05:57Z
Lists: pgsql-hackers
> If there is agreement to this fix, I think it should be backpacthed to
> all versions that
> support squashing of IN-lists.
Hi,

Thank you for providing the test case. I happened to have both versions 16 and 19 on hand — it stably triggers the issue on version 19, while version 16 works perfectly fine.
Additionally, I noticed that "ars" in the comment of your patch should be "Vars"  (this seems to be a typo).

```
postgres@zxm-VMware-Virtual-Platform:~/code/postgres$ psql
psql (19devel)
Type "help" for help.

postgres=# SELECT * FROM test_squash a, test_squash b WHERE a.id IN (1, 2, 3,
b.id, b.id + 1);
TRAP: failed Assert("len_to_wrt >= 0"), File: "pg_stat_statements.c", Line: 2906, PID: 52564
postgres: postgres postgres [local] SELECT(ExceptionalCondition+0xbb)[0x59d71bc1d631]
```

```
postgres@zxm-VMware-Virtual-Platform:~$ psql
psql (16.11)
Type "help" for help.

postgres=# SELECT * FROM test_squash a, test_squash b WHERE a.id IN (1, 2, 3,
b.id, b.id + 1);
 id | data | id | data 
----+------+----+------
(0 rows)

postgres=# SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C";
                                 query                                  | calls 
------------------------------------------------------------------------+-------
 SELECT * FROM test_squash a, test_squash b WHERE a.id IN ($1, $2, $3, +|     2
 b.id, b.id + $4)                                                       | 
 SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C" |     1
 select pg_backend_pid()                                                |     1
(3 rows)
```

--
Regards,
Man Zeng
www.openhalo.org

Commits

  1. pg_stat_statements: Fix crash in list squashing with Vars