Re: Bug in pg_stat_statements

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: Konstantin Knizhnik <knizhnik(at)garret(dot)ru>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Bug in pg_stat_statements
Date: 2025-10-24 17:55:24
Message-ID: CAA5RZ0t6rynOzvABTbHZPF9ydKoay5LN+_iM3hHk0ni_Qu_9tg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> > > Having said
> > > that it seems that another solution would be to check for duplicated constants
> > > in fill_in_constant_length
> >
> > Yes, I started thinking along these lines as well, where we check for
> > duplicates
> > in fill_in_constant_length; or after jumbling, we de-duplicate locations if we
> > have a squashable list, which is what I have attached with updated test cases.
> >
> > This means we do need to scan the locations one extra time during jumbling,
> > but I don't see that as a problem. Maybe there is another better way?
>
> Why? What I hand in mind is something like this, after a quick test it seems to
> be able to address both the original case and the one you've discovered.

ahh, what you have works because clocations is sorted by location before
the loop starts in `fill_in_constant_lengths` , so comparing locations
makes sense in this case. I am OK with this.

```
/*
* Sort the records by location so that we can process them in order while
* scanning the query text.
*/
if (jstate->clocations_count > 1)
qsort(jstate->clocations, jstate->clocations_count,
sizeof(LocationLen), comp_location);
```

I was really hoping that the fix could be inside of query jumbling, as I think
pg_stat_statements or any consumers of query jumbling don't need to
care more about squashing ( or other internals of jumbling ).
So now I also wonder if we should also move:

```
static char *generate_normalized_query(JumbleState *jstate, const char *query,
int query_loc, int *query_len_p);

static void fill_in_constant_lengths(JumbleState *jstate, const char *query,
int query_loc);
```

from pg_stat_statements.c to queryjumblefuncs.c?

--
Sami Imseih
Amazon Web Services (AWS)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2025-10-24 18:23:23 Re: Add uuid_to_base32hex() and base32hex_to_uuid() built-in functions
Previous Message Nathan Bossart 2025-10-24 17:48:31 Re: create table like including storage parameter