Re: queryId constant squashing does not support prepared statements
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael@paquier.xyz>
Cc: Sami Imseih <samimseih@gmail.com>, Dmitry Dolgov <9erthalion6@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-05-06T03:09:43Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix typo in comment
- a3994ec6acb2 18.0 landed
-
Make query jumbling also squash PARAM_EXTERN params
- c2da1a5d6325 18.0 landed
-
Fix squashing algorithm for query texts
- 0f65f3eec478 18.0 landed
-
pg_stat_statements: Fix parameter number gaps in normalized queries
- 3c03b8cd7979 13.22 landed
- 8a1459f62ad1 14.19 landed
- 130300a15407 15.14 landed
- 7e8b44f4e0e6 16.10 landed
- 290e8ab32ac5 17.6 landed
- 35a428f30b15 18.0 landed
Michael Paquier <michael@paquier.xyz> writes: > On Thu, May 01, 2025 at 03:57:16PM -0500, Sami Imseih wrote: >> I think what we should really allow the broader scope of expressions that >> are allowed via prepared statements, and this will make this implementation >> consistent between prepared vs non-prepared statements. I don't see why >> not. In fact, when we are examining the ArrayExpr, I think the only >> thing we should >> not squash is if we find a Sublink ( i.e. SELECT statement inside the array ). > Likely so. I don't have anything else than Sublink in mind that would > be worth a special case.. I think this is completely wrong. As simple examples, there is nothing even a little bit comparable between the behaviors of t1.x IN (1, 2, 3) t1.x IN (1, 2, t2.y) t1.x IN (1, 2, random()) Squashing these to look the same would be doing nobody any favors. I do agree that treating PARAM_EXTERN Params the same as constants for this purpose is a reasonable thing to do, on three arguments: 1. A PARAM_EXTERN Param actually behaves largely the same as a Const so far as a query is concerned: it does not change value across the execution of the query. (This is not true of other kinds of Params.) 2. It's very much dependent on the client-side stack whether a given value that is constant in the mind of the application will be passed to the backend as a Const or a Param. (This is okay because #1.) 3. Even if the value is passed as a Param, the planner might replace it by a Const by means of generating a custom query plan. So the boundary between PARAM_EXTERN Params and Consts is actually mighty squishy, and thus I think it makes sense for pg_stat_statements to mash them together. But this logic does not extend to Vars or function calls or much of anything else. Maybe in the future we could have a discussion about whether expressions involving only Params, Consts, and immutable functions (say, "$1 + 1") could be mashed as though they were constants, on the grounds that they'd have been reduced to a single constant if the planner had chosen to generate a custom plan. But I think it's too late to consider that for v18. I'd be okay with the rule "treat any list of Consts and PARAM_EXTERN Params the same as any other" for v18. I also agree with Alvaro that this discussion doesn't justify a revert. If the pre-v18 behavior wasn't chiseled on stone tablets, the new behavior isn't either. We can improve it some more later. regards, tom lane