From 0cb51f8c37f57039c69512963e90e4be3f7ddee6 Mon Sep 17 00:00:00 2001 From: Jelte Fennema Date: Wed, 3 Nov 2021 12:27:28 +0100 Subject: [PATCH] Test a query that failed on 9.5.8 when coordinator is in metadata (#5412) This test starts passing because of PR #4508, to be precise commit: 24e60b44a1d0ea95859ad7379b7a6557862f173e When I undo that commit this newly added test starts failing. This adds this test to make sure we don't regress on this again. --- .../regress/expected/distributed_planning.out | 45 +++++++++++++++++++ .../distributed_planning_create_load.out | 7 +++ src/test/regress/sql/distributed_planning.sql | 41 +++++++++++++++++ .../sql/distributed_planning_create_load.sql | 3 ++ 4 files changed, 96 insertions(+) diff --git a/src/test/regress/expected/distributed_planning.out b/src/test/regress/expected/distributed_planning.out index 4fecef905..746a55954 100644 --- a/src/test/regress/expected/distributed_planning.out +++ b/src/test/regress/expected/distributed_planning.out @@ -464,6 +464,51 @@ WHERE x IN (SELECT num FROM cte_1); 3 (1 row) +BEGIN; +INSERT INTO ref VALUES (1, 1), (3, 3), (4, 4); +INSERT INTO ref2 VALUES (1, 1), (2, 2), (3, 3), (5, 5); +-- multiple CTEs working together +-- this qeury was reported as a bug by a user +WITH cte_ref AS ( + SELECT a as abc from ref where a IN (1, 2) +), +cte_join1 AS ( + SELECT + 2 as result + FROM cte_ref + JOIN ref2 AS reff ON reff.b = cte_ref.abc +), +cte_join2 AS ( + SELECT + 1 as result + FROM cte_ref + LEFT JOIN test + ON test.x = cte_ref.abc + WHERE test.x IN (1, 2) + AND x > 0 +), +cte_with_subq AS ( + SELECT + (SELECT result FROM cte_join1 where result::int > 0) as result + FROM cte_join2 + UNION ALL + SELECT + (SELECT result FROM cte_join1 where result::int < 10) as result + FROM cte_ref +) +SELECT * from cte_with_subq +UNION ALL SELECT 3 FROM cte_join1 +UNION ALL SELECT 4 FROM cte_ref +ORDER BY 1; + result +--------------------------------------------------------------------- + 2 + 2 + 3 + 4 +(4 rows) + +ROLLBACK; -- query fails on the shards should be handled -- nicely \set VERBOSITY terse diff --git a/src/test/regress/expected/distributed_planning_create_load.out b/src/test/regress/expected/distributed_planning_create_load.out index 19f925bf2..22da7b2f3 100644 --- a/src/test/regress/expected/distributed_planning_create_load.out +++ b/src/test/regress/expected/distributed_planning_create_load.out @@ -46,6 +46,13 @@ SELECT create_reference_table('ref'); (1 row) +CREATE TABLE ref2(a int, b int); +SELECT create_reference_table('ref2'); + create_reference_table +--------------------------------------------------------------------- + +(1 row) + CREATE TABLE local(c int, d int); select citus_add_local_table_to_metadata('local'); citus_add_local_table_to_metadata diff --git a/src/test/regress/sql/distributed_planning.sql b/src/test/regress/sql/distributed_planning.sql index 9e466647e..803b78b98 100644 --- a/src/test/regress/sql/distributed_planning.sql +++ b/src/test/regress/sql/distributed_planning.sql @@ -245,6 +245,47 @@ FROM test WHERE x IN (SELECT num FROM cte_1); + +BEGIN; +INSERT INTO ref VALUES (1, 1), (3, 3), (4, 4); +INSERT INTO ref2 VALUES (1, 1), (2, 2), (3, 3), (5, 5); +-- multiple CTEs working together +-- this qeury was reported as a bug by a user +WITH cte_ref AS ( + SELECT a as abc from ref where a IN (1, 2) +), +cte_join1 AS ( + SELECT + 2 as result + FROM cte_ref + JOIN ref2 AS reff ON reff.b = cte_ref.abc +), +cte_join2 AS ( + SELECT + 1 as result + FROM cte_ref + LEFT JOIN test + ON test.x = cte_ref.abc + WHERE test.x IN (1, 2) + AND x > 0 +), +cte_with_subq AS ( + SELECT + (SELECT result FROM cte_join1 where result::int > 0) as result + FROM cte_join2 + UNION ALL + SELECT + (SELECT result FROM cte_join1 where result::int < 10) as result + FROM cte_ref +) + +SELECT * from cte_with_subq +UNION ALL SELECT 3 FROM cte_join1 +UNION ALL SELECT 4 FROM cte_ref +ORDER BY 1; + +ROLLBACK; + -- query fails on the shards should be handled -- nicely \set VERBOSITY terse diff --git a/src/test/regress/sql/distributed_planning_create_load.sql b/src/test/regress/sql/distributed_planning_create_load.sql index 1ef7abd77..e32012689 100644 --- a/src/test/regress/sql/distributed_planning_create_load.sql +++ b/src/test/regress/sql/distributed_planning_create_load.sql @@ -30,6 +30,9 @@ SELECT create_distributed_table('test_2','x'); CREATE TABLE ref(a int, b int); SELECT create_reference_table('ref'); +CREATE TABLE ref2(a int, b int); +SELECT create_reference_table('ref2'); + CREATE TABLE local(c int, d int); select citus_add_local_table_to_metadata('local');