Bug in pg_stat_statements - Mailing list pgsql-hackers

From Konstantin Knizhnik
Subject Bug in pg_stat_statements
Date
Msg-id 2b91e358-0d99-43f7-be44-d2d4dbce37b3@garret.ru
Whole thread Raw
List pgsql-hackers
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?





pgsql-hackers by date:

Previous
From: Srinath Reddy Sadipiralla
Date:
Subject: Re: Making pg_rewind faster
Next
From: Daniel Gustafsson
Date:
Subject: Re: CI: Add task that runs pgindent