Skip to content

Commit

Permalink
Improve error message for recursive CTEs (#7407)
Browse files Browse the repository at this point in the history
Fixes #2870
  • Loading branch information
onurctirtir committed Jan 30, 2024
1 parent f6ea619 commit 5aedec4
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/backend/distributed/planner/recursive_planning.c
Original file line number Diff line number Diff line change
Expand Up @@ -1097,8 +1097,8 @@ RecursivelyPlanCTEs(Query *query, RecursivePlanningContext *planningContext)
if (query->hasRecursive)
{
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
"recursive CTEs are not supported in distributed "
"queries",
"recursive CTEs are only supported when they "
"contain a filter on the distribution column",
NULL, NULL);
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/regress/expected/multi_mx_router_planner.out
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ WITH RECURSIVE hierarchy as (
h.company_id = ce.company_id))
SELECT * FROM hierarchy WHERE LEVEL <= 2;
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
-- from the same table, but still router plannable due to
-- shard being placed on the same worker.
Expand All @@ -386,7 +386,7 @@ WITH RECURSIVE hierarchy as (
ce.company_id = 2))
SELECT * FROM hierarchy WHERE LEVEL <= 2;
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
SELECT
id, substring(title, 2, 1) AS subtitle, count(*)
Expand Down
4 changes: 2 additions & 2 deletions src/test/regress/expected/multi_router_planner.out
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ WITH RECURSIVE hierarchy as MATERIALIZED (
h.company_id = ce.company_id))
SELECT * FROM hierarchy WHERE LEVEL <= 2;
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
-- from the same table
WITH RECURSIVE hierarchy as MATERIALIZED (
Expand All @@ -451,7 +451,7 @@ WITH RECURSIVE hierarchy as MATERIALIZED (
ce.company_id = 2))
SELECT * FROM hierarchy WHERE LEVEL <= 2;
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
WITH new_article AS MATERIALIZED(
INSERT INTO articles_hash VALUES (1, 1, 'arsenous', 9) RETURNING *
Expand Down
10 changes: 5 additions & 5 deletions src/test/regress/expected/pg14.out
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ WITH RECURSIVE search_graph(f, t, label) AS (
WHERE g.f = sg.t and g.f = 1
) SEARCH DEPTH FIRST BY f, t SET 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 (
SELECT * FROM graph0 g WHERE f = 1
UNION ALL
Expand All @@ -1151,7 +1151,7 @@ WITH RECURSIVE search_graph(f, t, label) AS (
WHERE g.f = sg.t and g.f = 1
) SEARCH DEPTH FIRST BY f, t SET 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);
SELECT create_reference_table('graph1');
create_reference_table
Expand All @@ -1170,7 +1170,7 @@ WITH RECURSIVE search_graph(f, t, label) AS (
WHERE g.f = sg.t and g.f = 1
) SEARCH DEPTH FIRST BY f, t SET 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 (
SELECT * FROM graph1 g WHERE f = 1
UNION ALL
Expand All @@ -1179,7 +1179,7 @@ WITH RECURSIVE search_graph(f, t, label) AS (
WHERE g.f = sg.t and g.f = 1
) SEARCH DEPTH FIRST BY f, t SET 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 (
WITH RECURSIVE search_graph(f, t, label) AS (
SELECT *
Expand All @@ -1191,7 +1191,7 @@ SELECT * FROM (
) SEARCH DEPTH FIRST BY f, t SET seq
SELECT * FROM search_graph ORDER BY seq
) 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
--
Expand Down
2 changes: 1 addition & 1 deletion src/test/regress/expected/query_single_shard_table.out
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ 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: 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
SELECT
id, substring(title, 2, 1) AS subtitle, count(*)
Expand Down
2 changes: 1 addition & 1 deletion src/test/regress/expected/subquery_and_cte.out
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ FROM
) as bar
WHERE foo.user_id = bar.user_id
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);
SELECT create_reference_table('ref_table_1');
create_reference_table
Expand Down
14 changes: 7 additions & 7 deletions src/test/regress/expected/with_basics.out
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 (
SELECT -1 as user_id, '2017-11-22 20:16:16.614779'::timestamp, -1, -1, -1, -1
UNION ALL
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;
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
SELECT
*
Expand All @@ -682,7 +682,7 @@ FROM
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;
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
SELECT
*
Expand All @@ -696,7 +696,7 @@ WHERE
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);
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
WITH RECURSIVE basic_recursive(x) AS(
VALUES (1)
Expand All @@ -707,7 +707,7 @@ basic AS (
SELECT count(user_id) FROM users_table
)
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
WITH RECURSIVE basic_recursive(x) AS(
VALUES (1)
Expand All @@ -718,7 +718,7 @@ basic AS (
SELECT count(x) FROM basic_recursive
)
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
WITH regular_cte AS (
WITH regular_2 AS (
Expand All @@ -732,7 +732,7 @@ WITH regular_cte AS (
SELECT * FROM regular_2
)
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
CREATE VIEW basic_view AS
SELECT * FROM users_table;
Expand Down

0 comments on commit 5aedec4

Please sign in to comment.