mirror of https://github.com/citusdata/citus.git
Fix incorrect union all pushdown issue
parent
7a909fc807
commit
ba39d72fe1
|
@ -596,7 +596,7 @@ DeferErrorIfUnsupportedSubqueryPushdown(Query *originalQuery,
|
||||||
{
|
{
|
||||||
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
|
return DeferredError(ERRCODE_FEATURE_NOT_SUPPORTED,
|
||||||
"complex joins are only supported when all distributed tables are "
|
"complex joins are only supported when all distributed tables are "
|
||||||
"joined on their distribution columns with equal operator",
|
"co-located and joined on their distribution columns",
|
||||||
NULL, NULL);
|
NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
*/
|
*/
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
|
||||||
|
#include "distributed/colocation_utils.h"
|
||||||
#include "distributed/distributed_planner.h"
|
#include "distributed/distributed_planner.h"
|
||||||
|
#include "distributed/listutils.h"
|
||||||
#include "distributed/metadata_cache.h"
|
#include "distributed/metadata_cache.h"
|
||||||
#include "distributed/multi_logical_planner.h"
|
#include "distributed/multi_logical_planner.h"
|
||||||
#include "distributed/multi_logical_optimizer.h"
|
#include "distributed/multi_logical_optimizer.h"
|
||||||
|
@ -133,6 +135,8 @@ static void ListConcatUniqueAttributeClassMemberLists(AttributeEquivalenceClass
|
||||||
secondClass);
|
secondClass);
|
||||||
static Index RelationRestrictionPartitionKeyIndex(RelationRestriction *
|
static Index RelationRestrictionPartitionKeyIndex(RelationRestriction *
|
||||||
relationRestriction);
|
relationRestriction);
|
||||||
|
static bool AllRelationsInRestrictionContextColocated(RelationRestrictionContext *
|
||||||
|
restrictionContext);
|
||||||
static RelationRestrictionContext * FilterRelationRestrictionContext(
|
static RelationRestrictionContext * FilterRelationRestrictionContext(
|
||||||
RelationRestrictionContext *relationRestrictionContext,
|
RelationRestrictionContext *relationRestrictionContext,
|
||||||
Relids
|
Relids
|
||||||
|
@ -345,8 +349,20 @@ SafeToPushdownUnionSubquery(PlannerRestrictionContext *plannerRestrictionContext
|
||||||
allAttributeEquivalenceList = lappend(allAttributeEquivalenceList,
|
allAttributeEquivalenceList = lappend(allAttributeEquivalenceList,
|
||||||
attributeEquivalance);
|
attributeEquivalance);
|
||||||
|
|
||||||
return EquivalenceListContainsRelationsEquality(allAttributeEquivalenceList,
|
if (!EquivalenceListContainsRelationsEquality(allAttributeEquivalenceList,
|
||||||
restrictionContext);
|
restrictionContext))
|
||||||
|
{
|
||||||
|
/* cannot confirm equality for all distribution colums */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!AllRelationsInRestrictionContextColocated(restrictionContext))
|
||||||
|
{
|
||||||
|
/* distribution columns are equal, but tables are not co-located */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1650,6 +1666,42 @@ RelationRestrictionPartitionKeyIndex(RelationRestriction *relationRestriction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* AllRelationsInRestrictionContextColocated determines whether all of the relations in the
|
||||||
|
* given relation restrictions list are co-located.
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
AllRelationsInRestrictionContextColocated(RelationRestrictionContext *restrictionContext)
|
||||||
|
{
|
||||||
|
RelationRestriction *relationRestriction = NULL;
|
||||||
|
int initialColocationId = INVALID_COLOCATION_ID;
|
||||||
|
|
||||||
|
/* check whether all relations exists in the main restriction list */
|
||||||
|
foreach_ptr(relationRestriction, restrictionContext->relationRestrictionList)
|
||||||
|
{
|
||||||
|
Oid relationId = relationRestriction->relationId;
|
||||||
|
|
||||||
|
if (PartitionMethod(relationId) == DISTRIBUTE_BY_NONE)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int colocationId = TableColocationId(relationId);
|
||||||
|
|
||||||
|
if (initialColocationId == INVALID_COLOCATION_ID)
|
||||||
|
{
|
||||||
|
initialColocationId = colocationId;
|
||||||
|
}
|
||||||
|
else if (colocationId != initialColocationId)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* RelationIdList returns list of unique relation ids in query tree.
|
* RelationIdList returns list of unique relation ids in query tree.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -274,14 +274,14 @@ where s_order_cnt > (select sum(s_order_cnt) * .005 as where_query from stock)
|
||||||
group by s_i_id
|
group by s_i_id
|
||||||
having (select max(s_order_cnt) > 2 as having_query from stock where s_i_id = s.s_i_id)
|
having (select max(s_order_cnt) > 2 as having_query from stock where s_i_id = s.s_i_id)
|
||||||
order by s_i_id;
|
order by s_i_id;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- We don't support correlated subqueries in having
|
-- We don't support correlated subqueries in having
|
||||||
select s_i_id, sum(s_order_cnt) as ordercount
|
select s_i_id, sum(s_order_cnt) as ordercount
|
||||||
from stock s
|
from stock s
|
||||||
group by s_i_id
|
group by s_i_id
|
||||||
having (select max(s_order_cnt) > 2 as having_query from stock where s_i_id = s.s_i_id)
|
having (select max(s_order_cnt) > 2 as having_query from stock where s_i_id = s.s_i_id)
|
||||||
order by s_i_id;
|
order by s_i_id;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
DROP TABLE stock;
|
DROP TABLE stock;
|
||||||
CREATE TABLE stock (
|
CREATE TABLE stock (
|
||||||
s_w_id int NOT NULL,
|
s_w_id int NOT NULL,
|
||||||
|
|
|
@ -279,14 +279,14 @@ where s_order_cnt > (select sum(s_order_cnt) * .005 as where_query from stock)
|
||||||
group by s_i_id
|
group by s_i_id
|
||||||
having (select max(s_order_cnt) > 2 as having_query from stock where s_i_id = s.s_i_id)
|
having (select max(s_order_cnt) > 2 as having_query from stock where s_i_id = s.s_i_id)
|
||||||
order by s_i_id;
|
order by s_i_id;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- We don't support correlated subqueries in having
|
-- We don't support correlated subqueries in having
|
||||||
select s_i_id, sum(s_order_cnt) as ordercount
|
select s_i_id, sum(s_order_cnt) as ordercount
|
||||||
from stock s
|
from stock s
|
||||||
group by s_i_id
|
group by s_i_id
|
||||||
having (select max(s_order_cnt) > 2 as having_query from stock where s_i_id = s.s_i_id)
|
having (select max(s_order_cnt) > 2 as having_query from stock where s_i_id = s.s_i_id)
|
||||||
order by s_i_id;
|
order by s_i_id;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
\c - - - :master_port
|
\c - - - :master_port
|
||||||
SET citus.replication_model TO streaming;
|
SET citus.replication_model TO streaming;
|
||||||
SET citus.shard_replication_factor to 1;
|
SET citus.shard_replication_factor to 1;
|
||||||
|
|
|
@ -116,7 +116,7 @@ select s_i_id
|
||||||
where
|
where
|
||||||
s_i_id in (select i_im_id from item)
|
s_i_id in (select i_im_id from item)
|
||||||
AND s_i_id = ol_i_id;
|
AND s_i_id = ol_i_id;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- Subquery + repartion is supported when it is a NOT IN query where the subquery
|
-- Subquery + repartion is supported when it is a NOT IN query where the subquery
|
||||||
-- returns unique results
|
-- returns unique results
|
||||||
select s_i_id
|
select s_i_id
|
||||||
|
@ -124,7 +124,7 @@ select s_i_id
|
||||||
where
|
where
|
||||||
s_i_id not in (select i_id from item)
|
s_i_id not in (select i_id from item)
|
||||||
AND s_i_id = ol_i_id;
|
AND s_i_id = ol_i_id;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- Subquery + repartion is not supported when it is a NOT IN where the subquery
|
-- Subquery + repartion is not supported when it is a NOT IN where the subquery
|
||||||
-- doesn't return unique results
|
-- doesn't return unique results
|
||||||
select s_i_id
|
select s_i_id
|
||||||
|
@ -132,7 +132,7 @@ select s_i_id
|
||||||
where
|
where
|
||||||
s_i_id not in (select i_im_id from item)
|
s_i_id not in (select i_im_id from item)
|
||||||
AND s_i_id = ol_i_id;
|
AND s_i_id = ol_i_id;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- Actual CHbenCHmark query is supported
|
-- Actual CHbenCHmark query is supported
|
||||||
select su_name, su_address
|
select su_name, su_address
|
||||||
from supplier, nation
|
from supplier, nation
|
||||||
|
|
|
@ -262,7 +262,7 @@ FROM
|
||||||
) as foo
|
) as foo
|
||||||
RETURNING *;
|
RETURNING *;
|
||||||
DEBUG: generating subplan 15_1 for subquery SELECT dept FROM recursive_dml_queries.second_distributed_table
|
DEBUG: generating subplan 15_1 for subquery SELECT dept FROM recursive_dml_queries.second_distributed_table
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- again a corrolated subquery
|
-- again a corrolated subquery
|
||||||
-- this time distribution key eq. exists
|
-- this time distribution key eq. exists
|
||||||
-- however recursive planning is prevented due to correlated subqueries
|
-- however recursive planning is prevented due to correlated subqueries
|
||||||
|
@ -292,7 +292,7 @@ FROM
|
||||||
) as baz
|
) as baz
|
||||||
) as foo WHERE second_distributed_table.tenant_id = foo.tenant_id
|
) as foo WHERE second_distributed_table.tenant_id = foo.tenant_id
|
||||||
RETURNING *;
|
RETURNING *;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- we don't support subqueries/CTEs inside VALUES
|
-- we don't support subqueries/CTEs inside VALUES
|
||||||
INSERT INTO
|
INSERT INTO
|
||||||
second_distributed_table (tenant_id, dept)
|
second_distributed_table (tenant_id, dept)
|
||||||
|
|
|
@ -59,4 +59,4 @@ FROM (customer LEFT OUTER JOIN orders ON (c_custkey = o_custkey)) AS
|
||||||
test(c_custkey, c_nationkey)
|
test(c_custkey, c_nationkey)
|
||||||
INNER JOIN lineitem ON (test.c_custkey = l_orderkey)
|
INNER JOIN lineitem ON (test.c_custkey = l_orderkey)
|
||||||
LIMIT 10;
|
LIMIT 10;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
|
|
|
@ -83,7 +83,7 @@ SELECT create_distributed_table('temp_nations', 'name', 'hash');
|
||||||
SELECT master_modify_multiple_shards('DELETE FROM multi_shard_modify_test USING temp_nations WHERE multi_shard_modify_test.t_value = temp_nations.key AND temp_nations.name = ''foobar'' ');
|
SELECT master_modify_multiple_shards('DELETE FROM multi_shard_modify_test USING temp_nations WHERE multi_shard_modify_test.t_value = temp_nations.key AND temp_nations.name = ''foobar'' ');
|
||||||
WARNING: master_modify_multiple_shards is deprecated and will be removed in a future release.
|
WARNING: master_modify_multiple_shards is deprecated and will be removed in a future release.
|
||||||
HINT: Run the command directly
|
HINT: Run the command directly
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- commands with a RETURNING clause are unsupported
|
-- commands with a RETURNING clause are unsupported
|
||||||
SELECT master_modify_multiple_shards('DELETE FROM multi_shard_modify_test WHERE t_key = 3 RETURNING *');
|
SELECT master_modify_multiple_shards('DELETE FROM multi_shard_modify_test WHERE t_key = 3 RETURNING *');
|
||||||
WARNING: master_modify_multiple_shards is deprecated and will be removed in a future release.
|
WARNING: master_modify_multiple_shards is deprecated and will be removed in a future release.
|
||||||
|
|
|
@ -656,7 +656,7 @@ WHERE user_id IN (SELECT user_id
|
||||||
UPDATE users_test_table
|
UPDATE users_test_table
|
||||||
SET value_2 = (SELECT value_3
|
SET value_2 = (SELECT value_3
|
||||||
FROM users_test_table);
|
FROM users_test_table);
|
||||||
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 co-located and joined on their distribution columns
|
||||||
UPDATE users_test_table
|
UPDATE users_test_table
|
||||||
SET value_2 = 2
|
SET value_2 = 2
|
||||||
WHERE
|
WHERE
|
||||||
|
@ -671,7 +671,7 @@ WHERE
|
||||||
GROUP BY
|
GROUP BY
|
||||||
user_id
|
user_id
|
||||||
);
|
);
|
||||||
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 co-located and joined on their distribution columns
|
||||||
UPDATE users_test_table
|
UPDATE users_test_table
|
||||||
SET (value_1, value_2) = (2,1)
|
SET (value_1, value_2) = (2,1)
|
||||||
WHERE user_id IN
|
WHERE user_id IN
|
||||||
|
|
|
@ -426,7 +426,7 @@ FROM events_table t1
|
||||||
LEFT JOIN users_table t2 ON t1.user_id > t2.user_id
|
LEFT JOIN users_table t2 ON t1.user_id > t2.user_id
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- outer joins on reference tables with expressions should work
|
-- outer joins on reference tables with expressions should work
|
||||||
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
|
||||||
|
@ -467,7 +467,7 @@ SELECT DISTINCT ON (t1.user_id) t1.user_id, t2.value_1, t2.value_2, t2.value_3
|
||||||
LEFT JOIN users_reference_table t2 ON t1.user_id = trunc(t2.user_id)
|
LEFT JOIN users_reference_table t2 ON t1.user_id = trunc(t2.user_id)
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- outer joins as subqueries should work
|
-- outer joins as subqueries should work
|
||||||
-- https://github.com/citusdata/citus/issues/2739
|
-- https://github.com/citusdata/citus/issues/2739
|
||||||
SELECT user_id, value_1, event_type
|
SELECT user_id, value_1, event_type
|
||||||
|
|
|
@ -2011,7 +2011,7 @@ FROM (
|
||||||
GROUP BY user_id
|
GROUP BY user_id
|
||||||
) q
|
) q
|
||||||
ORDER BY 2 DESC, 1;
|
ORDER BY 2 DESC, 1;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- note that the following query has both equi-joins on the partition keys
|
-- note that the following query has both equi-joins on the partition keys
|
||||||
-- and non-equi-joins on other columns. We now support query filters
|
-- and non-equi-joins on other columns. We now support query filters
|
||||||
-- having non-equi-joins as long as they have equi-joins on partition keys.
|
-- having non-equi-joins as long as they have equi-joins on partition keys.
|
||||||
|
@ -2100,7 +2100,7 @@ FROM
|
||||||
events_table.time = users_table.time AND
|
events_table.time = users_table.time AND
|
||||||
events_table.value_2 IN (0, 4)
|
events_table.value_2 IN (0, 4)
|
||||||
) as foo;
|
) as foo;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- we can even allow that on top level joins
|
-- we can even allow that on top level joins
|
||||||
SELECT
|
SELECT
|
||||||
count(*)
|
count(*)
|
||||||
|
@ -2150,7 +2150,7 @@ FROM
|
||||||
events_table.value_2 IN (1, 5)
|
events_table.value_2 IN (1, 5)
|
||||||
) as bar
|
) as bar
|
||||||
WHERE foo.event_type = bar.event_type;
|
WHERE foo.event_type = bar.event_type;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- DISTINCT in the outer query and DISTINCT in the subquery
|
-- DISTINCT in the outer query and DISTINCT in the subquery
|
||||||
SELECT
|
SELECT
|
||||||
DISTINCT users_ids.user_id
|
DISTINCT users_ids.user_id
|
||||||
|
|
|
@ -1616,7 +1616,7 @@ FROM
|
||||||
ORDER BY
|
ORDER BY
|
||||||
user_id DESC, lastseen DESC
|
user_id DESC, lastseen DESC
|
||||||
LIMIT 10;
|
LIMIT 10;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- not pushdownable since lower LATERAL JOIN is not on the partition key
|
-- not pushdownable since lower LATERAL JOIN is not on the partition key
|
||||||
-- not recursively plannable due to LATERAL join where there is a reference
|
-- not recursively plannable due to LATERAL join where there is a reference
|
||||||
-- from an outer query
|
-- from an outer query
|
||||||
|
|
|
@ -1420,7 +1420,7 @@ WHERE
|
||||||
GROUP BY 1
|
GROUP BY 1
|
||||||
ORDER BY 2 DESC, 1 DESC
|
ORDER BY 2 DESC, 1 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 co-located and joined on their distribution columns
|
||||||
SELECT foo.user_id FROM
|
SELECT foo.user_id FROM
|
||||||
(
|
(
|
||||||
SELECT m.user_id, random() FROM users_table m JOIN events_reference_table r ON int4eq(m.user_id, r.user_id)
|
SELECT m.user_id, random() FROM users_table m JOIN events_reference_table r ON int4eq(m.user_id, r.user_id)
|
||||||
|
|
|
@ -80,7 +80,7 @@ GROUP BY user_id
|
||||||
HAVING count(*) > 1
|
HAVING count(*) > 1
|
||||||
ORDER BY user_id
|
ORDER BY user_id
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- subqueries in where with ALL operator
|
-- subqueries in where with ALL operator
|
||||||
SELECT
|
SELECT
|
||||||
user_id
|
user_id
|
||||||
|
@ -465,7 +465,7 @@ SELECT user_id, value_2 FROM users_table WHERE
|
||||||
group by e1.user_id
|
group by e1.user_id
|
||||||
HAVING sum(submit_card_info) > 0
|
HAVING sum(submit_card_info) > 0
|
||||||
);
|
);
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- left leaf query does not return partition key
|
-- left leaf query does not return partition key
|
||||||
SELECT
|
SELECT
|
||||||
user_id
|
user_id
|
||||||
|
@ -561,7 +561,7 @@ FROM (
|
||||||
GROUP BY user_id
|
GROUP BY user_id
|
||||||
) q
|
) q
|
||||||
ORDER BY 2 DESC, 1;
|
ORDER BY 2 DESC, 1;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- subquery in where clause doesn't have a relation, but is constant
|
-- subquery in where clause doesn't have a relation, but is constant
|
||||||
SELECT
|
SELECT
|
||||||
user_id
|
user_id
|
||||||
|
@ -675,5 +675,5 @@ SELECT user_id, value_2 FROM users_table WHERE
|
||||||
AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type=1 AND value_3 > 1 AND test_join_function(events_table.user_id, users_table.user_id))
|
AND NOT EXISTS (SELECT user_id FROM events_table WHERE event_type=1 AND value_3 > 1 AND test_join_function(events_table.user_id, users_table.user_id))
|
||||||
ORDER BY 1 DESC, 2 DESC
|
ORDER BY 1 DESC, 2 DESC
|
||||||
LIMIT 3;
|
LIMIT 3;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
DROP FUNCTION test_join_function(int,int);
|
DROP FUNCTION test_join_function(int,int);
|
||||||
|
|
|
@ -629,7 +629,7 @@ SELECT true AS valid FROM explain_json_2($$
|
||||||
$$);
|
$$);
|
||||||
DEBUG: generating subplan 66_1 for subquery SELECT value_1, random() AS random FROM public.users_table
|
DEBUG: generating subplan 66_1 for subquery SELECT value_1, random() AS random FROM public.users_table
|
||||||
DEBUG: Plan 66 query after replacing subqueries and CTEs: SELECT count(*) AS count FROM ((public.users_table u1 JOIN public.users_table u2 USING (value_1)) a(value_1, user_id, "time", value_2, value_3, value_4, user_id_1, time_1, value_2_1, value_3_1, value_4_1) JOIN (SELECT intermediate_result.value_1, intermediate_result.random FROM read_intermediate_result('66_1'::text, 'binary'::citus_copy_format) intermediate_result(value_1 integer, random double precision)) u3 USING (value_1))
|
DEBUG: Plan 66 query after replacing subqueries and CTEs: SELECT count(*) AS count FROM ((public.users_table u1 JOIN public.users_table u2 USING (value_1)) a(value_1, user_id, "time", value_2, value_3, value_4, user_id_1, time_1, value_2_1, value_3_1, value_4_1) JOIN (SELECT intermediate_result.value_1, intermediate_result.random FROM read_intermediate_result('66_1'::text, 'binary'::citus_copy_format) intermediate_result(value_1 integer, random double precision)) u3 USING (value_1))
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- a very similar query to the above
|
-- a very similar query to the above
|
||||||
-- however, this time we users a subquery instead of join alias, and it works
|
-- however, this time we users a subquery instead of join alias, and it works
|
||||||
SELECT true AS valid FROM explain_json_2($$
|
SELECT true AS valid FROM explain_json_2($$
|
||||||
|
@ -926,7 +926,7 @@ DEBUG: Router planner cannot handle multi-shard select 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
|
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- similar to the above, make sure that we skip recursive planning when
|
-- similar to the above, make sure that we skip recursive planning when
|
||||||
-- the subquery doesn't have any tables
|
-- the subquery doesn't have any tables
|
||||||
SELECT true AS valid FROM explain_json_2($$
|
SELECT true AS valid FROM explain_json_2($$
|
||||||
|
@ -945,7 +945,7 @@ DEBUG: Router planner cannot handle multi-shard select 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
|
DEBUG: skipping recursive planning for the subquery since it contains references to outer queries
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- similar to the above, make sure that we skip recursive planning when
|
-- similar to the above, make sure that we skip recursive planning when
|
||||||
-- the subquery contains only intermediate results
|
-- the subquery contains only intermediate results
|
||||||
SELECT *
|
SELECT *
|
||||||
|
@ -1061,14 +1061,14 @@ SELECT create_distributed_table('table1','tenant_id');
|
||||||
-- all of the above queries are non-colocated subquery joins
|
-- all of the above queries are non-colocated subquery joins
|
||||||
-- because the views are replaced with subqueries
|
-- because the views are replaced with subqueries
|
||||||
UPDATE table2 SET id=20 FROM table1_view WHERE table1_view.id=table2.id;
|
UPDATE table2 SET id=20 FROM table1_view WHERE table1_view.id=table2.id;
|
||||||
DEBUG: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator
|
DEBUG: complex joins are only supported when all distributed tables are co-located and joined on their distribution columns
|
||||||
DEBUG: Router planner cannot handle multi-shard select queries
|
DEBUG: Router planner cannot handle multi-shard select queries
|
||||||
DEBUG: generating subplan 117_1 for subquery SELECT table1.id, table1.tenant_id FROM non_colocated_subquery.table1 WHERE (table1.id OPERATOR(pg_catalog.<) 100)
|
DEBUG: generating subplan 117_1 for subquery SELECT table1.id, table1.tenant_id FROM non_colocated_subquery.table1 WHERE (table1.id OPERATOR(pg_catalog.<) 100)
|
||||||
DEBUG: Plan 117 query after replacing subqueries and CTEs: UPDATE non_colocated_subquery.table2 SET id = 20 FROM (SELECT intermediate_result.id, intermediate_result.tenant_id FROM read_intermediate_result('117_1'::text, 'binary'::citus_copy_format) intermediate_result(id integer, tenant_id integer)) table1_view WHERE (table1_view.id OPERATOR(pg_catalog.=) table2.id)
|
DEBUG: Plan 117 query after replacing subqueries and CTEs: UPDATE non_colocated_subquery.table2 SET id = 20 FROM (SELECT intermediate_result.id, intermediate_result.tenant_id FROM read_intermediate_result('117_1'::text, 'binary'::citus_copy_format) intermediate_result(id integer, tenant_id integer)) table1_view WHERE (table1_view.id OPERATOR(pg_catalog.=) table2.id)
|
||||||
DEBUG: Creating router plan
|
DEBUG: Creating router plan
|
||||||
DEBUG: Plan is router executable
|
DEBUG: Plan is router executable
|
||||||
UPDATE table2_p1 SET id=20 FROM table1_view WHERE table1_view.id=table2_p1.id;
|
UPDATE table2_p1 SET id=20 FROM table1_view WHERE table1_view.id=table2_p1.id;
|
||||||
DEBUG: complex joins are only supported when all distributed tables are joined on their distribution columns with equal operator
|
DEBUG: complex joins are only supported when all distributed tables are co-located and joined on their distribution columns
|
||||||
DEBUG: Router planner cannot handle multi-shard select queries
|
DEBUG: Router planner cannot handle multi-shard select queries
|
||||||
DEBUG: generating subplan 119_1 for subquery SELECT table1.id, table1.tenant_id FROM non_colocated_subquery.table1 WHERE (table1.id OPERATOR(pg_catalog.<) 100)
|
DEBUG: generating subplan 119_1 for subquery SELECT table1.id, table1.tenant_id FROM non_colocated_subquery.table1 WHERE (table1.id OPERATOR(pg_catalog.<) 100)
|
||||||
DEBUG: Plan 119 query after replacing subqueries and CTEs: UPDATE non_colocated_subquery.table2_p1 SET id = 20 FROM (SELECT intermediate_result.id, intermediate_result.tenant_id FROM read_intermediate_result('119_1'::text, 'binary'::citus_copy_format) intermediate_result(id integer, tenant_id integer)) table1_view WHERE (table1_view.id OPERATOR(pg_catalog.=) table2_p1.id)
|
DEBUG: Plan 119 query after replacing subqueries and CTEs: UPDATE non_colocated_subquery.table2_p1 SET id = 20 FROM (SELECT intermediate_result.id, intermediate_result.tenant_id FROM read_intermediate_result('119_1'::text, 'binary'::citus_copy_format) intermediate_result(id integer, tenant_id integer)) table1_view WHERE (table1_view.id OPERATOR(pg_catalog.=) table2_p1.id)
|
||||||
|
|
|
@ -14,6 +14,13 @@ SELECT create_reference_table('ref');
|
||||||
|
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
CREATE TABLE test_not_colocated (LIKE test);
|
||||||
|
SELECT create_distributed_table('test_not_colocated', 'x', colocate_with := 'none');
|
||||||
|
create_distributed_table
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
(1 row)
|
||||||
|
|
||||||
INSERT INTO test VALUES (1,1), (2,2);
|
INSERT INTO test VALUES (1,1), (2,2);
|
||||||
INSERT INTO ref VALUES (2,2), (3,3);
|
INSERT INTO ref VALUES (2,2), (3,3);
|
||||||
-- top-level set operations are supported through recursive planning
|
-- top-level set operations are supported through recursive planning
|
||||||
|
@ -1045,11 +1052,49 @@ DEBUG: Plan is router executable
|
||||||
---
|
---
|
||||||
(0 rows)
|
(0 rows)
|
||||||
|
|
||||||
|
-- queries on non-colocated tables that would push down if they were not colocated are recursivelu planned
|
||||||
|
SELECT * FROM (SELECT * FROM test UNION SELECT * FROM test_not_colocated) u ORDER BY 1,2;
|
||||||
|
DEBUG: Router planner cannot handle multi-shard select queries
|
||||||
|
DEBUG: Router planner cannot handle multi-shard select queries
|
||||||
|
DEBUG: generating subplan 188_1 for subquery SELECT x, y FROM recursive_union.test
|
||||||
|
DEBUG: Router planner cannot handle multi-shard select queries
|
||||||
|
DEBUG: generating subplan 188_2 for subquery SELECT x, y FROM recursive_union.test_not_colocated
|
||||||
|
DEBUG: Creating router plan
|
||||||
|
DEBUG: Plan is router executable
|
||||||
|
DEBUG: generating subplan 188_3 for subquery SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('188_1'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer) UNION SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('188_2'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)
|
||||||
|
DEBUG: Plan 188 query after replacing subqueries and CTEs: SELECT x, y FROM (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('188_3'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) u ORDER BY x, y
|
||||||
|
DEBUG: Creating router plan
|
||||||
|
DEBUG: Plan is router executable
|
||||||
|
x | y
|
||||||
|
---+---
|
||||||
|
1 | 1
|
||||||
|
2 | 2
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
|
SELECT * FROM (SELECT * FROM test UNION ALL SELECT * FROM test_not_colocated) u ORDER BY 1,2;
|
||||||
|
DEBUG: Router planner cannot handle multi-shard select queries
|
||||||
|
DEBUG: Router planner cannot handle multi-shard select queries
|
||||||
|
DEBUG: generating subplan 192_1 for subquery SELECT x, y FROM recursive_union.test
|
||||||
|
DEBUG: Router planner cannot handle multi-shard select queries
|
||||||
|
DEBUG: generating subplan 192_2 for subquery SELECT x, y FROM recursive_union.test_not_colocated
|
||||||
|
DEBUG: Creating router plan
|
||||||
|
DEBUG: Plan is router executable
|
||||||
|
DEBUG: generating subplan 192_3 for subquery SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('192_1'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer) UNION ALL SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('192_2'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)
|
||||||
|
DEBUG: Plan 192 query after replacing subqueries and CTEs: SELECT x, y FROM (SELECT intermediate_result.x, intermediate_result.y FROM read_intermediate_result('192_3'::text, 'binary'::citus_copy_format) intermediate_result(x integer, y integer)) u ORDER BY x, y
|
||||||
|
DEBUG: Creating router plan
|
||||||
|
DEBUG: Plan is router executable
|
||||||
|
x | y
|
||||||
|
---+---
|
||||||
|
1 | 1
|
||||||
|
2 | 2
|
||||||
|
(2 rows)
|
||||||
|
|
||||||
RESET client_min_messages;
|
RESET client_min_messages;
|
||||||
DROP SCHEMA recursive_union CASCADE;
|
DROP SCHEMA recursive_union CASCADE;
|
||||||
NOTICE: drop cascades to 5 other objects
|
NOTICE: drop cascades to 6 other objects
|
||||||
DETAIL: drop cascades to table test
|
DETAIL: drop cascades to table test
|
||||||
drop cascades to table ref
|
drop cascades to table ref
|
||||||
|
drop cascades to table test_not_colocated
|
||||||
drop cascades to view set_view_recursive
|
drop cascades to view set_view_recursive
|
||||||
drop cascades to view set_view_pushdown
|
drop cascades to view set_view_pushdown
|
||||||
drop cascades to view set_view_recursive_second
|
drop cascades to view set_view_recursive_second
|
||||||
|
|
|
@ -272,7 +272,7 @@ SELECT
|
||||||
count(*)
|
count(*)
|
||||||
FROM
|
FROM
|
||||||
multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_nationkey = r_nationkey);
|
multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_nationkey = r_nationkey);
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- Anti-join should return customers for which there is no row in the right table
|
-- Anti-join should return customers for which there is no row in the right table
|
||||||
SELECT
|
SELECT
|
||||||
min(l_custkey), max(l_custkey)
|
min(l_custkey), max(l_custkey)
|
||||||
|
|
|
@ -252,7 +252,7 @@ SELECT
|
||||||
count(*)
|
count(*)
|
||||||
FROM
|
FROM
|
||||||
multi_outer_join_left_hash a LEFT JOIN multi_outer_join_right_hash b ON (l_nationkey = r_nationkey);
|
multi_outer_join_left_hash a LEFT JOIN multi_outer_join_right_hash b ON (l_nationkey = r_nationkey);
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- Anti-join should return customers for which there is no row in the right table
|
-- Anti-join should return customers for which there is no row in the right table
|
||||||
SELECT
|
SELECT
|
||||||
min(l_custkey), max(l_custkey)
|
min(l_custkey), max(l_custkey)
|
||||||
|
@ -326,7 +326,7 @@ FROM
|
||||||
LEFT JOIN multi_outer_join_right_reference r1 ON (l1.l_custkey = r1.r_custkey)
|
LEFT JOIN multi_outer_join_right_reference r1 ON (l1.l_custkey = r1.r_custkey)
|
||||||
LEFT JOIN multi_outer_join_right_reference r2 ON (l1.l_custkey = r2.r_custkey)
|
LEFT JOIN multi_outer_join_right_reference r2 ON (l1.l_custkey = r2.r_custkey)
|
||||||
RIGHT JOIN multi_outer_join_left_hash l2 ON (r2.r_custkey = l2.l_custkey);
|
RIGHT JOIN multi_outer_join_left_hash l2 ON (r2.r_custkey = l2.l_custkey);
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- add an anti-join, this should also error out
|
-- add an anti-join, this should also error out
|
||||||
SELECT
|
SELECT
|
||||||
*
|
*
|
||||||
|
@ -337,7 +337,7 @@ FROM
|
||||||
RIGHT JOIN multi_outer_join_left_hash l2 ON (r2.r_custkey = l2.l_custkey)
|
RIGHT JOIN multi_outer_join_left_hash l2 ON (r2.r_custkey = l2.l_custkey)
|
||||||
WHERE
|
WHERE
|
||||||
r1.r_custkey is NULL;
|
r1.r_custkey is NULL;
|
||||||
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 co-located and joined on their distribution columns
|
||||||
-- Three way join 2-1-1 (broadcast + broadcast join) should work
|
-- Three way join 2-1-1 (broadcast + broadcast join) should work
|
||||||
SELECT
|
SELECT
|
||||||
l_custkey, r_custkey, t_custkey
|
l_custkey, r_custkey, t_custkey
|
||||||
|
|
|
@ -7,6 +7,9 @@ SELECT create_distributed_table('test', 'x');
|
||||||
CREATE TABLE recursive_union.ref (a int, b int);
|
CREATE TABLE recursive_union.ref (a int, b int);
|
||||||
SELECT create_reference_table('ref');
|
SELECT create_reference_table('ref');
|
||||||
|
|
||||||
|
CREATE TABLE test_not_colocated (LIKE test);
|
||||||
|
SELECT create_distributed_table('test_not_colocated', 'x', colocate_with := 'none');
|
||||||
|
|
||||||
INSERT INTO test VALUES (1,1), (2,2);
|
INSERT INTO test VALUES (1,1), (2,2);
|
||||||
INSERT INTO ref VALUES (2,2), (3,3);
|
INSERT INTO ref VALUES (2,2), (3,3);
|
||||||
|
|
||||||
|
@ -169,5 +172,9 @@ SELECT * FROM set_view_recursive_second ORDER BY 1,2;
|
||||||
-- this should create lots of recursive calls since both views and set operations lead to recursive plans :)
|
-- this should create lots of recursive calls since both views and set operations lead to recursive plans :)
|
||||||
((SELECT x FROM set_view_recursive_second) INTERSECT (SELECT * FROM set_view_recursive)) EXCEPT (SELECT * FROM set_view_pushdown);
|
((SELECT x FROM set_view_recursive_second) INTERSECT (SELECT * FROM set_view_recursive)) EXCEPT (SELECT * FROM set_view_pushdown);
|
||||||
|
|
||||||
|
-- queries on non-colocated tables that would push down if they were not colocated are recursivelu planned
|
||||||
|
SELECT * FROM (SELECT * FROM test UNION SELECT * FROM test_not_colocated) u ORDER BY 1,2;
|
||||||
|
SELECT * FROM (SELECT * FROM test UNION ALL SELECT * FROM test_not_colocated) u ORDER BY 1,2;
|
||||||
|
|
||||||
RESET client_min_messages;
|
RESET client_min_messages;
|
||||||
DROP SCHEMA recursive_union CASCADE;
|
DROP SCHEMA recursive_union CASCADE;
|
||||||
|
|
Loading…
Reference in New Issue