From a7457d662c4be778da6250423b7ec10cd84cf32f Mon Sep 17 00:00:00 2001 From: Henson Choi Date: Tue, 1 Dec 2026 22:03:51 +0900 Subject: [PATCH v2 3/3] XXX: Volume tests for the tuplestore position index, not for commit. Run window frames over a spilled WindowAgg buffer and compare them with the same frames in memory, reposition a holdable SCROLL cursor in a spilled store at commit, and spill a buffer large enough that the position index grows and then thins out. These need far more rows than the regular suite should spend, so they are only for reviewers. --- src/test/regress/expected/window.out | 85 ++++++++++++++++++++++++++++ src/test/regress/sql/window.sql | 58 +++++++++++++++++++ 2 files changed, 143 insertions(+) diff --git a/src/test/regress/expected/window.out b/src/test/regress/expected/window.out index 19f56c80fef..5dff8574f77 100644 --- a/src/test/regress/expected/window.out +++ b/src/test/regress/expected/window.out @@ -6343,3 +6343,88 @@ SELECT last_value FROM null_treatment_seq; --cleanup DROP TABLE planets CASCADE; NOTICE: drop cascades to view planets_view +-- XXX DELETE BEFORE COMMIT: start of tuplestore position index volume test +-- Window frames over a spilled buffer give the same results as in memory +CREATE TEMP TABLE tsidx_rows AS + SELECT i, (i * 7919) % 10007 AS w, md5(i::text) || repeat('z', (i % 7) * 20) AS v + FROM generate_series(1, 8000) i; +CREATE TEMP VIEW tsidx_frames AS +SELECT i, + max(w) OVER (ORDER BY i ROWS BETWEEN 500 PRECEDING AND CURRENT ROW) AS m1, + max(w) OVER (ORDER BY i ROWS BETWEEN 300 PRECEDING AND 300 FOLLOWING) AS m2, + max(w) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND 300 FOLLOWING) AS m3, + sum(i) OVER (ORDER BY i ROWS BETWEEN 2000 PRECEDING AND CURRENT ROW) AS s1, + first_value(v) OVER (ORDER BY i ROWS BETWEEN 1000 PRECEDING AND CURRENT ROW) AS f1, + nth_value(v, 1000) OVER (ORDER BY i ROWS BETWEEN UNBOUNDED PRECEDING + AND UNBOUNDED FOLLOWING) AS n1, + last_value(v) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND 1000 FOLLOWING) AS l1, + lag(v, 700) OVER (ORDER BY i) AS g1, + lead(v, 700) OVER (ORDER BY i) AS g2, + count(*) OVER (ORDER BY i / 10 RANGE BETWEEN 50 PRECEDING AND 50 FOLLOWING) AS c1, + max(w) OVER (ORDER BY i / 5 GROUPS BETWEEN 100 PRECEDING AND 100 FOLLOWING + EXCLUDE CURRENT ROW) AS x1 +FROM tsidx_rows; +SET work_mem = '64kB'; +CREATE TEMP TABLE tsidx_spilled AS SELECT * FROM tsidx_frames; +RESET work_mem; +SELECT count(*) FROM + ((TABLE tsidx_spilled EXCEPT ALL TABLE tsidx_frames) + UNION ALL + (TABLE tsidx_frames EXCEPT ALL TABLE tsidx_spilled)) d; + count +------- + 0 +(1 row) + +DROP VIEW tsidx_frames; +DROP TABLE tsidx_spilled, tsidx_rows; +-- Holdable cursor repositioned in a spilled store at commit +SET work_mem = '64kB'; +BEGIN; +DECLARE tsidx_cur SCROLL CURSOR WITH HOLD FOR + SELECT i FROM generate_series(1, 20000) i; +MOVE ABSOLUTE 15000 IN tsidx_cur; +COMMIT; +FETCH RELATIVE 0 FROM tsidx_cur; + i +------- + 15000 +(1 row) + +FETCH ABSOLUTE 7 FROM tsidx_cur; + i +--- + 7 +(1 row) + +FETCH BACKWARD 1 FROM tsidx_cur; + i +--- + 6 +(1 row) + +FETCH ABSOLUTE 19999 FROM tsidx_cur; + i +------- + 19999 +(1 row) + +CLOSE tsidx_cur; +RESET work_mem; +-- Spilled buffer whose position index grows and then compacts +SET work_mem = '64kB'; +CREATE TEMP TABLE tsidx_wide AS + SELECT i, repeat('x', 1900) AS p FROM generate_series(1, 20000) i; +SELECT count(*) FROM + (SELECT i, p, sum(i) OVER (ORDER BY i ROWS BETWEEN 100 PRECEDING AND CURRENT ROW) s + FROM tsidx_wide) w +WHERE s <> (i - greatest(i - 100, 1) + 1) * (i + greatest(i - 100, 1)) / 2 + OR length(p) <> 1900; + count +------- + 0 +(1 row) + +DROP TABLE tsidx_wide; +RESET work_mem; +-- XXX DELETE BEFORE COMMIT: end of tuplestore position index volume test diff --git a/src/test/regress/sql/window.sql b/src/test/regress/sql/window.sql index f62f73e36b1..5c52ae51c7c 100644 --- a/src/test/regress/sql/window.sql +++ b/src/test/regress/sql/window.sql @@ -2349,3 +2349,61 @@ SELECT last_value FROM null_treatment_seq; --cleanup DROP TABLE planets CASCADE; + +-- XXX DELETE BEFORE COMMIT: start of tuplestore position index volume test +-- Window frames over a spilled buffer give the same results as in memory +CREATE TEMP TABLE tsidx_rows AS + SELECT i, (i * 7919) % 10007 AS w, md5(i::text) || repeat('z', (i % 7) * 20) AS v + FROM generate_series(1, 8000) i; +CREATE TEMP VIEW tsidx_frames AS +SELECT i, + max(w) OVER (ORDER BY i ROWS BETWEEN 500 PRECEDING AND CURRENT ROW) AS m1, + max(w) OVER (ORDER BY i ROWS BETWEEN 300 PRECEDING AND 300 FOLLOWING) AS m2, + max(w) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND 300 FOLLOWING) AS m3, + sum(i) OVER (ORDER BY i ROWS BETWEEN 2000 PRECEDING AND CURRENT ROW) AS s1, + first_value(v) OVER (ORDER BY i ROWS BETWEEN 1000 PRECEDING AND CURRENT ROW) AS f1, + nth_value(v, 1000) OVER (ORDER BY i ROWS BETWEEN UNBOUNDED PRECEDING + AND UNBOUNDED FOLLOWING) AS n1, + last_value(v) OVER (ORDER BY i ROWS BETWEEN CURRENT ROW AND 1000 FOLLOWING) AS l1, + lag(v, 700) OVER (ORDER BY i) AS g1, + lead(v, 700) OVER (ORDER BY i) AS g2, + count(*) OVER (ORDER BY i / 10 RANGE BETWEEN 50 PRECEDING AND 50 FOLLOWING) AS c1, + max(w) OVER (ORDER BY i / 5 GROUPS BETWEEN 100 PRECEDING AND 100 FOLLOWING + EXCLUDE CURRENT ROW) AS x1 +FROM tsidx_rows; +SET work_mem = '64kB'; +CREATE TEMP TABLE tsidx_spilled AS SELECT * FROM tsidx_frames; +RESET work_mem; +SELECT count(*) FROM + ((TABLE tsidx_spilled EXCEPT ALL TABLE tsidx_frames) + UNION ALL + (TABLE tsidx_frames EXCEPT ALL TABLE tsidx_spilled)) d; +DROP VIEW tsidx_frames; +DROP TABLE tsidx_spilled, tsidx_rows; + +-- Holdable cursor repositioned in a spilled store at commit +SET work_mem = '64kB'; +BEGIN; +DECLARE tsidx_cur SCROLL CURSOR WITH HOLD FOR + SELECT i FROM generate_series(1, 20000) i; +MOVE ABSOLUTE 15000 IN tsidx_cur; +COMMIT; +FETCH RELATIVE 0 FROM tsidx_cur; +FETCH ABSOLUTE 7 FROM tsidx_cur; +FETCH BACKWARD 1 FROM tsidx_cur; +FETCH ABSOLUTE 19999 FROM tsidx_cur; +CLOSE tsidx_cur; +RESET work_mem; + +-- Spilled buffer whose position index grows and then compacts +SET work_mem = '64kB'; +CREATE TEMP TABLE tsidx_wide AS + SELECT i, repeat('x', 1900) AS p FROM generate_series(1, 20000) i; +SELECT count(*) FROM + (SELECT i, p, sum(i) OVER (ORDER BY i ROWS BETWEEN 100 PRECEDING AND CURRENT ROW) s + FROM tsidx_wide) w +WHERE s <> (i - greatest(i - 100, 1) + 1) * (i + greatest(i - 100, 1)) / 2 + OR length(p) <> 1900; +DROP TABLE tsidx_wide; +RESET work_mem; +-- XXX DELETE BEFORE COMMIT: end of tuplestore position index volume test -- 2.54.0 (Apple Git-157)