Improve error message for recursive CTEs (#7407)

Fixes #2870
pull/7471/head
Onur Tirtir 2024-01-30 18:12:48 +03:00 committed by GitHub
parent f6ea619e27
commit 5aedec4242
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 20 additions and 20 deletions

View File

@ -1097,8 +1097,8 @@ RecursivelyPlanCTEs(Query *query, RecursivePlanningContext *planningContext)
if (query->hasRecursive) if (query->hasRecursive)
{ {
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED, return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"recursive CTEs are not supported in distributed " "recursive CTEs are only supported when they "
"queries", "contain a filter on the distribution column",
NULL, NULL); NULL, NULL);
} }

View File

@ -370,7 +370,7 @@ WITH RECURSIVE hierarchy as (
h.company_id = ce.company_id)) h.company_id = ce.company_id))
SELECT * FROM hierarchy WHERE LEVEL <= 2; SELECT * FROM hierarchy WHERE LEVEL <= 2;
DEBUG: Router planner cannot handle multi-shard select queries DEBUG: Router planner cannot handle multi-shard select queries
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- logically wrong query, query involves different shards -- logically wrong query, query involves different shards
-- from the same table, but still router plannable due to -- from the same table, but still router plannable due to
-- shard being placed on the same worker. -- shard being placed on the same worker.
@ -386,7 +386,7 @@ WITH RECURSIVE hierarchy as (
ce.company_id = 2)) ce.company_id = 2))
SELECT * FROM hierarchy WHERE LEVEL <= 2; SELECT * FROM hierarchy WHERE LEVEL <= 2;
DEBUG: router planner does not support queries that reference non-colocated distributed tables DEBUG: router planner does not support queries that reference non-colocated distributed tables
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- grouping sets are supported on single shard -- grouping sets are supported on single shard
SELECT SELECT
id, substring(title, 2, 1) AS subtitle, count(*) id, substring(title, 2, 1) AS subtitle, count(*)

View File

