Regression test output changes after CTE support

pull/1853/head
Marco Slot 2017-12-04 18:32:19 +01:00
parent 2e2b4e81fa
commit fa73abe6d4
9 changed files with 89 additions and 45 deletions

View File

@ -679,9 +679,10 @@ SELECT user_id, value_1_agg FROM agg_events ORDER BY 1,2;
9 | 90 9 | 90
(9 rows) (9 rows)
-- We do not support some CTEs -- We support CTEs
BEGIN;
WITH fist_table_agg AS 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 INSERT INTO agg_events
(value_1_agg, user_id) (value_1_agg, user_id)
SELECT SELECT
@ -690,9 +691,11 @@ INSERT INTO agg_events
fist_table_agg; fist_table_agg;
DEBUG: distributed INSERT ... SELECT can only select from distributed tables DEBUG: distributed INSERT ... SELECT can only select from distributed tables
DEBUG: Collecting INSERT ... SELECT results on coordinator DEBUG: Collecting INSERT ... SELECT results on coordinator
ERROR: could not run distributed query with complex table expressions 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
HINT: Consider using an equality filter on the distributed table's partition column. DEBUG: Creating router plan
-- We don't support CTEs that consist of const values as well DEBUG: Plan is router executable
ROLLBACK;
-- We don't support CTEs that are referenced in the target list
INSERT INTO agg_events INSERT INTO agg_events
WITH sub_cte AS (SELECT 1) WITH sub_cte AS (SELECT 1)
SELECT SELECT
@ -701,7 +704,8 @@ INSERT INTO agg_events
raw_events_first; raw_events_first;
DEBUG: Subqueries without relations are not allowed in distributed INSERT ... SELECT queries DEBUG: Subqueries without relations are not allowed in distributed INSERT ... SELECT queries
DEBUG: Collecting INSERT ... SELECT results on coordinator 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. HINT: Consider using an equality filter on the distributed table's partition column.
-- We support set operations via the coordinator -- We support set operations via the coordinator
BEGIN; BEGIN;

View File

@ -265,12 +265,22 @@ DEBUG: Plan is router executable
----+-----------+----+------- ----+-----------+----+-------
(0 rows) (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), 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) 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; SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id;
ERROR: could not run distributed query with complex table expressions DEBUG: generating subplan 66_1 for CTE id_author: SELECT id, author_id FROM public.articles_hash_mx WHERE (author_id = 1)
HINT: Consider using an equality filter on the distributed table's partition column. 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 -- recursive CTEs are supported when filtered on partition column
INSERT INTO company_employees_mx values(1, 1, 0); INSERT INTO company_employees_mx values(1, 1, 0);
DEBUG: Creating router plan DEBUG: Creating router plan
@ -329,8 +339,7 @@ WITH RECURSIVE hierarchy as (
ON (h.employee_id = ce.manager_id AND ON (h.employee_id = ce.manager_id AND
h.company_id = ce.company_id)) h.company_id = ce.company_id))
SELECT * FROM hierarchy WHERE LEVEL <= 2; SELECT * FROM hierarchy WHERE LEVEL <= 2;
ERROR: could not run distributed query with complex table expressions ERROR: recursive CTEs are not supported in distributed queries
HINT: Consider using an equality filter on the distributed table's partition 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.
@ -345,8 +354,7 @@ WITH RECURSIVE hierarchy as (
h.company_id = ce.company_id AND h.company_id = ce.company_id AND
ce.company_id = 2)) ce.company_id = 2))
SELECT * FROM hierarchy WHERE LEVEL <= 2; SELECT * FROM hierarchy WHERE LEVEL <= 2;
ERROR: could not run distributed query with complex table expressions ERROR: recursive CTEs are not supported in distributed queries
HINT: Consider using an equality filter on the distributed table's partition 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(*)
@ -584,15 +592,23 @@ DEBUG: Plan is router executable
-- following join is not router plannable since there are no -- following join is not router plannable since there are no
-- workers containing both shards, added a CTE to make this fail -- workers containing both shards, but will work through recursive
-- at logical planner -- planning
WITH single_shard as (SELECT * FROM articles_single_shard_hash_mx) 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 SELECT a.author_id as first_author, b.word_count as second_word_count
FROM articles_hash_mx a, single_shard b FROM articles_hash_mx a, single_shard b
WHERE a.author_id = 2 and a.author_id = b.author_id WHERE a.author_id = 2 and a.author_id = b.author_id
LIMIT 3; LIMIT 3;
DEBUG: Found no worker with all shard placements 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 -- single shard select with limit is router plannable
SELECT * SELECT *
FROM articles_hash_mx FROM articles_hash_mx

