From 537898bd81bd8bd3650846e0abde4298ff1373da Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Thu, 7 Feb 2019 09:21:57 +0900 Subject: [PATCH] Add more tests for CREATE TABLE AS with WITH NO DATA The relation creation is done at executor startup, however the main regression test suite is lacking scenarios where no data is inserted which is something that can happen when using EXECUTE or EXPLAIN with CREATE TABLE AS and WITH NO DATA. Some patches are worked on to reshape the way CTAS relations are created, so this makes sure that we do not miss some query patterns already supported. Reported-by: Andreas Karlsson Author: Michael Paquier Reviewed-by: Andreas Karlsson Discussion: https://postgr.es/m/20190206091817.GB14980@paquier.xyz --- src/test/regress/expected/prepare.out | 7 +++++++ src/test/regress/expected/select_into.out | 7 ++++--- src/test/regress/sql/prepare.sql | 3 +++ src/test/regress/sql/select_into.sql | 7 ++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/test/regress/expected/prepare.out b/src/test/regress/expected/prepare.out index d07c0cc9c9..717732300d 100644 --- a/src/test/regress/expected/prepare.out +++ b/src/test/regress/expected/prepare.out @@ -145,6 +145,13 @@ SELECT * FROM q5_prep_results; 9961 | 2058 | 1 | 1 | 1 | 1 | 61 | 961 | 1961 | 4961 | 9961 | 122 | 123 | DTAAAA | EBDAAA | OOOOxx (16 rows) +CREATE TEMPORARY TABLE q5_prep_nodata AS EXECUTE q5(200, 'DTAAAA') + WITH NO DATA; +SELECT * FROM q5_prep_nodata; + unique1 | unique2 | two | four | ten | twenty | hundred | thousand | twothousand | fivethous | tenthous | odd | even | stringu1 | stringu2 | string4 +---------+---------+-----+------+-----+--------+---------+----------+-------------+-----------+----------+-----+------+----------+----------+--------- +(0 rows) + -- unknown or unspecified parameter types: should succeed PREPARE q6 AS SELECT * FROM tenk1 WHERE unique1 = $1 AND stringu1 = $2; diff --git a/src/test/regress/expected/select_into.out b/src/test/regress/expected/select_into.out index 942f975e95..f373fae679 100644 --- a/src/test/regress/expected/select_into.out +++ b/src/test/regress/expected/select_into.out @@ -112,14 +112,15 @@ SELECT * FROM created_table; 4567890123456789 | -4567890123456789 (5 rows) --- Try EXPLAIN ANALYZE SELECT INTO, but hide the output since it won't --- be stable. +-- Try EXPLAIN ANALYZE SELECT INTO and EXPLAIN ANALYZE CREATE TABLE AS +-- WITH NO DATA, but hide the outputs since they won't be stable. DO $$ BEGIN EXECUTE 'EXPLAIN ANALYZE SELECT * INTO TABLE easi FROM int8_tbl'; + EXECUTE 'EXPLAIN ANALYZE CREATE TABLE easi2 AS SELECT * FROM int8_tbl WITH NO DATA'; END$$; DROP TABLE created_table; -DROP TABLE easi; +DROP TABLE easi, easi2; -- -- Disallowed uses of SELECT ... INTO. All should fail -- diff --git a/src/test/regress/sql/prepare.sql b/src/test/regress/sql/prepare.sql index 7fe8c8d7f5..985d0f05c9 100644 --- a/src/test/regress/sql/prepare.sql +++ b/src/test/regress/sql/prepare.sql @@ -61,6 +61,9 @@ PREPARE q5(int, text) AS ORDER BY unique1; CREATE TEMPORARY TABLE q5_prep_results AS EXECUTE q5(200, 'DTAAAA'); SELECT * FROM q5_prep_results; +CREATE TEMPORARY TABLE q5_prep_nodata AS EXECUTE q5(200, 'DTAAAA') + WITH NO DATA; +SELECT * FROM q5_prep_nodata; -- unknown or unspecified parameter types: should succeed PREPARE q6 AS diff --git a/src/test/regress/sql/select_into.sql b/src/test/regress/sql/select_into.sql index 62eddeed9d..a708fef0ea 100644 --- a/src/test/regress/sql/select_into.sql +++ b/src/test/regress/sql/select_into.sql @@ -85,15 +85,16 @@ SELECT make_table(); SELECT * FROM created_table; --- Try EXPLAIN ANALYZE SELECT INTO, but hide the output since it won't --- be stable. +-- Try EXPLAIN ANALYZE SELECT INTO and EXPLAIN ANALYZE CREATE TABLE AS +-- WITH NO DATA, but hide the outputs since they won't be stable. DO $$ BEGIN EXECUTE 'EXPLAIN ANALYZE SELECT * INTO TABLE easi FROM int8_tbl'; + EXECUTE 'EXPLAIN ANALYZE CREATE TABLE easi2 AS SELECT * FROM int8_tbl WITH NO DATA'; END$$; DROP TABLE created_table; -DROP TABLE easi; +DROP TABLE easi, easi2; -- -- Disallowed uses of SELECT ... INTO. All should fail