Re: Bug in pg_stat_statements - Mailing list pgsql-hackers

From Dmitry Dolgov
Subject Re: Bug in pg_stat_statements
Date
Msg-id 637jlyhmvrwmzlpzj2xo47phvek7le36epdujv4oxvd4ujb6x2@n3mh2lapgdhd
Whole thread Raw
In response to Re: Bug in pg_stat_statements  (Sami Imseih <samimseih@gmail.com>)
Responses Re: Bug in pg_stat_statements
List pgsql-hackers
> On Fri, Oct 24, 2025 at 09:17:22AM -0500, Sami Imseih wrote:
> > 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.

diff --git a/contrib/pg_stat_statements/pg_stat_statements.c b/contrib/pg_stat_statements/pg_stat_statements.c
index f2187167..f17a2b79 100644
--- a/contrib/pg_stat_statements/pg_stat_statements.c
+++ b/contrib/pg_stat_statements/pg_stat_statements.c
@@ -3008,11 +3008,17 @@ fill_in_constant_lengths(JumbleState *jstate, const char *query,

                Assert(loc >= 0);

-               if (locs[i].squashed)
-                       continue;                       /* squashable list, ignore */
-
                if (loc <= last_loc)
+               {
+                       locs[i].length = -1;
                        continue;                       /* Duplicate constant, ignore */
+               }
+
+               if (locs[i].squashed)
+               {
+                       last_loc = loc;
+                       continue;                       /* squashable list, ignore */
+               }

                /* Lex tokens until we find the desired constant */
                for (;;)



pgsql-hackers by date:

Previous
From: Ivan Bykov
Date:
Subject: Re: IPC/MultixactCreation on the Standby server
Next
From: Greg Sabino Mullane
Date:
Subject: Re: display hot standby state in psql prompt