Skip to content

Commit 320cab3

Browse files
committed
Move prepared statement queries to shared tests
This patch moves the prepared statement test to the shared tests so they can be run on compressed hypertables as well.
1 parent ded9c8e commit 320cab3

13 files changed

+2989
-1825
lines changed

test/expected/append-10.out

Lines changed: 1 addition & 622 deletions
Large diffs are not rendered by default.

test/expected/append-11.out

Lines changed: 1 addition & 622 deletions
Large diffs are not rendered by default.

test/expected/append-9.6.out

Lines changed: 1 addition & 497 deletions
Large diffs are not rendered by default.

test/runner_shared.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,19 @@ TEST_PGUSER=${TEST_PGUSER:-postgres}
1111
TEST_INPUT_DIR=${TEST_INPUT_DIR:-${EXE_DIR}}
1212
TEST_OUTPUT_DIR=${TEST_OUTPUT_DIR:-${EXE_DIR}}
1313

14+
# PGAPPNAME will be 'pg_regress/test' so we cut off the prefix
15+
# to get the name of the test (PG 10 and 11 only)
16+
TEST_BASE_NAME=${PGAPPNAME##pg_regress/}
17+
18+
# if this is a versioned test our name will have version as suffix
19+
# so we cut off suffix to get base name
20+
if [[ ${TEST_BASE_NAME} == *-1[0-9] ]]; then
21+
TEST_BASE_NAME=${TEST_BASE_NAME::-3}
22+
fi
23+
1424
#docker doesn't set user
1525
USER=${USER:-`whoami`}
1626

17-
TEST_SPINWAIT_ITERS=${TEST_SPINWAIT_ITERS:-10}
18-
1927
TEST_ROLE_SUPERUSER=${TEST_ROLE_SUPERUSER:-super_user}
2028
TEST_ROLE_DEFAULT_PERM_USER=${TEST_ROLE_DEFAULT_PERM_USER:-default_perm_user}
2129
TEST_ROLE_DEFAULT_PERM_USER_2=${TEST_ROLE_DEFAULT_PERM_USER_2:-default_perm_user_2}
@@ -37,9 +45,9 @@ ${PSQL} -U ${TEST_PGUSER} \
3745
-v ON_ERROR_STOP=1 \
3846
-v VERBOSITY=terse \
3947
-v ECHO=all \
48+
-v TEST_BASE_NAME=${TEST_BASE_NAME} \
4049
-v TEST_INPUT_DIR=${TEST_INPUT_DIR} \
4150
-v TEST_OUTPUT_DIR=${TEST_OUTPUT_DIR} \
42-
-v TEST_SPINWAIT_ITERS=${TEST_SPINWAIT_ITERS} \
4351
-v ROLE_SUPERUSER=${TEST_ROLE_SUPERUSER} \
4452
-v ROLE_DEFAULT_PERM_USER=${TEST_ROLE_DEFAULT_PERM_USER} \
4553
-v ROLE_DEFAULT_PERM_USER_2=${TEST_ROLE_DEFAULT_PERM_USER_2} \

test/sql/include/append_query.sql

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -283,63 +283,6 @@ ORDER BY time DESC, device_id;
283283
-- should include 2 chunks
284284
:PREFIX SELECT device_id, time FROM (SELECT device_id, time FROM metrics_timestamptz WHERE time < '2000-01-10'::text::timestamptz ORDER BY device_id, time) m;
285285

286-
-- test prepared statements
287-
-- executor startup exclusion with no chunks excluded
288-
PREPARE prep AS SELECT time FROM metrics_timestamptz WHERE time < now() AND device_id = 1 ORDER BY time;
289-
:PREFIX EXECUTE prep;
290-
:PREFIX EXECUTE prep;
291-
:PREFIX EXECUTE prep;
292-
:PREFIX EXECUTE prep;
293-
:PREFIX EXECUTE prep;
294-
DEALLOCATE prep;
295-
296-
-- executor startup exclusion with no chunks excluded and space partitioning
297-
PREPARE prep AS SELECT time FROM metrics_space WHERE time < now() AND device_id = 1 ORDER BY time;
298-
:PREFIX EXECUTE prep;
299-
:PREFIX EXECUTE prep;
300-
:PREFIX EXECUTE prep;
301-
:PREFIX EXECUTE prep;
302-
:PREFIX EXECUTE prep;
303-
DEALLOCATE prep;
304-
305-
-- executor startup exclusion with chunks excluded
306-
PREPARE prep AS SELECT time FROM metrics_timestamptz WHERE time < '2000-01-10'::text::timestamptz AND device_id = 1 ORDER BY time;
307-
:PREFIX EXECUTE prep;
308-
:PREFIX EXECUTE prep;
309-
:PREFIX EXECUTE prep;
310-
:PREFIX EXECUTE prep;
311-
:PREFIX EXECUTE prep;
312-
DEALLOCATE prep;
313-
314-
-- runtime exclusion with LATERAL and 2 hypertables
315-
PREPARE prep AS SELECT m1.time, m2.time FROM metrics_timestamptz m1 LEFT JOIN LATERAL(SELECT time FROM metrics_timestamptz m2 WHERE m1.time = m2.time LIMIT 1) m2 ON true ORDER BY m1.time;
316-
:PREFIX EXECUTE prep;
317-
:PREFIX EXECUTE prep;
318-
:PREFIX EXECUTE prep;
319-
:PREFIX EXECUTE prep;
320-
:PREFIX EXECUTE prep;
321-
DEALLOCATE prep;
322-
323-
-- executor startup exclusion with subquery
324-
PREPARE prep AS SELECT time FROM (SELECT time FROM metrics_timestamptz WHERE time < '2000-01-10'::text::timestamptz ORDER BY time) m;
325-
:PREFIX EXECUTE prep;
326-
:PREFIX EXECUTE prep;
327-
:PREFIX EXECUTE prep;
328-
:PREFIX EXECUTE prep;
329-
:PREFIX EXECUTE prep;
330-
DEALLOCATE prep;
331-
332-
-- test constraint exclusion for subqueries with ConstraintAwareAppend
333-
SET timescaledb.enable_chunk_append TO false;
334-
PREPARE prep AS SELECT device_id, time FROM (SELECT device_id, time FROM metrics_timestamptz WHERE time < '2000-01-10'::text::timestamptz ORDER BY device_id, time) m;
335-
:PREFIX EXECUTE prep;
336-
:PREFIX EXECUTE prep;
337-
:PREFIX EXECUTE prep;
338-
:PREFIX EXECUTE prep;
339-
:PREFIX EXECUTE prep;
340-
DEALLOCATE prep;
341-
RESET timescaledb.enable_chunk_append;
342-
343286
-- test LIMIT pushdown
344287
-- no aggregates/window functions/SRF should pushdown limit
345288
:PREFIX SELECT FROM metrics_timestamptz ORDER BY time LIMIT 1;

tsl/test/shared/expected/constraint_exclusion_prepared.out

Lines changed: 2850 additions & 0 deletions
Large diffs are not rendered by default.

tsl/test/shared/expected/ordered_append-10.out

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
-- This file and its contents are licensed under the Timescale License.
22
-- Please see the included NOTICE for copyright information and
33
-- LICENSE-TIMESCALE for a copy of the license.
4-
\set TEST_BASE_NAME ordered_append
54
SELECT
65
format('include/%s_query.sql', :'TEST_BASE_NAME') as "TEST_QUERY_NAME",
76
format('%s/shared/results/%s_results_uncompressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED",
8-
format('%s/shared/results/%s_results_uncompressed_idx.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED_IDX",
9-
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED",
10-
format('%s/shared/results/%s_results_compressed_idx.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED_IDX"
7+
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED"
118
\gset
129
SELECT format('\! diff -u --label "Uncompressed results" --label "Compressed results" %s %s', :'TEST_RESULTS_UNCOMPRESSED', :'TEST_RESULTS_COMPRESSED') as "DIFF_CMD"
1310
\gset

tsl/test/shared/expected/ordered_append-11.out

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
-- This file and its contents are licensed under the Timescale License.
22
-- Please see the included NOTICE for copyright information and
33
-- LICENSE-TIMESCALE for a copy of the license.
4-
\set TEST_BASE_NAME ordered_append
54
SELECT
65
format('include/%s_query.sql', :'TEST_BASE_NAME') as "TEST_QUERY_NAME",
76
format('%s/shared/results/%s_results_uncompressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED",
8-
format('%s/shared/results/%s_results_uncompressed_idx.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED_IDX",
9-
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED",
10-
format('%s/shared/results/%s_results_compressed_idx.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED_IDX"
7+
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED"
118
\gset
129
SELECT format('\! diff -u --label "Uncompressed results" --label "Compressed results" %s %s', :'TEST_RESULTS_UNCOMPRESSED', :'TEST_RESULTS_COMPRESSED') as "DIFF_CMD"
1310
\gset

tsl/test/shared/sql/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
set(TEST_FILES_SHARED
2+
constraint_exclusion_prepared.sql
23
)
34

45
set(TEST_TEMPLATES_SHARED
6+
ordered_append.sql.in
57
)
68

7-
if (${PG_VERSION_MAJOR} EQUAL "10" OR ${PG_VERSION_MAJOR} GREATER "10")
8-
list(APPEND TEST_TEMPLATES_SHARED
9-
ordered_append.sql.in
10-
)
11-
endif()
12-
139
# Regression tests that vary with PostgreSQL version. Generated test
1410
# files are put in the original source directory since all tests must
1511
# be in the same directory. These files are updated when the template
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
-- This file and its contents are licensed under the Timescale License.
2+
-- Please see the included NOTICE for copyright information and
3+
-- LICENSE-TIMESCALE for a copy of the license.
4+
5+
SELECT
6+
format('include/%s.sql', :'TEST_BASE_NAME') as "TEST_QUERY_NAME",
7+
format('%s/shared/results/%s_results_unoptimized.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNOPTIMIZED",
8+
format('%s/shared/results/%s_results_uncompressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED",
9+
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED"
10+
\gset
11+
SELECT format('\! diff -u --label "Uncompressed results" --label "Compressed results" %s %s', :'TEST_RESULTS_UNCOMPRESSED', :'TEST_RESULTS_COMPRESSED') as "DIFF_CMD"
12+
\gset
13+
14+
-- get EXPLAIN output for all variations
15+
-- look at postgres version to decide whether we run with analyze or without
16+
SELECT
17+
CASE WHEN current_setting('server_version_num')::int >= 100000
18+
THEN 'EXPLAIN (analyze, costs off, timing off, summary off)'
19+
ELSE 'EXPLAIN (costs off)'
20+
END AS "PREFIX",
21+
CASE WHEN current_setting('server_version_num')::int >= 100000
22+
THEN 'EXPLAIN (analyze, costs off, timing off, summary off, verbose)'
23+
ELSE 'EXPLAIN (costs off, verbose)'
24+
END AS "PREFIX_VERBOSE"
25+
\gset
26+
27+
set work_mem to '64MB';
28+
29+
set max_parallel_workers_per_gather to 0;
30+
\set TEST_TABLE 'metrics'
31+
\ir :TEST_QUERY_NAME
32+
\set TEST_TABLE 'metrics_space'
33+
\ir :TEST_QUERY_NAME
34+
\set TEST_TABLE 'metrics_compressed'
35+
\ir :TEST_QUERY_NAME
36+
\set TEST_TABLE 'metrics_space_compressed'
37+
\ir :TEST_QUERY_NAME
38+
39+
40+
-- get results for all the queries
41+
-- run queries on uncompressed hypertable and store result
42+
\set PREFIX ''
43+
\set PREFIX_VERBOSE ''
44+
\set ECHO none
45+
SET client_min_messages TO error;
46+
47+
-- run queries on compressed hypertable and store result
48+
\set TEST_TABLE 'metrics'
49+
\o :TEST_RESULTS_UNCOMPRESSED
50+
\ir :TEST_QUERY_NAME
51+
\set TEST_TABLE 'metrics_compressed'
52+
\o :TEST_RESULTS_COMPRESSED
53+
\ir :TEST_QUERY_NAME
54+
\o
55+
56+
-- diff compressed and uncompressed results
57+
:DIFF_CMD
58+
59+
-- do the same for space partitioned hypertable
60+
\set TEST_TABLE 'metrics_space'
61+
\o :TEST_RESULTS_UNCOMPRESSED
62+
\ir :TEST_QUERY_NAME
63+
\set TEST_TABLE 'metrics_space_compressed'
64+
\o :TEST_RESULTS_COMPRESSED
65+
\ir :TEST_QUERY_NAME
66+
\o
67+
68+
-- diff compressed and uncompressed results
69+
:DIFF_CMD
70+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
-- test prepared statements
3+
-- executor startup exclusion with no chunks excluded
4+
PREPARE prep AS SELECT time FROM :TEST_TABLE WHERE time < now() AND device_id = 1 ORDER BY time;
5+
:PREFIX EXECUTE prep;
6+
:PREFIX EXECUTE prep;
7+
:PREFIX EXECUTE prep;
8+
:PREFIX EXECUTE prep;
9+
:PREFIX EXECUTE prep;
10+
DEALLOCATE prep;
11+
12+
-- executor startup exclusion with chunks excluded
13+
PREPARE prep AS SELECT time FROM :TEST_TABLE WHERE time < '2000-01-10'::text::timestamptz AND device_id = 1 ORDER BY time;
14+
:PREFIX EXECUTE prep;
15+
:PREFIX EXECUTE prep;
16+
:PREFIX EXECUTE prep;
17+
:PREFIX EXECUTE prep;
18+
:PREFIX EXECUTE prep;
19+
DEALLOCATE prep;
20+
21+
-- runtime exclusion with LATERAL and 2 hypertables
22+
PREPARE prep AS SELECT m1.time, m2.time FROM :TEST_TABLE m1 LEFT JOIN LATERAL(SELECT time FROM :TEST_TABLE m2 WHERE m1.time = m2.time LIMIT 1) m2 ON true WHERE device_id = 2 ORDER BY m1.time;
23+
:PREFIX EXECUTE prep;
24+
:PREFIX EXECUTE prep;
25+
:PREFIX EXECUTE prep;
26+
:PREFIX EXECUTE prep;
27+
:PREFIX EXECUTE prep;
28+
DEALLOCATE prep;
29+
30+
-- executor startup exclusion with subquery
31+
PREPARE prep AS SELECT time FROM (SELECT time FROM :TEST_TABLE WHERE time < '2000-01-10'::text::timestamptz ORDER BY time LIMIT 100) m;
32+
:PREFIX EXECUTE prep;
33+
:PREFIX EXECUTE prep;
34+
:PREFIX EXECUTE prep;
35+
:PREFIX EXECUTE prep;
36+
:PREFIX EXECUTE prep;
37+
DEALLOCATE prep;
38+
39+
-- test constraint exclusion for subqueries with ConstraintAwareAppend
40+
SET timescaledb.enable_chunk_append TO false;
41+
PREPARE prep AS SELECT device_id, time FROM (SELECT device_id, time FROM :TEST_TABLE WHERE time < '2000-01-10'::text::timestamptz ORDER BY device_id, time LIMIT 100) m;
42+
:PREFIX EXECUTE prep;
43+
:PREFIX EXECUTE prep;
44+
:PREFIX EXECUTE prep;
45+
:PREFIX EXECUTE prep;
46+
:PREFIX EXECUTE prep;
47+
DEALLOCATE prep;
48+
RESET timescaledb.enable_chunk_append;
49+

tsl/test/shared/sql/ordered_append-11.sql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
21
-- This file and its contents are licensed under the Timescale License.
32
-- Please see the included NOTICE for copyright information and
43
-- LICENSE-TIMESCALE for a copy of the license.
54

6-
\set TEST_BASE_NAME ordered_append
75
SELECT
86
format('include/%s_query.sql', :'TEST_BASE_NAME') as "TEST_QUERY_NAME",
97
format('%s/shared/results/%s_results_uncompressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED",
10-
format('%s/shared/results/%s_results_uncompressed_idx.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED_IDX",
11-
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED",
12-
format('%s/shared/results/%s_results_compressed_idx.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED_IDX"
8+
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED"
139
\gset
1410
SELECT format('\! diff -u --label "Uncompressed results" --label "Compressed results" %s %s', :'TEST_RESULTS_UNCOMPRESSED', :'TEST_RESULTS_COMPRESSED') as "DIFF_CMD"
1511
\gset

tsl/test/shared/sql/ordered_append.sql.in

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
21
-- This file and its contents are licensed under the Timescale License.
32
-- Please see the included NOTICE for copyright information and
43
-- LICENSE-TIMESCALE for a copy of the license.
54

6-
\set TEST_BASE_NAME ordered_append
75
SELECT
86
format('include/%s_query.sql', :'TEST_BASE_NAME') as "TEST_QUERY_NAME",
97
format('%s/shared/results/%s_results_uncompressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED",
10-
format('%s/shared/results/%s_results_uncompressed_idx.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_UNCOMPRESSED_IDX",
11-
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED",
12-
format('%s/shared/results/%s_results_compressed_idx.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED_IDX"
8+
format('%s/shared/results/%s_results_compressed.out', :'TEST_OUTPUT_DIR', :'TEST_BASE_NAME') as "TEST_RESULTS_COMPRESSED"
139
\gset
1410
SELECT format('\! diff -u --label "Uncompressed results" --label "Compressed results" %s %s', :'TEST_RESULTS_UNCOMPRESSED', :'TEST_RESULTS_COMPRESSED') as "DIFF_CMD"
1511
\gset

0 commit comments

Comments
 (0)