mirror of https://github.com/citusdata/citus.git
Merge pull request #2742 from citusdata/fix_2739_outer_join_subquery_error
Also check rewrittenQuery jointree for outer joinpull/2654/head
commit
5cc8049caa
|
@ -142,6 +142,19 @@ ShouldUseSubqueryPushDown(Query *originalQuery, Query *rewrittenQuery)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Original query may not have an outer join while rewritten query does.
|
||||||
|
* We should push down in this case.
|
||||||
|
* An example of this is https://github.com/citusdata/citus/issues/2739
|
||||||
|
* where postgres pulls-up the outer-join in the subquery.
|
||||||
|
*/
|
||||||
|
if (FindNodeCheck((Node *) rewrittenQuery->jointree, IsOuterJoinExpr))
|
||||||
|
{
|
||||||
|
/* Assert what _should_ be only situation this occurs in. */
|
||||||
|
Assert(JoinTreeContainsSubquery(originalQuery));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Some unsupported join clauses in logical planner
|
* Some unsupported join clauses in logical planner
|
||||||
* may be supported by subquery pushdown planner.
|
* may be supported by subquery pushdown planner.
|
||||||
|
|
|
@ -462,6 +462,25 @@ SELECT DISTINCT ON (t1.user_id) t1.user_id, t2.value_1, t2.value_2, t2.value_3
|
||||||
ORDER BY 1 DESC, 2 DESC, 3 DESC, 4 DESC
|
ORDER BY 1 DESC, 2 DESC, 3 DESC, 4 DESC
|
||||||
LIMIT 5;
|
LIMIT 5;
|
||||||
ERROR: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator
|
ERROR: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator
|
||||||
|
-- outer joins as subqueries should work
|
||||||
|
-- https://github.com/citusdata/citus/issues/2739
|
||||||
|
SELECT user_id, value_1, event_type
|
||||||
|
FROM (
|
||||||
|
SELECT a.user_id, a.value_1, b.event_type
|
||||||
|
FROM users_table a
|
||||||
|
LEFT JOIN events_table b ON a.user_id = b.user_id
|
||||||
|
) lo
|
||||||
|
ORDER BY 1, 2, 3
|
||||||
|
LIMIT 5;
|
||||||
|
user_id | value_1 | event_type
|
||||||
|
---------+---------+------------
|
||||||
|
1 | 1 | 0
|
||||||
|
1 | 1 | 0
|
||||||
|
1 | 1 | 1
|
||||||
|
1 | 1 | 1
|
||||||
|
1 | 1 | 2
|
||||||
|
(5 rows)
|
||||||
|
|
||||||
-- inner joins on reference tables with functions works
|
-- inner joins on reference tables with functions works
|
||||||
SELECT DISTINCT ON (t1.user_id) t1.user_id, t2.value_1, t2.value_2, t2.value_3
|
SELECT DISTINCT ON (t1.user_id) t1.user_id, t2.value_1, t2.value_2, t2.value_3
|
||||||
FROM events_table t1
|
FROM events_table t1
|
||||||
|
|
|
@ -957,7 +957,7 @@ $$);
|
||||||
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
|
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
|
||||||
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
|
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
|
||||||
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
|
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
|
||||||
ERROR: cannot perform distributed planning on this query
|
ERROR: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator
|
||||||
-- similar to the above, make sure that we skip recursive plannig when
|
-- similar to the above, make sure that we skip recursive plannig when
|
||||||
-- the subquery contains only intermediate results
|
-- the subquery contains only intermediate results
|
||||||
SELECT *
|
SELECT *
|
||||||
|
|
|
@ -314,6 +314,17 @@ SELECT DISTINCT ON (t1.user_id) t1.user_id, t2.value_1, t2.value_2, t2.value_3
|
||||||
ORDER BY 1 DESC, 2 DESC, 3 DESC, 4 DESC
|
ORDER BY 1 DESC, 2 DESC, 3 DESC, 4 DESC
|
||||||
LIMIT 5;
|
LIMIT 5;
|
||||||
|
|
||||||
|
-- outer joins as subqueries should work
|
||||||
|
-- https://github.com/citusdata/citus/issues/2739
|
||||||
|
SELECT user_id, value_1, event_type
|
||||||
|
FROM (
|
||||||
|
SELECT a.user_id, a.value_1, b.event_type
|
||||||
|
FROM users_table a
|
||||||
|
LEFT JOIN events_table b ON a.user_id = b.user_id
|
||||||
|
) lo
|
||||||
|
ORDER BY 1, 2, 3
|
||||||
|
LIMIT 5;
|
||||||
|
|
||||||
-- inner joins on reference tables with functions works
|
-- inner joins on reference tables with functions works
|
||||||
SELECT DISTINCT ON (t1.user_id) t1.user_id, t2.value_1, t2.value_2, t2.value_3
|
SELECT DISTINCT ON (t1.user_id) t1.user_id, t2.value_1, t2.value_2, t2.value_3
|
||||||
FROM events_table t1
|
FROM events_table t1
|
||||||
|
|
Loading…
Reference in New Issue