Skip to content

Commit 35c4683

Browse files
author
Commitfest Bot
committed
[CF 5733] v6 - Improve explicit cursor handling in pg_stat_statements
This branch was automatically generated by a robot using patches from an email thread registered at: https://commitfest.postgresql.org/patch/5733 The branch will be overwritten each time a new patch version is posted to the thread, and also periodically to check for bitrot caused by changes on the master branch. Patch(es): https://www.postgresql.org/message-id/CAA5RZ0v8iRihm8zC8Rs3U1HzXOH8RWnY0_zf+AQNoo_WbWo2Nw@mail.gmail.com Author(s): Sami Imseih
2 parents 40a96cd + 4212465 commit 35c4683

File tree

7 files changed

+294
-15
lines changed

7 files changed

+294
-15
lines changed

contrib/pg_stat_statements/expected/cursors.out

Lines changed: 171 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
5757
1 | 0 | COMMIT
5858
1 | 0 | DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT $1
5959
1 | 0 | DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT $1
60-
1 | 1 | FETCH 1 IN cursor_stats_1
61-
1 | 1 | FETCH 1 IN cursor_stats_2
60+
1 | 1 | FETCH $1 IN cursor_stats_1
61+
1 | 1 | FETCH $1 IN cursor_stats_2
6262
1 | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t
6363
(9 rows)
6464

@@ -68,3 +68,172 @@ SELECT pg_stat_statements_reset() IS NOT NULL AS t;
6868
t
6969
(1 row)
7070

71+
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
72+
t
73+
---
74+
t
75+
(1 row)
76+
77+
-- Normalization of FETCH statements
78+
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
79+
t
80+
---
81+
t
82+
(1 row)
83+
84+
BEGIN;
85+
DECLARE pgss_cursor CURSOR FOR SELECT FROM generate_series(1, 50);
86+
-- implicit directions
87+
FETCH pgss_cursor;
88+
--
89+
(1 row)
90+
91+
FETCH 1 pgss_cursor;
92+
--
93+
(1 row)
94+
95+
FETCH 2 pgss_cursor;
96+
--
97+
(2 rows)
98+
99+
FETCH 3 pgss_cursor;
100+
--
101+
(3 rows)
102+
103+
FETCH -1 pgss_cursor;
104+
--
105+
(1 row)
106+
107+
-- explicit NEXT
108+
FETCH NEXT pgss_cursor;
109+
--
110+
(1 row)
111+
112+
-- explicit PRIOR
113+
FETCH PRIOR pgss_cursor;
114+
--
115+
(1 row)
116+
117+
-- explicit FIRST
118+
FETCH FIRST pgss_cursor;
119+
--
120+
(1 row)
121+
122+
-- explicit LAST
123+
FETCH LAST pgss_cursor;
124+
--
125+
(1 row)
126+
127+
-- explicit ABSOLUTE
128+
FETCH ABSOLUTE 1 pgss_cursor;
129+
--
130+
(1 row)
131+
132+
FETCH ABSOLUTE 2 pgss_cursor;
133+
--
134+
(1 row)
135+
136+
FETCH ABSOLUTE 3 pgss_cursor;
137+
--
138+
(1 row)
139+
140+
FETCH ABSOLUTE -1 pgss_cursor;
141+
--
142+
(1 row)
143+
144+
-- explicit RELATIVE
145+
FETCH RELATIVE 1 pgss_cursor;
146+
--
147+
(0 rows)
148+
149+
FETCH RELATIVE 2 pgss_cursor;
150+
--
151+
(0 rows)
152+
153+
FETCH RELATIVE 3 pgss_cursor;
154+
--
155+
(0 rows)
156+
157+
FETCH RELATIVE -1 pgss_cursor;
158+
--
159+
(1 row)
160+
161+
-- explicit FORWARD
162+
FETCH ALL pgss_cursor;
163+
--
164+
(0 rows)
165+
166+
-- explicit FORWARD ALL
167+
FETCH FORWARD ALL pgss_cursor;
168+
--
169+
(0 rows)
170+
171+
-- explicit BACKWARD ALL
172+
FETCH BACKWARD ALL pgss_cursor;
173+
--
174+
(50 rows)
175+
176+
-- explicit FETCH FORWARD
177+
FETCH FORWARD pgss_cursor;
178+
--
179+
(1 row)
180+
181+
FETCH FORWARD 1 pgss_cursor;
182+
--
183+
(1 row)
184+
185+
FETCH FORWARD 2 pgss_cursor;
186+
--
187+
(2 rows)
188+
189+
FETCH FORWARD 3 pgss_cursor;
190+
--
191+
(3 rows)
192+
193+
FETCH FORWARD -1 pgss_cursor;
194+
--
195+
(1 row)
196+
197+
-- explicit FETCH BACKWARD
198+
FETCH BACKWARD pgss_cursor;
199+
--
200+
(1 row)
201+
202+
FETCH BACKWARD 1 pgss_cursor;
203+
--
204+
(1 row)
205+
206+
FETCH BACKWARD 2 pgss_cursor;
207+
--
208+
(2 rows)
209+
210+
FETCH BACKWARD 3 pgss_cursor;
211+
--
212+
(1 row)
213+
214+
FETCH BACKWARD -1 pgss_cursor;
215+
--
216+
(1 row)
217+
218+
COMMIT;
219+
SELECT calls, query FROM pg_stat_statements ORDER BY query COLLATE "C";
220+
calls | query
221+
-------+--------------------------------------------------------------------
222+
1 | BEGIN
223+
1 | COMMIT
224+
1 | DECLARE pgss_cursor CURSOR FOR SELECT FROM generate_series($1, $2)
225+
4 | FETCH ABSOLUTE $1 pgss_cursor
226+
1 | FETCH ALL pgss_cursor
227+
1 | FETCH BACKWARD ALL pgss_cursor
228+
5 | FETCH BACKWARD pgss_cursor
229+
1 | FETCH FIRST pgss_cursor
230+
1 | FETCH FORWARD ALL pgss_cursor
231+
5 | FETCH FORWARD pgss_cursor
232+
1 | FETCH LAST pgss_cursor
233+
1 | FETCH NEXT pgss_cursor
234+
1 | FETCH PRIOR pgss_cursor
235+
4 | FETCH RELATIVE $1 pgss_cursor
236+
5 | FETCH pgss_cursor
237+
1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t
238+
(16 rows)
239+

contrib/pg_stat_statements/expected/level_tracking.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ SELECT toplevel, calls, query FROM pg_stat_statements
11471147
t | 1 | COMMIT
11481148
t | 1 | DECLARE FOOCUR CURSOR FOR SELECT * from stats_track_tab
11491149
f | 1 | DECLARE FOOCUR CURSOR FOR SELECT * from stats_track_tab;
1150-
t | 1 | FETCH FORWARD 1 FROM foocur
1150+
t | 1 | FETCH FORWARD $1 FROM foocur
11511151
t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t
11521152
(7 rows)
11531153

@@ -1176,7 +1176,7 @@ SELECT toplevel, calls, query FROM pg_stat_statements
11761176
t | 1 | CLOSE foocur
11771177
t | 1 | COMMIT
11781178
t | 1 | DECLARE FOOCUR CURSOR FOR SELECT * FROM stats_track_tab
1179-
t | 1 | FETCH FORWARD 1 FROM foocur
1179+
t | 1 | FETCH FORWARD $1 FROM foocur
11801180
t | 1 | SELECT pg_stat_statements_reset() IS NOT NULL AS t
11811181
(6 rows)
11821182

contrib/pg_stat_statements/expected/utility.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
702702
1 | 13 | CREATE MATERIALIZED VIEW pgss_matv AS SELECT * FROM pgss_ctas
703703
1 | 10 | CREATE TABLE pgss_ctas AS SELECT a, $1 b FROM generate_series($2, $3) a
704704
1 | 0 | DECLARE pgss_cursor CURSOR FOR SELECT * FROM pgss_matv
705-
1 | 5 | FETCH FORWARD 5 pgss_cursor
705+
1 | 5 | FETCH FORWARD $1 pgss_cursor
706706
1 | 7 | FETCH FORWARD ALL pgss_cursor
707707
1 | 1 | FETCH NEXT pgss_cursor
708708
1 | 13 | REFRESH MATERIALIZED VIEW pgss_matv

contrib/pg_stat_statements/sql/cursors.sql

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,54 @@ COMMIT;
2828

2929
SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
3030
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
31+
32+
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
33+
34+
-- Normalization of FETCH statements
35+
SELECT pg_stat_statements_reset() IS NOT NULL AS t;
36+
BEGIN;
37+
DECLARE pgss_cursor CURSOR FOR SELECT FROM generate_series(1, 50);
38+
-- implicit directions
39+
FETCH pgss_cursor;
40+
FETCH 1 pgss_cursor;
41+
FETCH 2 pgss_cursor;
42+
FETCH 3 pgss_cursor;
43+
FETCH -1 pgss_cursor;
44+
-- explicit NEXT
45+
FETCH NEXT pgss_cursor;
46+
-- explicit PRIOR
47+
FETCH PRIOR pgss_cursor;
48+
-- explicit FIRST
49+
FETCH FIRST pgss_cursor;
50+
-- explicit LAST
51+
FETCH LAST pgss_cursor;
52+
-- explicit ABSOLUTE
53+
FETCH ABSOLUTE 1 pgss_cursor;
54+
FETCH ABSOLUTE 2 pgss_cursor;
55+
FETCH ABSOLUTE 3 pgss_cursor;
56+
FETCH ABSOLUTE -1 pgss_cursor;
57+
-- explicit RELATIVE
58+
FETCH RELATIVE 1 pgss_cursor;
59+
FETCH RELATIVE 2 pgss_cursor;
60+
FETCH RELATIVE 3 pgss_cursor;
61+
FETCH RELATIVE -1 pgss_cursor;
62+
-- explicit FORWARD
63+
FETCH ALL pgss_cursor;
64+
-- explicit FORWARD ALL
65+
FETCH FORWARD ALL pgss_cursor;
66+
-- explicit BACKWARD ALL
67+
FETCH BACKWARD ALL pgss_cursor;
68+
-- explicit FETCH FORWARD
69+
FETCH FORWARD pgss_cursor;
70+
FETCH FORWARD 1 pgss_cursor;
71+
FETCH FORWARD 2 pgss_cursor;
72+
FETCH FORWARD 3 pgss_cursor;
73+
FETCH FORWARD -1 pgss_cursor;
74+
-- explicit FETCH BACKWARD
75+
FETCH BACKWARD pgss_cursor;
76+
FETCH BACKWARD 1 pgss_cursor;
77+
FETCH BACKWARD 2 pgss_cursor;
78+
FETCH BACKWARD 3 pgss_cursor;
79+
FETCH BACKWARD -1 pgss_cursor;
80+
COMMIT;
81+
SELECT calls, query FROM pg_stat_statements ORDER BY query COLLATE "C";

0 commit comments

Comments
 (0)