Skip to content

Commit 0f65f3e

Browse files
author
Álvaro Herrera
committed
Fix squashing algorithm for query texts
The algorithm to squash lists of constants added by commit 62d712e was a bit too simplistic; we wanted to avoid adding unnecessary complexity, but cases like direct function calls of typecasting functions (and others) were missed, and bogus SQL syntax was being shown in pg_stat_statements normalized query text field. To fix normalization for those cases, we need the parser to transmit information about were each list of constant values starts and ends, so add that to a couple of nodes. Also add a few more test cases to make sure we're doing the right thing. The patch initially submitted by Sami added a new private struct in gram.y to carry the start/end information for A_Expr, but I (Álvaro) decided that a better fix was to remove the parser indirection via the in_expr production, and instead create separate components in the a_expr rule. I'm surprised that this works and doesn't require more changes, but I assume (without checking) that the grammar used to be more complex and got simplified at some point. Bump catversion. Author: Sami Imseih <samimseih@gmail.com> Author: Dmitry Dolgov <9erthalion6@gmail.com> Reviewed-by: Michael Paquier <michael@paquier.xyz> Discussion: https://postgr.es/m/CAA5RZ0tRXoPG2y6bMgBCWNDt0Tn=unRerbzYM=oW0syi1=C1OA@mail.gmail.com
1 parent f7b1141 commit 0f65f3e

File tree

14 files changed

+833
-292
lines changed

14 files changed

+833
-292
lines changed

contrib/pg_stat_statements/expected/select.out

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,36 @@ SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C";
267267
SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C" | 0
268268
(4 rows)
269269

270+
-- with the last element being an explicit function call with an argument, ensure
271+
-- the normalization of the squashing interval is correct.
272+
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
273+
t
274+
---
275+
t
276+
(1 row)
277+
278+
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
279+
t
280+
---
281+
t
282+
(1 row)
283+
284+
SELECT WHERE 1 IN (1, int4(1), int4(2));
285+
--
286+
(1 row)
287+
288+
SELECT WHERE 1 = ANY (ARRAY[1, int4(1), int4(2)]);
289+
--
290+
(1 row)
291+
292+
SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C";
293+
query | calls
294+
------------------------------------------------------------------------+-------
295+
SELECT WHERE $1 IN ($2 /*, ... */) | 2
296+
SELECT pg_stat_statements_reset() IS NOT NULL AS t | 1
297+
SELECT query, calls FROM pg_stat_statements ORDER BY query COLLATE "C" | 0
298+
(3 rows)
299+
270300
--
271301
-- queries with locking clauses
272302
--

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy