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?