From fa73abe6d4632e11e86b999602b7e27eb01d4c23 Mon Sep 17 00:00:00 2001 From: Marco Slot Date: Mon, 4 Dec 2017 18:32:19 +0100 Subject: [PATCH] Regression test output changes after CTE support --- .../regress/expected/multi_insert_select.out | 16 +++++--- .../expected/multi_mx_router_planner.out | 36 ++++++++++++----- .../regress/expected/multi_router_planner.out | 40 +++++++++++++------ .../regress/expected/multi_simple_queries.out | 14 +++++-- src/test/regress/expected/multi_view.out | 4 +- src/test/regress/sql/multi_insert_select.sql | 8 ++-- .../regress/sql/multi_mx_router_planner.sql | 6 +-- src/test/regress/sql/multi_router_planner.sql | 6 +-- src/test/regress/sql/multi_simple_queries.sql | 4 +- 9 files changed, 89 insertions(+), 45 deletions(-) diff --git a/src/test/regress/expected/multi_insert_select.out b/src/test/regress/expected/multi_insert_select.out index b64360297..ab5c97c65 100644 --- a/src/test/regress/expected/multi_insert_select.out +++ b/src/test/regress/expected/multi_insert_select.out @@ -679,9 +679,10 @@ SELECT user_id, value_1_agg FROM agg_events ORDER BY 1,2; 9 | 90 (9 rows) --- We do not support some CTEs +-- We support CTEs +BEGIN; WITH fist_table_agg AS - (SELECT sum(value_1) as v1_agg, user_id FROM raw_events_first GROUP BY user_id) + (SELECT max(value_1)+1 as v1_agg, user_id FROM raw_events_first GROUP BY user_id) INSERT INTO agg_events (value_1_agg, user_id) SELECT @@ -690,9 +691,11 @@ INSERT INTO agg_events fist_table_agg; DEBUG: distributed INSERT ... SELECT can only select from distributed tables DEBUG: Collecting INSERT ... SELECT results on coordinator -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. --- We don't support CTEs that consist of const values as well +DEBUG: generating subplan 51_1 for CTE fist_table_agg: SELECT (max(value_1) + 1) AS v1_agg, user_id FROM public.raw_events_first GROUP BY user_id +DEBUG: Creating router plan +DEBUG: Plan is router executable +ROLLBACK; +-- We don't support CTEs that are referenced in the target list INSERT INTO agg_events WITH sub_cte AS (SELECT 1) SELECT @@ -701,7 +704,8 @@ INSERT INTO agg_events raw_events_first; DEBUG: Subqueries without relations are not allowed in distributed INSERT ... SELECT queries DEBUG: Collecting INSERT ... SELECT results on coordinator -ERROR: could not run distributed query with common table expressions +DEBUG: generating subplan 54_1 for CTE sub_cte: SELECT 1 +ERROR: could not run distributed query with subquery outside the FROM and WHERE clauses HINT: Consider using an equality filter on the distributed table's partition column. -- We support set operations via the coordinator BEGIN; diff --git a/src/test/regress/expected/multi_mx_router_planner.out b/src/test/regress/expected/multi_mx_router_planner.out index be69db7ce..62868945b 100644 --- a/src/test/regress/expected/multi_mx_router_planner.out +++ b/src/test/regress/expected/multi_mx_router_planner.out @@ -265,12 +265,22 @@ DEBUG: Plan is router executable ----+-----------+----+------- (0 rows) --- CTE joins are not supported if table shards are at different workers +-- CTE joins on different workers are supported because they are both planned recursively WITH id_author AS ( SELECT id, author_id FROM articles_hash_mx WHERE author_id = 1), id_title AS (SELECT id, title from articles_hash_mx WHERE author_id = 2) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. +DEBUG: generating subplan 66_1 for CTE id_author: SELECT id, author_id FROM public.articles_hash_mx WHERE (author_id = 1) +DEBUG: Creating router plan +DEBUG: Plan is router executable +DEBUG: generating subplan 66_2 for CTE id_title: SELECT id, title FROM public.articles_hash_mx WHERE (author_id = 2) +DEBUG: Creating router plan +DEBUG: Plan is router executable +DEBUG: Creating router plan +DEBUG: Plan is router executable + id | author_id | id | title +----+-----------+----+------- +(0 rows) + -- recursive CTEs are supported when filtered on partition column INSERT INTO company_employees_mx values(1, 1, 0); DEBUG: Creating router plan @@ -329,8 +339,7 @@ WITH RECURSIVE hierarchy as ( ON (h.employee_id = ce.manager_id AND h.company_id = ce.company_id)) SELECT * FROM hierarchy WHERE LEVEL <= 2; -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. +ERROR: recursive CTEs are not supported in distributed queries -- logically wrong query, query involves different shards -- from the same table, but still router plannable due to -- shard being placed on the same worker. @@ -345,8 +354,7 @@ WITH RECURSIVE hierarchy as ( h.company_id = ce.company_id AND ce.company_id = 2)) SELECT * FROM hierarchy WHERE LEVEL <= 2; -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. +ERROR: recursive CTEs are not supported in distributed queries -- grouping sets are supported on single shard SELECT id, substring(title, 2, 1) AS subtitle, count(*) @@ -584,15 +592,23 @@ DEBUG: Plan is router executable -- following join is not router plannable since there are no --- workers containing both shards, added a CTE to make this fail --- at logical planner +-- workers containing both shards, but will work through recursive +-- planning WITH single_shard as (SELECT * FROM articles_single_shard_hash_mx) SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash_mx a, single_shard b WHERE a.author_id = 2 and a.author_id = b.author_id LIMIT 3; DEBUG: Found no worker with all shard placements -ERROR: could not run distributed query with complex table expressions +DEBUG: generating subplan 94_1 for CTE single_shard: SELECT id, author_id, title, word_count FROM public.articles_single_shard_hash_mx +DEBUG: Creating router plan +DEBUG: Plan is router executable +DEBUG: Creating router plan +DEBUG: Plan is router executable + first_author | second_word_count +--------------+------------------- +(0 rows) + -- single shard select with limit is router plannable SELECT * FROM articles_hash_mx diff --git a/src/test/regress/expected/multi_router_planner.out b/src/test/regress/expected/multi_router_planner.out index d9e583bcf..0c7221d15 100644 --- a/src/test/regress/expected/multi_router_planner.out +++ b/src/test/regress/expected/multi_router_planner.out @@ -325,12 +325,22 @@ DEBUG: Plan is router executable ----+-----------+----+------- (0 rows) --- CTE joins are not supported if table shards are at different workers +-- CTE joins are supported because they are both planned recursively WITH id_author AS ( SELECT id, author_id FROM articles_hash WHERE author_id = 1), id_title AS (SELECT id, title from articles_hash WHERE author_id = 2) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. +DEBUG: generating subplan 67_1 for CTE id_author: SELECT id, author_id FROM public.articles_hash WHERE (author_id = 1) +DEBUG: Creating router plan +DEBUG: Plan is router executable +DEBUG: generating subplan 67_2 for CTE id_title: SELECT id, title FROM public.articles_hash WHERE (author_id = 2) +DEBUG: Creating router plan +DEBUG: Plan is router executable +DEBUG: Creating router plan +DEBUG: Plan is router executable + id | author_id | id | title +----+-----------+----+------- +(0 rows) + -- recursive CTEs are supported when filtered on partition column CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); SELECT master_create_distributed_table('company_employees', 'company_id', 'hash'); @@ -402,8 +412,7 @@ WITH RECURSIVE hierarchy as ( ON (h.employee_id = ce.manager_id AND h.company_id = ce.company_id)) SELECT * FROM hierarchy WHERE LEVEL <= 2; -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. +ERROR: recursive CTEs are not supported in distributed queries -- logically wrong query, query involves different shards -- from the same table WITH RECURSIVE hierarchy as ( @@ -417,16 +426,14 @@ WITH RECURSIVE hierarchy as ( h.company_id = ce.company_id AND ce.company_id = 2)) SELECT * FROM hierarchy WHERE LEVEL <= 2; -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. +ERROR: recursive CTEs are not supported in distributed queries -- CTE with queries other than SELECT is not supported WITH new_article AS ( INSERT INTO articles_hash VALUES (1, 1, 'arsenous', 9572) RETURNING * ) SELECT * FROM new_article; DEBUG: data-modifying statements are not supported in the WITH clauses of distributed queries -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. +ERROR: data-modifying statements are not supported in the WITH clauses of distributed queries -- Modifying statement in nested CTE case is covered by PostgreSQL itself WITH new_article AS ( WITH nested_cte AS ( @@ -700,16 +707,23 @@ DEBUG: Plan is router executable -- following join is not router plannable since there are no --- workers containing both shards, added a CTE to make this fail --- at logical planner +-- workers containing both shards, but will work through recursive +-- planning WITH single_shard as (SELECT * FROM articles_single_shard_hash) SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash a, single_shard b WHERE a.author_id = 2 and a.author_id = b.author_id LIMIT 3; DEBUG: Found no worker with all shard placements -ERROR: could not run distributed query with complex table expressions -HINT: Consider using an equality filter on the distributed table's partition column. +DEBUG: generating subplan 97_1 for CTE single_shard: SELECT id, author_id, title, word_count FROM public.articles_single_shard_hash +DEBUG: Creating router plan +DEBUG: Plan is router executable +DEBUG: Creating router plan +DEBUG: Plan is router executable + first_author | second_word_count +--------------+------------------- +(0 rows) + -- single shard select with limit is router plannable SELECT * FROM articles_hash diff --git a/src/test/regress/expected/multi_simple_queries.out b/src/test/regress/expected/multi_simple_queries.out index 17aaf100a..b997589ee 100644 --- a/src/test/regress/expected/multi_simple_queries.out +++ b/src/test/regress/expected/multi_simple_queries.out @@ -172,10 +172,18 @@ SELECT * FROM articles WHERE author_id = 10 UNION SELECT * FROM articles WHERE author_id = 2; ERROR: could not run distributed query with UNION, INTERSECT, or EXCEPT HINT: Consider using an equality filter on the distributed table's partition column. --- queries using CTEs are unsupported +-- queries using CTEs are supported WITH long_names AS ( SELECT id FROM authors WHERE char_length(name) > 15 ) -SELECT title FROM articles; -ERROR: relation authors is not distributed +SELECT title FROM articles ORDER BY 1 LIMIT 5; + title +----------- + abducing + abeyance + abhorring + abington + ablation +(5 rows) + -- queries which involve functions in FROM clause are unsupported. SELECT * FROM articles, position('om' in 'Thomas'); ERROR: could not run distributed query with complex table expressions diff --git a/src/test/regress/expected/multi_view.out b/src/test/regress/expected/multi_view.out index fab72b2cf..cb7c258ee 100644 --- a/src/test/regress/expected/multi_view.out +++ b/src/test/regress/expected/multi_view.out @@ -640,12 +640,12 @@ CREATE VIEW cte_view_1 AS WITH c1 AS (SELECT * FROM users_table WHERE value_1 = 3) SELECT * FROM c1 WHERE value_2 < 4; SELECT * FROM cte_view_1; ERROR: cannot push down this subquery -DETAIL: CTEs in multi-shard queries are currently unsupported +DETAIL: CTEs in subqueries are currently unsupported -- this is single shard query but still not supported since it has view + cte -- router planner can't detect it SELECT * FROM cte_view_1 WHERE user_id = 2; ERROR: cannot push down this subquery -DETAIL: CTEs in multi-shard queries are currently unsupported +DETAIL: CTEs in subqueries are currently unsupported -- if CTE itself prunes down to a single shard than the view is supported (router plannable) CREATE VIEW cte_view_2 AS WITH c1 AS (SELECT * FROM users_table WHERE user_id = 2) SELECT * FROM c1 WHERE value_1 = 3; diff --git a/src/test/regress/sql/multi_insert_select.sql b/src/test/regress/sql/multi_insert_select.sql index 618f3f971..ee80bd4f3 100644 --- a/src/test/regress/sql/multi_insert_select.sql +++ b/src/test/regress/sql/multi_insert_select.sql @@ -505,17 +505,19 @@ INSERT INTO agg_events (value_1_agg, user_id) SELECT user_id, value_1_agg FROM agg_events ORDER BY 1,2; --- We do not support some CTEs +-- We support CTEs +BEGIN; WITH fist_table_agg AS - (SELECT sum(value_1) as v1_agg, user_id FROM raw_events_first GROUP BY user_id) + (SELECT max(value_1)+1 as v1_agg, user_id FROM raw_events_first GROUP BY user_id) INSERT INTO agg_events (value_1_agg, user_id) SELECT v1_agg, user_id FROM fist_table_agg; +ROLLBACK; --- We don't support CTEs that consist of const values as well +-- We don't support CTEs that are referenced in the target list INSERT INTO agg_events WITH sub_cte AS (SELECT 1) SELECT diff --git a/src/test/regress/sql/multi_mx_router_planner.sql b/src/test/regress/sql/multi_mx_router_planner.sql index 6801e543b..7c0d840ad 100644 --- a/src/test/regress/sql/multi_mx_router_planner.sql +++ b/src/test/regress/sql/multi_mx_router_planner.sql @@ -137,7 +137,7 @@ WITH id_author AS ( SELECT id, author_id FROM articles_hash_mx WHERE author_id = id_title AS (SELECT id, title from articles_hash_mx WHERE author_id = 3) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; --- CTE joins are not supported if table shards are at different workers +-- CTE joins on different workers are supported because they are both planned recursively WITH id_author AS ( SELECT id, author_id FROM articles_hash_mx WHERE author_id = 1), id_title AS (SELECT id, title from articles_hash_mx WHERE author_id = 2) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; @@ -269,8 +269,8 @@ SELECT a.author_id as first_author, b.word_count as second_word_count LIMIT 3; -- following join is not router plannable since there are no --- workers containing both shards, added a CTE to make this fail --- at logical planner +-- workers containing both shards, but will work through recursive +-- planning WITH single_shard as (SELECT * FROM articles_single_shard_hash_mx) SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash_mx a, single_shard b diff --git a/src/test/regress/sql/multi_router_planner.sql b/src/test/regress/sql/multi_router_planner.sql index 66620d1c5..1e1707dc9 100644 --- a/src/test/regress/sql/multi_router_planner.sql +++ b/src/test/regress/sql/multi_router_planner.sql @@ -176,7 +176,7 @@ WITH id_author AS ( SELECT id, author_id FROM articles_hash WHERE author_id = 1) id_title AS (SELECT id, title from articles_hash WHERE author_id = 3) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; --- CTE joins are not supported if table shards are at different workers +-- CTE joins are supported because they are both planned recursively WITH id_author AS ( SELECT id, author_id FROM articles_hash WHERE author_id = 1), id_title AS (SELECT id, title from articles_hash WHERE author_id = 2) SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id; @@ -338,8 +338,8 @@ SELECT a.author_id as first_author, b.word_count as second_word_count LIMIT 3; -- following join is not router plannable since there are no --- workers containing both shards, added a CTE to make this fail --- at logical planner +-- workers containing both shards, but will work through recursive +-- planning WITH single_shard as (SELECT * FROM articles_single_shard_hash) SELECT a.author_id as first_author, b.word_count as second_word_count FROM articles_hash a, single_shard b diff --git a/src/test/regress/sql/multi_simple_queries.sql b/src/test/regress/sql/multi_simple_queries.sql index 5827331cb..4d8396885 100644 --- a/src/test/regress/sql/multi_simple_queries.sql +++ b/src/test/regress/sql/multi_simple_queries.sql @@ -120,9 +120,9 @@ SELECT author_id, sum(word_count) AS corpus_size FROM articles SELECT * FROM articles WHERE author_id = 10 UNION SELECT * FROM articles WHERE author_id = 2; --- queries using CTEs are unsupported +-- queries using CTEs are supported WITH long_names AS ( SELECT id FROM authors WHERE char_length(name) > 15 ) -SELECT title FROM articles; +SELECT title FROM articles ORDER BY 1 LIMIT 5; -- queries which involve functions in FROM clause are unsupported. SELECT * FROM articles, position('om' in 'Thomas');