pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Konstantin Knizhnik <knizhnik@garret.ru>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Bug in pg_stat_statements
Date: Thu, 23 Oct 2025 19:21:33 +0300
Message-ID: <2b91e358-0d99-43f7-be44-d2d4dbce37b3@garret.ru> (raw)

Hi hackers.


In PG18 gthere is bug either in pg_stat_statements.c, either in 
queryjumblefuncs.c.

Repro (you need Postgres build with asserts and pg_stat_statements 
included in shared_preload_librarties:

create function f(a integer[], out x integer, out y integer) returns 
record as $$            begin
        x = a[1];
        y = a[2];
    end;
$$ language plpgsql;

create table t(x integer);
select ((f(array[1,2]))).* from t;

The problems is caused by ((...)).* which cause to include the same 
array literal twice in JumbleQuery.
But pg_stat_stataement assumes that any occurrence of constant is unique 
and it cause assertion failure here:

         /* Copy next chunk (what precedes the next constant) */
         len_to_wrt = off - last_off;
         len_to_wrt -= last_tok_len;
         Assert(len_to_wrt >= 0);

So we should either exclude duplicates in RecordConstLocation 
(queryjumblefuncs.c)
either in generate_normalized_query in pg_stat_statements.c

What is considered to be more correct?







view thread (17+ messages)  latest in thread

Message-ID: <2b91e358-0d99-43f7-be44-d2d4dbce37b3@garret.ru>
Permalink:  ../2b91e358-0d99-43f7-be44-d2d4dbce37b3@garret.ru/
Also on:    postgresql.org/message-id/2b91e358-0d99-43f7-be44-d2d4dbce37b3@garret.ru

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: knizhnik@garret.ru, pgsql-hackers@lists.postgresql.org
  Subject: Re: Bug in pg_stat_statements
  In-Reply-To: <2b91e358-0d99-43f7-be44-d2d4dbce37b3@garret.ru>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox