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:
24e60b44a1

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.
pull/5431/head
Jelte Fennema 2021-11-03 12:27:28 +01:00 committed by GitHub
parent d691148e7e
commit 0cb51f8c37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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');