@ -436,7 +436,7 @@ WITH RECURSIVE hierarchy as MATERIALIZED (
h.company_id = ce.company_id)) h.company_id = ce.company_id))
SELECT * FROM hierarchy WHERE LEVEL <= 2; SELECT * FROM hierarchy WHERE LEVEL <= 2;
DEBUG: Router planner cannot handle multi-shard select queries DEBUG: Router planner cannot handle multi-shard select queries
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- logically wrong query, query involves different shards -- logically wrong query, query involves different shards
-- from the same table -- from the same table
WITH RECURSIVE hierarchy as MATERIALIZED ( WITH RECURSIVE hierarchy as MATERIALIZED (
@ -451,7 +451,7 @@ WITH RECURSIVE hierarchy as MATERIALIZED (
ce.company_id = 2)) ce.company_id = 2))
SELECT * FROM hierarchy WHERE LEVEL <= 2; SELECT * FROM hierarchy WHERE LEVEL <= 2;
DEBUG: router planner does not support queries that reference non-colocated distributed tables DEBUG: router planner does not support queries that reference non-colocated distributed tables
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- Test router modifying CTEs -- Test router modifying CTEs
WITH new_article AS MATERIALIZED( WITH new_article AS MATERIALIZED(
INSERT INTO articles_hash VALUES (1, 1, 'arsenous', 9) RETURNING * INSERT INTO articles_hash VALUES (1, 1, 'arsenous', 9) RETURNING *

View File

@ -1142,7 +1142,7 @@ WITH RECURSIVE search_graph(f, t, label) AS (
WHERE g.f = sg.t and g.f = 1 WHERE g.f = sg.t and g.f = 1
) SEARCH DEPTH FIRST BY f, t SET seq ) SEARCH DEPTH FIRST BY f, t SET seq
SELECT * FROM search_graph ORDER BY seq; SELECT * FROM search_graph ORDER BY seq;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
WITH RECURSIVE search_graph(f, t, label) AS ( WITH RECURSIVE search_graph(f, t, label) AS (
SELECT * FROM graph0 g WHERE f = 1 SELECT * FROM graph0 g WHERE f = 1
UNION ALL UNION ALL
@ -1151,7 +1151,7 @@ WITH RECURSIVE search_graph(f, t, label) AS (
WHERE g.f = sg.t and g.f = 1 WHERE g.f = sg.t and g.f = 1
) SEARCH DEPTH FIRST BY f, t SET seq ) SEARCH DEPTH FIRST BY f, t SET seq
DELETE FROM graph0 WHERE t IN (SELECT t FROM search_graph ORDER BY seq); DELETE FROM graph0 WHERE t IN (SELECT t FROM search_graph ORDER BY seq);
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
CREATE TABLE graph1(f INT, t INT, label TEXT); CREATE TABLE graph1(f INT, t INT, label TEXT);
SELECT create_reference_table('graph1'); SELECT create_reference_table('graph1');
create_reference_table create_reference_table
@ -1170,7 +1170,7 @@ WITH RECURSIVE search_graph(f, t, label) AS (
WHERE g.f = sg.t and g.f = 1 WHERE g.f = sg.t and g.f = 1
) SEARCH DEPTH FIRST BY f, t SET seq ) SEARCH DEPTH FIRST BY f, t SET seq
SELECT * FROM search_graph ORDER BY seq; SELECT * FROM search_graph ORDER BY seq;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
WITH RECURSIVE search_graph(f, t, label) AS ( WITH RECURSIVE search_graph(f, t, label) AS (
SELECT * FROM graph1 g WHERE f = 1 SELECT * FROM graph1 g WHERE f = 1
UNION ALL UNION ALL
@ -1179,7 +1179,7 @@ WITH RECURSIVE search_graph(f, t, label) AS (
WHERE g.f = sg.t and g.f = 1 WHERE g.f = sg.t and g.f = 1
) SEARCH DEPTH FIRST BY f, t SET seq ) SEARCH DEPTH FIRST BY f, t SET seq
DELETE FROM graph1 WHERE t IN (SELECT t FROM search_graph ORDER BY seq); DELETE FROM graph1 WHERE t IN (SELECT t FROM search_graph ORDER BY seq);
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
SELECT * FROM ( SELECT * FROM (
WITH RECURSIVE search_graph(f, t, label) AS ( WITH RECURSIVE search_graph(f, t, label) AS (
SELECT * SELECT *
@ -1191,7 +1191,7 @@ SELECT * FROM (
) SEARCH DEPTH FIRST BY f, t SET seq ) SEARCH DEPTH FIRST BY f, t SET seq
SELECT * FROM search_graph ORDER BY seq SELECT * FROM search_graph ORDER BY seq
) as foo; ) as foo;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- --
-- https://github.com/citusdata/citus/issues/5258 -- https://github.com/citusdata/citus/issues/5258
-- --

View File

@ -1529,7 +1529,7 @@ DEBUG: Router planner cannot handle multi-shard select queries
DEBUG: Router planner cannot handle multi-shard select queries DEBUG: Router planner cannot handle multi-shard select queries
DEBUG: generating subplan XXX_1 for CTE level_1: WITH RECURSIVE level_2_recursive(x) AS (VALUES (1) UNION ALL SELECT (nullkey_c1_t1.a OPERATOR(pg_catalog.+) 1) FROM (query_single_shard_table.nullkey_c1_t1 JOIN level_2_recursive level_2_recursive_1 ON ((nullkey_c1_t1.a OPERATOR(pg_catalog.=) level_2_recursive_1.x))) WHERE (nullkey_c1_t1.a OPERATOR(pg_catalog.<) 100)) SELECT level_2_recursive.x, distributed_table.a, distributed_table.b FROM (level_2_recursive JOIN query_single_shard_table.distributed_table ON ((level_2_recursive.x OPERATOR(pg_catalog.=) distributed_table.a))) DEBUG: generating subplan XXX_1 for CTE level_1: WITH RECURSIVE level_2_recursive(x) AS (VALUES (1) UNION ALL SELECT (nullkey_c1_t1.a OPERATOR(pg_catalog.+) 1) FROM (query_single_shard_table.nullkey_c1_t1 JOIN level_2_recursive level_2_recursive_1 ON ((nullkey_c1_t1.a OPERATOR(pg_catalog.=) level_2_recursive_1.x))) WHERE (nullkey_c1_t1.a OPERATOR(pg_catalog.<) 100)) SELECT level_2_recursive.x, distributed_table.a, distributed_table.b FROM (level_2_recursive JOIN query_single_shard_table.distributed_table ON ((level_2_recursive.x OPERATOR(pg_catalog.=) distributed_table.a)))
DEBUG: Router planner cannot handle multi-shard select queries DEBUG: Router planner cannot handle multi-shard select queries
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- grouping set -- grouping set
SELECT SELECT
id, substring(title, 2, 1) AS subtitle, count(*) id, substring(title, 2, 1) AS subtitle, count(*)

View File

@ -527,7 +527,7 @@ FROM
) as bar ) as bar
WHERE foo.user_id = bar.user_id WHERE foo.user_id = bar.user_id
ORDER BY 1 DESC; ORDER BY 1 DESC;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
CREATE TABLE ref_table_1 (a int); CREATE TABLE ref_table_1 (a int);
SELECT create_reference_table('ref_table_1'); SELECT create_reference_table('ref_table_1');
create_reference_table create_reference_table

View File

@ -664,14 +664,14 @@ WITH RECURSIVE basic_recursive(x) AS (
SELECT user_id + 1 FROM users_table JOIN basic_recursive ON (user_id = x) WHERE user_id < 100 SELECT user_id + 1 FROM users_table JOIN basic_recursive ON (user_id = x) WHERE user_id < 100
) )
SELECT sum(x) FROM basic_recursive; SELECT sum(x) FROM basic_recursive;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
WITH RECURSIVE basic_recursive AS ( WITH RECURSIVE basic_recursive AS (
SELECT -1 as user_id, '2017-11-22 20:16:16.614779'::timestamp, -1, -1, -1, -1 SELECT -1 as user_id, '2017-11-22 20:16:16.614779'::timestamp, -1, -1, -1, -1
UNION ALL UNION ALL
SELECT basic_recursive.* FROM users_table JOIN basic_recursive USING (user_id) WHERE user_id>1 SELECT basic_recursive.* FROM users_table JOIN basic_recursive USING (user_id) WHERE user_id>1
) )
SELECT * FROM basic_recursive ORDER BY user_id LIMIT 1; SELECT * FROM basic_recursive ORDER BY user_id LIMIT 1;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- basic_recursive in FROM should error out -- basic_recursive in FROM should error out
SELECT SELECT
* *
@ -682,7 +682,7 @@ FROM
SELECT basic_recursive.* FROM users_table JOIN basic_recursive USING (user_id) WHERE user_id>1 SELECT basic_recursive.* FROM users_table JOIN basic_recursive USING (user_id) WHERE user_id>1
) )
SELECT * FROM basic_recursive ORDER BY user_id LIMIT 1) cte_rec; SELECT * FROM basic_recursive ORDER BY user_id LIMIT 1) cte_rec;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- basic_recursive in WHERE with UNION ALL -- basic_recursive in WHERE with UNION ALL
SELECT SELECT
* *
@ -696,7 +696,7 @@ WHERE
SELECT basic_recursive.* FROM users_table JOIN basic_recursive USING (user_id) WHERE user_id>1 SELECT basic_recursive.* FROM users_table JOIN basic_recursive USING (user_id) WHERE user_id>1
) )
SELECT * FROM basic_recursive ORDER BY user_id LIMIT 1); SELECT * FROM basic_recursive ORDER BY user_id LIMIT 1);
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- one recursive one regular CTE should error out -- one recursive one regular CTE should error out
WITH RECURSIVE basic_recursive(x) AS( WITH RECURSIVE basic_recursive(x) AS(
VALUES (1) VALUES (1)
@ -707,7 +707,7 @@ basic AS (
SELECT count(user_id) FROM users_table SELECT count(user_id) FROM users_table
) )
SELECT x FROM basic, basic_recursive; SELECT x FROM basic, basic_recursive;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- one recursive one regular which SELECTs from the recursive CTE under a simple SELECT -- one recursive one regular which SELECTs from the recursive CTE under a simple SELECT
WITH RECURSIVE basic_recursive(x) AS( WITH RECURSIVE basic_recursive(x) AS(
VALUES (1) VALUES (1)
@ -718,7 +718,7 @@ basic AS (
SELECT count(x) FROM basic_recursive SELECT count(x) FROM basic_recursive
) )
SELECT * FROM basic; SELECT * FROM basic;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- recursive CTE in a NESTED manner -- recursive CTE in a NESTED manner
WITH regular_cte AS ( WITH regular_cte AS (
WITH regular_2 AS ( WITH regular_2 AS (
@ -732,7 +732,7 @@ WITH regular_cte AS (
SELECT * FROM regular_2 SELECT * FROM regular_2
) )
SELECT * FROM regular_cte; SELECT * FROM regular_cte;
ERROR: recursive CTEs are not supported in distributed queries ERROR: recursive CTEs are only supported when they contain a filter on the distribution column
-- CTEs should work with VIEWs as well -- CTEs should work with VIEWs as well
CREATE VIEW basic_view AS CREATE VIEW basic_view AS
SELECT * FROM users_table; SELECT * FROM users_table;