From 446893234a175018fca751a7b12d0af3bcba7a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?mehmet=20furkan=20=C5=9Fahin?= Date: Fri, 22 Dec 2017 11:40:45 +0300 Subject: [PATCH] unsupported subquery error messages are fixed --- .../planner/multi_logical_planner.c | 15 ++++--- .../multi_subquery_complex_queries.out | 8 ++-- .../multi_subquery_in_where_clause.out | 2 +- ...lti_subquery_in_where_reference_clause.out | 4 +- .../expected/subqueries_not_supported.out | 40 ++++++++++++++++++ .../regress/sql/subqueries_not_supported.sql | 42 ++++++++++++++++++- 6 files changed, 98 insertions(+), 13 deletions(-) diff --git a/src/backend/distributed/planner/multi_logical_planner.c b/src/backend/distributed/planner/multi_logical_planner.c index fe3428324..5f6bc5037 100644 --- a/src/backend/distributed/planner/multi_logical_planner.c +++ b/src/backend/distributed/planner/multi_logical_planner.c @@ -960,14 +960,16 @@ DeferErrorIfCannotPushdownSubquery(Query *subqueryTree, bool outerMostQueryHasLi if (subqueryTree->limitOffset) { preconditionsSatisfied = false; - errorDetail = "Offset clause is currently unsupported"; + errorDetail = "Offset clause is currently unsupported when a subquery " + "references a column from another query"; } /* limit is not supported when SubqueryPushdown is not set */ if (subqueryTree->limitCount && !SubqueryPushdown) { preconditionsSatisfied = false; - errorDetail = "Limit in subquery is currently unsupported"; + errorDetail = "Limit in subquery is currently unsupported when a " + "subquery references a column from another query"; } /* @@ -1022,7 +1024,8 @@ DeferErrorIfCannotPushdownSubquery(Query *subqueryTree, bool outerMostQueryHasLi { preconditionsSatisfied = false; errorDetail = "Group by list without partition column is currently " - "unsupported"; + "unsupported when a subquery references a column " + "from another query"; } } @@ -1041,7 +1044,8 @@ DeferErrorIfCannotPushdownSubquery(Query *subqueryTree, bool outerMostQueryHasLi if (subqueryTree->hasAggs && (subqueryTree->groupClause == NULL)) { preconditionsSatisfied = false; - errorDetail = "Aggregates without group by are currently unsupported"; + errorDetail = "Aggregates without group by are currently unsupported " + "when a subquery references a column from another query"; } /* having clause without group by on partition column is not supported */ @@ -1049,7 +1053,8 @@ DeferErrorIfCannotPushdownSubquery(Query *subqueryTree, bool outerMostQueryHasLi { preconditionsSatisfied = false; errorDetail = "Having qual without group by on partition column is " - "currently unsupported"; + "currently unsupported when a subquery references " + "a column from another query"; } /* distinct clause list must include partition column */ diff --git a/src/test/regress/expected/multi_subquery_complex_queries.out b/src/test/regress/expected/multi_subquery_complex_queries.out index 0f2e103cb..2b649ae05 100644 --- a/src/test/regress/expected/multi_subquery_complex_queries.out +++ b/src/test/regress/expected/multi_subquery_complex_queries.out @@ -1213,7 +1213,7 @@ ORDER BY user_id limit 50; ERROR: cannot push down this subquery -DETAIL: Limit in subquery is currently unsupported +DETAIL: Limit in subquery is currently unsupported when a subquery references a column from another query -- we recursively plan some queries but fail in the end -- since some_users_data since it has a reference -- from an outer query which is not recursively planned @@ -1250,7 +1250,7 @@ ORDER BY user_id limit 50; ERROR: cannot push down this subquery -DETAIL: Limit in subquery is currently unsupported +DETAIL: Limit in subquery is currently unsupported when a subquery references a column from another query -- LATERAL JOINs used with INNER JOINs SET citus.subquery_pushdown to ON; SELECT user_id, lastseen @@ -1598,7 +1598,7 @@ ORDER BY user_id DESC LIMIT 10; ERROR: cannot push down this subquery -DETAIL: Limit in subquery is currently unsupported +DETAIL: Limit in subquery is currently unsupported when a subquery references a column from another query -- NESTED INNER JOINs SELECT count(*) AS value, "generated_group_field" @@ -2200,7 +2200,7 @@ ORDER BY value_2 DESC, user_id DESC LIMIT 10; ERROR: cannot push down this subquery -DETAIL: Limit in subquery is currently unsupported +DETAIL: Limit in subquery is currently unsupported when a subquery references a column from another query -- lets test some unsupported set operations -- not supported since we use INTERSECT SELECT ("final_query"."event_types") as types, count(*) AS sumOfEventType diff --git a/src/test/regress/expected/multi_subquery_in_where_clause.out b/src/test/regress/expected/multi_subquery_in_where_clause.out index 22d93f460..f8cc556b8 100644 --- a/src/test/regress/expected/multi_subquery_in_where_clause.out +++ b/src/test/regress/expected/multi_subquery_in_where_clause.out @@ -610,7 +610,7 @@ WHERE OFFSET 3 ); ERROR: cannot push down this subquery -DETAIL: Offset clause is currently unsupported +DETAIL: Offset clause is currently unsupported when a subquery references a column from another query -- we can detect unsupported subquerues even if they appear -- in WHERE subquery -> FROM subquery -> WHERE subquery -- but we can recursively plan that anyway diff --git a/src/test/regress/expected/multi_subquery_in_where_reference_clause.out b/src/test/regress/expected/multi_subquery_in_where_reference_clause.out index e606cc6f2..18eaba1fe 100644 --- a/src/test/regress/expected/multi_subquery_in_where_reference_clause.out +++ b/src/test/regress/expected/multi_subquery_in_where_reference_clause.out @@ -493,7 +493,7 @@ HAVING count(*) > 3 ORDER BY user_id LIMIT 5; ERROR: cannot push down this subquery -DETAIL: Group by list without partition column is currently unsupported +DETAIL: Group by list without partition column is currently unsupported when a subquery references a column from another query -- similar query with slightly more complex group by -- though the error message is a bit confusing SELECT @@ -516,4 +516,4 @@ HAVING count(*) > 3 ORDER BY user_id LIMIT 5; ERROR: cannot push down this subquery -DETAIL: Group by list without partition column is currently unsupported +DETAIL: Group by list without partition column is currently unsupported when a subquery references a column from another query diff --git a/src/test/regress/expected/subqueries_not_supported.out b/src/test/regress/expected/subqueries_not_supported.out index 19b693ab4..1dd59b325 100644 --- a/src/test/regress/expected/subqueries_not_supported.out +++ b/src/test/regress/expected/subqueries_not_supported.out @@ -143,6 +143,46 @@ DEBUG: generating subplan 17_1 for subquery SELECT users_table.value_2 FROM pub DEBUG: Plan 17 query after replacing subqueries and CTEs: SELECT foo.value_2 FROM ((SELECT intermediate_result.value_2 FROM read_intermediate_result('17_1'::text, 'binary'::citus_copy_format) intermediate_result(value_2 integer)) foo LEFT JOIN (SELECT users_table.value_2 FROM public.users_table, public.events_table WHERE ((users_table.user_id = events_table.user_id) AND (events_table.event_type = ANY (ARRAY[5, 6, 7, 8])))) bar ON ((foo.value_2 = bar.value_2))) ERROR: cannot pushdown the subquery DETAIL: Complex subqueries and CTEs cannot be in the outer part of the outer join +-- Aggregates in subquery without partition column can be planned recursively +-- unless there is a reference to an outer query +SELECT + * +FROM + users_table +WHERE + user_id IN + ( + SELECT + SUM(events_table.user_id) + FROM + events_table + WHERE + users_table.user_id = events_table.user_id + ) +; +ERROR: cannot push down this subquery +DETAIL: Aggregates without group by are currently unsupported when a subquery references a column from another query +-- Having qual without group by on partition column can be planned recursively +-- unless there is a reference to an outer query +SELECT + * +FROM + users_table +WHERE + user_id IN + ( + SELECT + SUM(events_table.user_id) + FROM + events_table + WHERE + events_table.user_id = users_table.user_id + HAVING + MIN(value_2) > 2 + ) +; +ERROR: cannot push down this subquery +DETAIL: Having qual without group by on partition column is currently unsupported when a subquery references a column from another query SET client_min_messages TO DEFAULT; DROP SCHEMA not_supported CASCADE; NOTICE: drop cascades to table users_table_local diff --git a/src/test/regress/sql/subqueries_not_supported.sql b/src/test/regress/sql/subqueries_not_supported.sql index 44de380f1..136117045 100644 --- a/src/test/regress/sql/subqueries_not_supported.sql +++ b/src/test/regress/sql/subqueries_not_supported.sql @@ -131,7 +131,47 @@ FROM (SELECT users_table.value_2 FROM users_table, events_table WHERE users_table.user_id = events_table.user_id AND event_type IN (5,6,7,8)) as bar ON(foo.value_2 = bar.value_2); + +-- Aggregates in subquery without partition column can be planned recursively +-- unless there is a reference to an outer query +SELECT + * +FROM + users_table +WHERE + user_id IN + ( + SELECT + SUM(events_table.user_id) + FROM + events_table + WHERE + users_table.user_id = events_table.user_id + ) +; + + +-- Having qual without group by on partition column can be planned recursively +-- unless there is a reference to an outer query +SELECT + * +FROM + users_table +WHERE + user_id IN + ( + SELECT + SUM(events_table.user_id) + FROM + events_table + WHERE + events_table.user_id = users_table.user_id + HAVING + MIN(value_2) > 2 + ) +; + SET client_min_messages TO DEFAULT; DROP SCHEMA not_supported CASCADE; -SET search_path TO public; \ No newline at end of file +SET search_path TO public;