From 594684bb330f9c150b4045a0b15236eadf4d53a2 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Thu, 19 Jan 2023 11:48:14 +0300 Subject: [PATCH] Do clean-up before columnar_create to make it runnable multiple times So that flaky test detector can run columnar_create.sql multiple times. --- src/test/regress/expected/columnar_create.out | 53 ++++++++++++++----- src/test/regress/sql/columnar_create.sql | 52 +++++++++++++----- 2 files changed, 81 insertions(+), 24 deletions(-) diff --git a/src/test/regress/expected/columnar_create.out b/src/test/regress/expected/columnar_create.out index 3bd4359ef..d679b7790 100644 --- a/src/test/regress/expected/columnar_create.out +++ b/src/test/regress/expected/columnar_create.out @@ -1,24 +1,50 @@ -- -- Test the CREATE statements related to columnar. -- --- Create uncompressed table -CREATE TABLE contestant (handle TEXT, birthdate DATE, rating INT, - percentile FLOAT, country CHAR(3), achievements TEXT[]) - USING columnar; -ALTER TABLE contestant SET (columnar.compression = none); -CREATE INDEX contestant_idx on contestant(handle); --- Create zstd compressed table -CREATE TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, - percentile FLOAT, country CHAR(3), achievements TEXT[]) - USING columnar; --- Test that querying an empty table works -ANALYZE contestant; +-- We cannot create below tables within columnar_create because columnar_create +-- is dropped at the end of this test but unfortunately some other tests depend +-- those tables too. +-- +-- However, this file has to be runnable multiple times for flaky test detection; +-- so we create them below --outside columnar_create-- idempotantly. +DO +$$ +BEGIN +IF NOT EXISTS ( + SELECT 1 FROM pg_class + WHERE relname = 'contestant' AND + relnamespace = ( + SELECT oid FROM pg_namespace WHERE nspname = 'public' + ) + ) +THEN + -- Create uncompressed table + CREATE TABLE contestant (handle TEXT, birthdate DATE, rating INT, + percentile FLOAT, country CHAR(3), achievements TEXT[]) + USING columnar; + ALTER TABLE contestant SET (columnar.compression = none); + + CREATE INDEX contestant_idx on contestant(handle); + + -- Create zstd compressed table + CREATE TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, + percentile FLOAT, country CHAR(3), achievements TEXT[]) + USING columnar; + + -- Test that querying an empty table works + ANALYZE contestant; +END IF; +END +$$ +LANGUAGE plpgsql; SELECT count(*) FROM contestant; count --------------------------------------------------------------------- 0 (1 row) +CREATE SCHEMA columnar_create; +SET search_path TO columnar_create; -- Should fail: unlogged tables not supported CREATE UNLOGGED TABLE columnar_unlogged(i int) USING columnar; ERROR: unlogged columnar tables are not supported @@ -156,6 +182,7 @@ SELECT columnar.get_storage_id(oid) AS columnar_temp_storage_id FROM pg_class WHERE relname='columnar_temp' \gset SELECT pg_backend_pid() AS val INTO old_backend_pid; \c - - - :master_port +SET search_path TO columnar_create; -- wait until old backend to expire to make sure that temp table cleanup is complete SELECT columnar_test_helpers.pg_waitpid(val) FROM old_backend_pid; pg_waitpid @@ -265,3 +292,5 @@ SELECT columnar_test_helpers.columnar_metadata_has_storage_id(:columnar_temp_sto -- make sure citus_columnar can be loaded LOAD 'citus_columnar'; +SET client_min_messages TO WARNING; +DROP SCHEMA columnar_create CASCADE; diff --git a/src/test/regress/sql/columnar_create.sql b/src/test/regress/sql/columnar_create.sql index 1790e69ad..017cc0d8f 100644 --- a/src/test/regress/sql/columnar_create.sql +++ b/src/test/regress/sql/columnar_create.sql @@ -2,24 +2,48 @@ -- Test the CREATE statements related to columnar. -- +-- We cannot create below tables within columnar_create because columnar_create +-- is dropped at the end of this test but unfortunately some other tests depend +-- those tables too. +-- +-- However, this file has to be runnable multiple times for flaky test detection; +-- so we create them below --outside columnar_create-- idempotantly. +DO +$$ +BEGIN +IF NOT EXISTS ( + SELECT 1 FROM pg_class + WHERE relname = 'contestant' AND + relnamespace = ( + SELECT oid FROM pg_namespace WHERE nspname = 'public' + ) + ) +THEN + -- Create uncompressed table + CREATE TABLE contestant (handle TEXT, birthdate DATE, rating INT, + percentile FLOAT, country CHAR(3), achievements TEXT[]) + USING columnar; + ALTER TABLE contestant SET (columnar.compression = none); --- Create uncompressed table -CREATE TABLE contestant (handle TEXT, birthdate DATE, rating INT, - percentile FLOAT, country CHAR(3), achievements TEXT[]) - USING columnar; -ALTER TABLE contestant SET (columnar.compression = none); + CREATE INDEX contestant_idx on contestant(handle); -CREATE INDEX contestant_idx on contestant(handle); + -- Create zstd compressed table + CREATE TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, + percentile FLOAT, country CHAR(3), achievements TEXT[]) + USING columnar; --- Create zstd compressed table -CREATE TABLE contestant_compressed (handle TEXT, birthdate DATE, rating INT, - percentile FLOAT, country CHAR(3), achievements TEXT[]) - USING columnar; + -- Test that querying an empty table works + ANALYZE contestant; +END IF; +END +$$ +LANGUAGE plpgsql; --- Test that querying an empty table works -ANALYZE contestant; SELECT count(*) FROM contestant; +CREATE SCHEMA columnar_create; +SET search_path TO columnar_create; + -- Should fail: unlogged tables not supported CREATE UNLOGGED TABLE columnar_unlogged(i int) USING columnar; @@ -118,6 +142,7 @@ FROM pg_class WHERE relname='columnar_temp' \gset SELECT pg_backend_pid() AS val INTO old_backend_pid; \c - - - :master_port +SET search_path TO columnar_create; -- wait until old backend to expire to make sure that temp table cleanup is complete SELECT columnar_test_helpers.pg_waitpid(val) FROM old_backend_pid; @@ -184,3 +209,6 @@ SELECT columnar_test_helpers.columnar_metadata_has_storage_id(:columnar_temp_sto -- make sure citus_columnar can be loaded LOAD 'citus_columnar'; + +SET client_min_messages TO WARNING; +DROP SCHEMA columnar_create CASCADE;