Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit11c34b3

Browse files
committed
Show parameters of CALL as constants in pg_stat_statements
This commit changes the query jumbling of CallStmt so as its IN/OUTparameters are able to show up as constants with a parameter symbol inpg_stat_statements, like:CALL proc1($1, $2);CALL proc2($1, $2, $3);The transformed FuncExpr is used in the query ID computation instead ofthe FuncCall generated by the parser, so as it is sensitive to the OIDof the procedure and its list of input arguments. The output argumentsare handled in a separate list in CallStmt, which is also included inthe computation.Tests are added to pg_stat_statements to show how this affects CALL withIN/OUT parameters as well as overloaded functions.Like638d42a or31de7e6, this improves the monitoring ofworkloads with a lot of CALL statements, preventing unnecessary bloatwhen these use different input (or event output) values.Author: Sami ImseihDiscussion:https://postgr.es/m/B44FA29D-EBD0-4DD9-ABC2-16F1CB087074@amazon.com
1 parentd060e92 commit11c34b3

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

‎contrib/pg_stat_statements/expected/utility.out

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,27 @@ DECLARE
300300
BEGIN
301301
SELECT (i + j)::int INTO r;
302302
END; $$ LANGUAGE plpgsql;
303+
-- Overloaded functions.
304+
CREATE OR REPLACE PROCEDURE overload(i int) AS $$
305+
DECLARE
306+
r int;
307+
BEGIN
308+
SELECT (i + i)::int INTO r;
309+
END; $$ LANGUAGE plpgsql;
310+
CREATE OR REPLACE PROCEDURE overload(i text) AS $$
311+
DECLARE
312+
r text;
313+
BEGIN
314+
SELECT i::text INTO r;
315+
END; $$ LANGUAGE plpgsql;
316+
-- Mix of IN/OUT parameters.
317+
CREATE OR REPLACE PROCEDURE in_out(i int, i2 OUT int, i3 INOUT int) AS $$
318+
DECLARE
319+
r int;
320+
BEGIN
321+
i2 := i;
322+
i3 := i3 + i;
323+
END; $$ LANGUAGE plpgsql;
303324
SELECT pg_stat_statements_reset();
304325
pg_stat_statements_reset
305326
--------------------------
@@ -310,15 +331,30 @@ CALL sum_one(3);
310331
CALL sum_one(199);
311332
CALL sum_two(1,1);
312333
CALL sum_two(1,2);
334+
CALL overload(1);
335+
CALL overload('A');
336+
CALL in_out(1, NULL, 1);
337+
i2 | i3
338+
----+----
339+
1 | 2
340+
(1 row)
341+
342+
CALL in_out(2, 1, 2);
343+
i2 | i3
344+
----+----
345+
2 | 4
346+
(1 row)
347+
313348
SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
314349
calls | rows | query
315350
-------+------+-----------------------------------
316-
1 | 0 | CALL sum_one(199)
317-
1 | 0 | CALL sum_one(3)
318-
1 | 0 | CALL sum_two(1,1)
319-
1 | 0 | CALL sum_two(1,2)
351+
2 | 0 | CALL in_out($1, $2, $3)
352+
1 | 0 | CALL overload($1)
353+
1 | 0 | CALL overload($1)
354+
2 | 0 | CALL sum_one($1)
355+
2 | 0 | CALL sum_two($1,$2)
320356
1 | 1 | SELECT pg_stat_statements_reset()
321-
(5 rows)
357+
(6 rows)
322358

323359
-- COPY
324360
CREATE TABLE copy_stats (a int, b int);

‎contrib/pg_stat_statements/sql/utility.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,36 @@ DECLARE
164164
BEGIN
165165
SELECT (i+ j)::int INTO r;
166166
END; $$ LANGUAGE plpgsql;
167+
-- Overloaded functions.
168+
CREATEOR REPLACE PROCEDURE overload(iint)AS $$
169+
DECLARE
170+
rint;
171+
BEGIN
172+
SELECT (i+ i)::int INTO r;
173+
END; $$ LANGUAGE plpgsql;
174+
CREATEOR REPLACE PROCEDURE overload(itext)AS $$
175+
DECLARE
176+
rtext;
177+
BEGIN
178+
SELECT i::text INTO r;
179+
END; $$ LANGUAGE plpgsql;
180+
-- Mix of IN/OUT parameters.
181+
CREATEOR REPLACE PROCEDURE in_out(iint, i2 OUTint, i3 INOUTint)AS $$
182+
DECLARE
183+
rint;
184+
BEGIN
185+
i2 := i;
186+
i3 := i3+ i;
187+
END; $$ LANGUAGE plpgsql;
167188
SELECT pg_stat_statements_reset();
168189
CALL sum_one(3);
169190
CALL sum_one(199);
170191
CALL sum_two(1,1);
171192
CALL sum_two(1,2);
193+
CALL overload(1);
194+
CALL overload('A');
195+
CALL in_out(1,NULL,1);
196+
CALL in_out(2,1,2);
172197
SELECT calls, rows, queryFROM pg_stat_statementsORDER BY query COLLATE"C";
173198

174199
-- COPY

‎src/include/nodes/parsenodes.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3376,11 +3376,12 @@ typedef struct InlineCodeBlock
33763376
typedefstructCallStmt
33773377
{
33783378
NodeTagtype;
3379-
FuncCall*funccall;/* from the parser */
3379+
/* from the parser */
3380+
FuncCall*funccallpg_node_attr(query_jumble_ignore);
33803381
/* transformed call, with only input args */
3381-
FuncExpr*funcexprpg_node_attr(query_jumble_ignore);
3382+
FuncExpr*funcexpr;
33823383
/* transformed output-argument expressions */
3383-
List*outargspg_node_attr(query_jumble_ignore);
3384+
List*outargs;
33843385
}CallStmt;
33853386

33863387
typedefstructCallContext

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp