Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ PG_BIN_DIR=$(pg_config --bindir)

cd "$SCRIPT_DIR/../../"

OPTS='-c shared_preload_libraries=pg_stat_monitor'
# The two-phase transaction cases of the "utility" test need
# max_prepared_transactions to be nonzero.
OPTS='-c shared_preload_libraries=pg_stat_monitor -c max_prepared_transactions=5'

if [ "$1" = sanitize ]; then
OPTS+=' -c max_stack_depth=8MB'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Our name and version are now in `pg_get_loaded_modules()` for PostgreSQL 18+
- Support for `EXEC_BACKEND` builds ([PG-2547](https://perconadev.atlassian.net/browse/PG-2547))
- Add PostgreSQL 19 support ([PG-2424](https://perconadev.atlassian.net/browse/PG-2424)): add generic and custom plan counts, support property graphs, use ComputeConstantLengths API for constants squashing
- Backport test cases from pg_stat_statements

### Changed

Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ REGRESS = basic \
level_tracking \
decode_error_level \
parallel \
select \
dml \
cursors \
utility \
planning \
wal \
privileges \
plancache \
histogram

PG_CONFIG ?= pg_config
Expand Down
2 changes: 2 additions & 0 deletions pg_stat_monitor.conf
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
shared_preload_libraries = 'pg_stat_monitor'
# Needed by the two-phase transaction cases of the "utility" test.
max_prepared_transactions = 5
216 changes: 216 additions & 0 deletions regression/expected/cursors.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
--
-- Cursors
--
CREATE EXTENSION pg_stat_monitor;
-- These tests require utility tracking and query normalization to be enabled.
SET pg_stat_monitor.pgsm_track_utility = on;
SET pg_stat_monitor.pgsm_normalized_query = on;
SELECT pg_stat_monitor_reset() IS NOT NULL AS t;
t
---
t
(1 row)

-- DECLARE
-- SELECT is normalized.
DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 1;
CLOSE cursor_stats_1;
DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 2;
CLOSE cursor_stats_1;
SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
calls | rows | query
-------+------+------------------------------------------------------
2 | 0 | CLOSE cursor_stats_1
2 | 0 | DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 1
1 | 1 | SELECT pg_stat_monitor_reset() IS NOT NULL AS t
(3 rows)

SELECT pg_stat_monitor_reset() IS NOT NULL AS t;
t
---
t
(1 row)

-- FETCH
BEGIN;
DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 2;
DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT 3;
FETCH 1 IN cursor_stats_1;
?column?
----------
2
(1 row)

FETCH 1 IN cursor_stats_2;
?column?
----------
3
(1 row)

CLOSE cursor_stats_1;
CLOSE cursor_stats_2;
COMMIT;
SELECT calls, rows, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
calls | rows | query
-------+------+------------------------------------------------------
1 | 0 | BEGIN
1 | 0 | CLOSE cursor_stats_1
1 | 0 | CLOSE cursor_stats_2
1 | 0 | COMMIT
1 | 0 | DECLARE cursor_stats_1 CURSOR WITH HOLD FOR SELECT 2
1 | 0 | DECLARE cursor_stats_2 CURSOR WITH HOLD FOR SELECT 3
1 | 1 | FETCH 1 IN cursor_stats_1
1 | 1 | FETCH 1 IN cursor_stats_2
1 | 1 | SELECT pg_stat_monitor_reset() IS NOT NULL AS t
(9 rows)

SELECT pg_stat_monitor_reset() IS NOT NULL AS t;
t
---
t
(1 row)

-- Normalization of FETCH statements
BEGIN;
DECLARE pgsm_cursor CURSOR FOR SELECT FROM generate_series(1, 10);
-- implicit directions
FETCH pgsm_cursor;
--
(1 row)

FETCH 1 pgsm_cursor;
--
(1 row)

FETCH 2 pgsm_cursor;
--
(2 rows)

FETCH -1 pgsm_cursor;
--
(1 row)

-- explicit NEXT
FETCH NEXT pgsm_cursor;
--
(1 row)

-- explicit PRIOR
FETCH PRIOR pgsm_cursor;
--
(1 row)

-- explicit FIRST
FETCH FIRST pgsm_cursor;
--
(1 row)

-- explicit LAST
FETCH LAST pgsm_cursor;
--
(1 row)

-- explicit ABSOLUTE
FETCH ABSOLUTE 1 pgsm_cursor;
--
(1 row)

FETCH ABSOLUTE 2 pgsm_cursor;
--
(1 row)

FETCH ABSOLUTE -1 pgsm_cursor;
--
(1 row)

-- explicit RELATIVE
FETCH RELATIVE 1 pgsm_cursor;
--
(0 rows)

FETCH RELATIVE 2 pgsm_cursor;
--
(0 rows)

FETCH RELATIVE -1 pgsm_cursor;
--
(1 row)

-- explicit FORWARD
FETCH ALL pgsm_cursor;
--
(0 rows)

-- explicit FORWARD ALL
FETCH FORWARD ALL pgsm_cursor;
--
(0 rows)

-- explicit FETCH FORWARD
FETCH FORWARD pgsm_cursor;
--
(0 rows)

FETCH FORWARD 1 pgsm_cursor;
--
(0 rows)

FETCH FORWARD 2 pgsm_cursor;
--
(0 rows)

FETCH FORWARD -1 pgsm_cursor;
--
(1 row)

-- explicit FETCH BACKWARD
FETCH BACKWARD pgsm_cursor;
--
(1 row)

FETCH BACKWARD 1 pgsm_cursor;
--
(1 row)

FETCH BACKWARD 2 pgsm_cursor;
--
(2 rows)

FETCH BACKWARD -1 pgsm_cursor;
--
(1 row)

-- explicit BACKWARD ALL
FETCH BACKWARD ALL pgsm_cursor;
--
(6 rows)

COMMIT;
SELECT calls, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
calls | query
-------+-------------------------------------------------------------------
1 | BEGIN
1 | COMMIT
1 | DECLARE pgsm_cursor CURSOR FOR SELECT FROM generate_series(1, 10)
3 | FETCH ABSOLUTE 1 pgsm_cursor
1 | FETCH ALL pgsm_cursor
1 | FETCH BACKWARD ALL pgsm_cursor
4 | FETCH BACKWARD pgsm_cursor
1 | FETCH FIRST pgsm_cursor
1 | FETCH FORWARD ALL pgsm_cursor
4 | FETCH FORWARD pgsm_cursor
1 | FETCH LAST pgsm_cursor
1 | FETCH NEXT pgsm_cursor
1 | FETCH PRIOR pgsm_cursor
3 | FETCH RELATIVE 1 pgsm_cursor
4 | FETCH pgsm_cursor
1 | SELECT pg_stat_monitor_reset() IS NOT NULL AS t
(16 rows)

SELECT pg_stat_monitor_reset() IS NOT NULL AS t;
t
---
t
(1 row)

DROP EXTENSION pg_stat_monitor;
Loading
Loading