View File

@ -325,12 +325,22 @@ DEBUG: Plan is router executable
----+-----------+----+------- ----+-----------+----+-------
(0 rows) (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), 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) 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; SELECT * FROM id_author, id_title WHERE id_author.id = id_title.id;
ERROR: could not run distributed query with complex table expressions DEBUG: generating subplan 67_1 for CTE id_author: SELECT id, author_id FROM public.articles_hash WHERE (author_id = 1)
HINT: Consider using an equality filter on the distributed table's partition column. 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 -- recursive CTEs are supported when filtered on partition column
CREATE TABLE company_employees (company_id int, employee_id int, manager_id int); CREATE TABLE company_employees (company_id int, employee_id int, manager_id int);
SELECT master_create_distributed_table('company_employees', 'company_id', 'hash'); 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 ON (h.employee_id = ce.manager_id AND
h.company_id = ce.company_id)) h.company_id = ce.company_id))
SELECT * FROM hierarchy WHERE LEVEL <= 2; SELECT * FROM hierarchy WHERE LEVEL <= 2;
ERROR: could not run distributed query with complex table expressions ERROR: recursive CTEs are not supported in distributed queries
HINT: Consider using an equality filter on the distributed table's partition 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 ( WITH RECURSIVE hierarchy as (
@ -417,16 +426,14 @@ WITH RECURSIVE hierarchy as (
h.company_id = ce.company_id AND h.company_id = ce.company_id AND
ce.company_id = 2)) ce.company_id = 2))
SELECT * FROM hierarchy WHERE LEVEL <= 2; SELECT * FROM hierarchy WHERE LEVEL <= 2;
ERROR: could not run distributed query with complex table expressions ERROR: recursive CTEs are not supported in distributed queries
HINT: Consider using an equality filter on the distributed table's partition column.
-- CTE with queries other than SELECT is not supported -- CTE with queries other than SELECT is not supported
WITH new_article AS ( WITH new_article AS (
INSERT INTO articles_hash VALUES (1, 1, 'arsenous', 9572) RETURNING * INSERT INTO articles_hash VALUES (1, 1, 'arsenous', 9572) RETURNING *
) )
SELECT * FROM new_article; SELECT * FROM new_article;
DEBUG: data-modifying statements are not supported in the WITH clauses of distributed queries DEBUG: data-modifying statements are not supported in the WITH clauses of distributed queries
ERROR: could not run distributed query with complex table expressions ERROR: data-modifying statements are not supported in the WITH clauses of distributed queries
HINT: Consider using an equality filter on the distributed table's partition column.
-- Modifying statement in nested CTE case is covered by PostgreSQL itself -- Modifying statement in nested CTE case is covered by PostgreSQL itself
WITH new_article AS ( WITH new_article AS (
WITH nested_cte AS ( WITH nested_cte AS (
@ -700,16 +707,23 @@ DEBUG: Plan is router executable
-- following join is not router plannable since there are no -- following join is not router plannable since there are no
-- workers containing both shards, added a CTE to make this fail -- workers containing both shards, but will work through recursive
-- at logical planner -- planning
WITH single_shard as (SELECT * FROM articles_single_shard_hash) WITH single_shard as (SELECT * FROM articles_single_shard_hash)
SELECT a.author_id as first_author, b.word_count as second_word_count SELECT a.author_id as first_author, b.word_count as second_word_count
FROM articles_hash a, single_shard b FROM articles_hash a, single_shard b
WHERE a.author_id = 2 and a.author_id = b.author_id WHERE a.author_id = 2 and a.author_id = b.author_id
LIMIT 3; LIMIT 3;
DEBUG: Found no worker with all shard placements DEBUG: Found no worker with all shard placements
ERROR: could not run distributed query with complex table expressions DEBUG: generating subplan 97_1 for CTE single_shard: SELECT id, author_id, title, word_count FROM public.articles_single_shard_hash
HINT: Consider using an equality filter on the distributed table's partition column. 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 -- single shard select with limit is router plannable
SELECT * SELECT *
FROM articles_hash FROM articles_hash

View File

@ -172,10 +172,18 @@ SELECT * FROM articles WHERE author_id = 10 UNION
SELECT * FROM articles WHERE author_id = 2; SELECT * FROM articles WHERE author_id = 2;
ERROR: could not run distributed query with UNION, INTERSECT, or EXCEPT ERROR: could not run distributed query with UNION, INTERSECT, or EXCEPT
HINT: Consider using an equality filter on the distributed table's partition column. 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 ) 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;
ERROR: relation authors is not distributed title
-----------
abducing
abeyance
abhorring
abington
ablation
(5 rows)
-- queries which involve functions in FROM clause are unsupported. -- queries which involve functions in FROM clause are unsupported.
SELECT * FROM articles, position('om' in 'Thomas'); SELECT * FROM articles, position('om' in 'Thomas');
ERROR: could not run distributed query with complex table expressions ERROR: could not run distributed query with complex table expressions

View File

@ -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; WITH c1 AS (SELECT * FROM users_table WHERE value_1 = 3) SELECT * FROM c1 WHERE value_2 < 4;
SELECT * FROM cte_view_1; SELECT * FROM cte_view_1;
ERROR: cannot push down this subquery 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 -- this is single shard query but still not supported since it has view + cte
-- router planner can't detect it -- router planner can't detect it
SELECT * FROM cte_view_1 WHERE user_id = 2; SELECT * FROM cte_view_1 WHERE user_id = 2;
ERROR: cannot push down this subquery 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) -- if CTE itself prunes down to a single shard than the view is supported (router plannable)
CREATE VIEW cte_view_2 AS CREATE VIEW cte_view_2 AS
WITH c1 AS (SELECT * FROM users_table WHERE user_id = 2) SELECT * FROM c1 WHERE value_1 = 3; WITH c1 AS (SELECT * FROM users_table WHERE user_id = 2) SELECT * FROM c1 WHERE value_1 = 3;

View File

@ -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; 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 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 INSERT INTO agg_events
(value_1_agg, user_id) (value_1_agg, user_id)
SELECT SELECT
v1_agg, user_id v1_agg, user_id
FROM FROM
fist_table_agg; 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 INSERT INTO agg_events
WITH sub_cte AS (SELECT 1) WITH sub_cte AS (SELECT 1)
SELECT SELECT

View File

@ -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) 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; 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), 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) 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; 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; LIMIT 3;
-- following join is not router plannable since there are no -- following join is not router plannable since there are no
-- workers containing both shards, added a CTE to make this fail -- workers containing both shards, but will work through recursive
-- at logical planner -- planning
WITH single_shard as (SELECT * FROM articles_single_shard_hash_mx) 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 SELECT a.author_id as first_author, b.word_count as second_word_count
FROM articles_hash_mx a, single_shard b FROM articles_hash_mx a, single_shard b

View File

@ -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) 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; 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), 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) 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; 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; LIMIT 3;
-- following join is not router plannable since there are no -- following join is not router plannable since there are no
-- workers containing both shards, added a CTE to make this fail -- workers containing both shards, but will work through recursive
-- at logical planner -- planning
WITH single_shard as (SELECT * FROM articles_single_shard_hash) WITH single_shard as (SELECT * FROM articles_single_shard_hash)
SELECT a.author_id as first_author, b.word_count as second_word_count SELECT a.author_id as first_author, b.word_count as second_word_count
FROM articles_hash a, single_shard b FROM articles_hash a, single_shard b

View File

@ -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 = 10 UNION
SELECT * FROM articles WHERE author_id = 2; 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 ) 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. -- queries which involve functions in FROM clause are unsupported.
SELECT * FROM articles, position('om' in 'Thomas'); SELECT * FROM articles, position('om' in 'Thomas');