Never allow co-located joins of append-distributed tables

pull/5359/head
Marco Slot 2021-10-15 17:46:09 +02:00
parent b97e5081c7
commit 93e79b9262
8 changed files with 341 additions and 240 deletions

View File

@ -234,6 +234,12 @@ TargetListOnPartitionColumn(Query *query, List *targetEntryList)
continue; continue;
} }
/* append-distributed tables do not have a strict partition column */
if (IsCitusTableType(relationId, APPEND_DISTRIBUTED))
{
continue;
}
if (isPartitionColumn) if (isPartitionColumn)
{ {
FieldSelect *compositeField = CompositeFieldRecursive(targetExpression, FieldSelect *compositeField = CompositeFieldRecursive(targetExpression,

View File

@ -2445,16 +2445,6 @@ ErrorIfUnsupportedShardDistribution(Query *query)
} }
else else
{ {
CitusTableCacheEntry *distTableEntry = GetCitusTableCacheEntry(relationId);
if (distTableEntry->hasOverlappingShardInterval)
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot push down this subquery"),
errdetail("Currently append partitioned relations "
"with overlapping shard intervals are "
"not supported")));
}
appendDistributedRelationCount++; appendDistributedRelationCount++;
} }
} }
@ -2647,14 +2637,19 @@ QueryPushdownTaskCreate(Query *originalQuery, int shardIndex,
bool bool
CoPartitionedTables(Oid firstRelationId, Oid secondRelationId) CoPartitionedTables(Oid firstRelationId, Oid secondRelationId)
{ {
if (firstRelationId == secondRelationId)
{
return true;
}
CitusTableCacheEntry *firstTableCache = GetCitusTableCacheEntry(firstRelationId); CitusTableCacheEntry *firstTableCache = GetCitusTableCacheEntry(firstRelationId);
CitusTableCacheEntry *secondTableCache = GetCitusTableCacheEntry(secondRelationId); CitusTableCacheEntry *secondTableCache = GetCitusTableCacheEntry(secondRelationId);
if (firstTableCache->partitionMethod == DISTRIBUTE_BY_APPEND ||
secondTableCache->partitionMethod == DISTRIBUTE_BY_APPEND)
{
/*
* Append-distributed tables can have overlapping shards. Therefore they are
* never co-partitioned, not even with themselves.
*/
return false;
}
/* /*
* Check if the tables have the same colocation ID - if so, we know * Check if the tables have the same colocation ID - if so, we know
* they're colocated. * they're colocated.
@ -2665,6 +2660,15 @@ CoPartitionedTables(Oid firstRelationId, Oid secondRelationId)
return true; return true;
} }
if (firstRelationId == secondRelationId)
{
/*
* Even without an explicit co-location ID, non-append tables can be considered
* co-located with themselves.
*/
return true;
}
return false; return false;
} }

View File

@ -85,6 +85,7 @@ typedef struct AttributeEquivalenceClassMember
static bool ContextContainsLocalRelation(RelationRestrictionContext *restrictionContext); static bool ContextContainsLocalRelation(RelationRestrictionContext *restrictionContext);
static bool ContextContainsAppendRelation(RelationRestrictionContext *restrictionContext);
static int RangeTableOffsetCompat(PlannerInfo *root, AppendRelInfo *appendRelInfo); static int RangeTableOffsetCompat(PlannerInfo *root, AppendRelInfo *appendRelInfo);
static Var * FindUnionAllVar(PlannerInfo *root, List *translatedVars, Oid relationOid, static Var * FindUnionAllVar(PlannerInfo *root, List *translatedVars, Oid relationOid,
Index relationRteIndex, Index *partitionKeyIndex); Index relationRteIndex, Index *partitionKeyIndex);
@ -236,6 +237,29 @@ ContextContainsLocalRelation(RelationRestrictionContext *restrictionContext)
} }
/*
* ContextContainsAppendRelation determines whether the given
* RelationRestrictionContext contains any append-distributed tables.
*/
static bool
ContextContainsAppendRelation(RelationRestrictionContext *restrictionContext)
{
ListCell *relationRestrictionCell = NULL;
foreach(relationRestrictionCell, restrictionContext->relationRestrictionList)
{
RelationRestriction *relationRestriction = lfirst(relationRestrictionCell);
if (IsCitusTableType(relationRestriction->relationId, APPEND_DISTRIBUTED))
{
return true;
}
}
return false;
}
/* /*
* SafeToPushdownUnionSubquery returns true if all the relations are returns * SafeToPushdownUnionSubquery returns true if all the relations are returns
* partition keys in the same ordinal position and there is no reference table * partition keys in the same ordinal position and there is no reference table
@ -504,6 +528,12 @@ RestrictionEquivalenceForPartitionKeys(PlannerRestrictionContext *restrictionCon
/* there is a single distributed relation, no need to continue */ /* there is a single distributed relation, no need to continue */
return true; return true;
} }
else if (ContextContainsAppendRelation(
restrictionContext->relationRestrictionContext))
{
/* we never consider append-distributed tables co-located */
return false;
}
List *attributeEquivalenceList = GenerateAllAttributeEquivalences(restrictionContext); List *attributeEquivalenceList = GenerateAllAttributeEquivalences(restrictionContext);
@ -1906,6 +1936,17 @@ AllRelationsInRestrictionContextColocated(RelationRestrictionContext *restrictio
continue; continue;
} }
if (IsCitusTableType(relationId, APPEND_DISTRIBUTED))
{
/*
* If we got to this point, it means there are multiple distributed
* relations and at least one of them is append-distributed. Since
* we do not consider append-distributed tables to be co-located,
* we can immediately return false.
*/
return false;
}
int colocationId = TableColocationId(relationId); int colocationId = TableColocationId(relationId);
if (initialColocationId == INVALID_COLOCATION_ID) if (initialColocationId == INVALID_COLOCATION_ID)

View File

@ -101,7 +101,7 @@ EXPLAIN (COSTS OFF)
SELECT count(*) SELECT count(*)
FROM array_partitioned_table table1, array_partitioned_table table2 FROM array_partitioned_table table1, array_partitioned_table table2
WHERE table1.array_column = table2.array_column; WHERE table1.array_column = table2.array_column;
DEBUG: Router planner does not support append-partitioned tables. DEBUG: Router planner cannot handle multi-shard select queries
DEBUG: join prunable for intervals [{},{AZZXSP27F21T6,AZZXSP27F21T6}] and [{BA1000U2AMO4ZGX,BZZXSP27F21T6},{CA1000U2AMO4ZGX,CZZXSP27F21T6}] DEBUG: join prunable for intervals [{},{AZZXSP27F21T6,AZZXSP27F21T6}] and [{BA1000U2AMO4ZGX,BZZXSP27F21T6},{CA1000U2AMO4ZGX,CZZXSP27F21T6}]
DEBUG: join prunable for intervals [{BA1000U2AMO4ZGX,BZZXSP27F21T6},{CA1000U2AMO4ZGX,CZZXSP27F21T6}] and [{},{AZZXSP27F21T6,AZZXSP27F21T6}] DEBUG: join prunable for intervals [{BA1000U2AMO4ZGX,BZZXSP27F21T6},{CA1000U2AMO4ZGX,CZZXSP27F21T6}] and [{},{AZZXSP27F21T6,AZZXSP27F21T6}]
QUERY PLAN QUERY PLAN
@ -115,7 +115,7 @@ EXPLAIN (COSTS OFF)
SELECT count(*) SELECT count(*)
FROM composite_partitioned_table table1, composite_partitioned_table table2 FROM composite_partitioned_table table1, composite_partitioned_table table2
WHERE table1.composite_column = table2.composite_column; WHERE table1.composite_column = table2.composite_column;
DEBUG: Router planner does not support append-partitioned tables. DEBUG: Router planner cannot handle multi-shard select queries
DEBUG: join prunable for intervals [(a,3,b),(b,4,c)] and [(c,5,d),(d,6,e)] DEBUG: join prunable for intervals [(a,3,b),(b,4,c)] and [(c,5,d),(d,6,e)]
DEBUG: join prunable for intervals [(c,5,d),(d,6,e)] and [(a,3,b),(b,4,c)] DEBUG: join prunable for intervals [(c,5,d),(d,6,e)] and [(a,3,b),(b,4,c)]
QUERY PLAN QUERY PLAN
@ -130,7 +130,7 @@ EXPLAIN (COSTS OFF)
SELECT count(*) SELECT count(*)
FROM varchar_partitioned_table table1, varchar_partitioned_table table2 FROM varchar_partitioned_table table1, varchar_partitioned_table table2
WHERE table1.varchar_column = table2.varchar_column; WHERE table1.varchar_column = table2.varchar_column;
DEBUG: Router planner does not support append-partitioned tables. DEBUG: Router planner cannot handle multi-shard select queries
DEBUG: join prunable for intervals [AA1000U2AMO4ZGX,AZZXSP27F21T6] and [BA1000U2AMO4ZGX,BZZXSP27F21T6] DEBUG: join prunable for intervals [AA1000U2AMO4ZGX,AZZXSP27F21T6] and [BA1000U2AMO4ZGX,BZZXSP27F21T6]
DEBUG: join prunable for intervals [BA1000U2AMO4ZGX,BZZXSP27F21T6] and [AA1000U2AMO4ZGX,AZZXSP27F21T6] DEBUG: join prunable for intervals [BA1000U2AMO4ZGX,BZZXSP27F21T6] and [AA1000U2AMO4ZGX,AZZXSP27F21T6]
QUERY PLAN QUERY PLAN

View File

@ -57,7 +57,7 @@ CREATE TABLE varchar_partitioned_table
( (
varchar_column varchar(100) varchar_column varchar(100)
); );
SELECT create_distributed_table('varchar_partitioned_table', 'varchar_column', 'append'); SELECT create_distributed_table('varchar_partitioned_table', 'varchar_column', 'range');
create_distributed_table create_distributed_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -85,7 +85,7 @@ CREATE TABLE array_partitioned_table
( (
array_column text[] array_column text[]
); );
SELECT create_distributed_table('array_partitioned_table', 'array_column', 'append'); SELECT create_distributed_table('array_partitioned_table', 'array_column', 'range');
create_distributed_table create_distributed_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -121,7 +121,7 @@ CREATE TABLE composite_partitioned_table
( (
composite_column composite_type composite_column composite_type
); );
SELECT create_distributed_table('composite_partitioned_table', 'composite_column', 'append'); SELECT create_distributed_table('composite_partitioned_table', 'composite_column', 'range');
create_distributed_table create_distributed_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -150,40 +150,37 @@ INSERT INTO pg_dist_shard_placement (shardid, shardstate, shardlength, nodename,
SET client_min_messages TO ERROR; SET client_min_messages TO ERROR;
EXPLAIN (COSTS OFF) EXPLAIN (COSTS OFF)
SELECT count(*) FROM varchar_partitioned_table WHERE varchar_column = 'BA2'; SELECT count(*) FROM varchar_partitioned_table WHERE varchar_column = 'BA2';
QUERY PLAN QUERY PLAN
--------------------------------------------------------------------- ---------------------------------------------------------------------
Aggregate Custom Scan (Citus Adaptive)
-> Custom Scan (Citus Adaptive) Task Count: 1
Task Count: 1 Tasks Shown: All
Tasks Shown: All -> Task
-> Task Error: Could not get remote plan.
Error: Could not get remote plan. (5 rows)
(6 rows)
EXPLAIN (COSTS OFF) EXPLAIN (COSTS OFF)
SELECT count(*) FROM array_partitioned_table SELECT count(*) FROM array_partitioned_table
WHERE array_column > '{BA1000U2AMO4ZGX, BZZXSP27F21T6}'; WHERE array_column > '{BA1000U2AMO4ZGX, BZZXSP27F21T6}';
QUERY PLAN QUERY PLAN
--------------------------------------------------------------------- ---------------------------------------------------------------------
Aggregate Custom Scan (Citus Adaptive)
-> Custom Scan (Citus Adaptive) Task Count: 1
Task Count: 1 Tasks Shown: All
Tasks Shown: All -> Task
-> Task Error: Could not get remote plan.
Error: Could not get remote plan. (5 rows)
(6 rows)
EXPLAIN (COSTS OFF) EXPLAIN (COSTS OFF)
SELECT count(*) FROM composite_partitioned_table SELECT count(*) FROM composite_partitioned_table
WHERE composite_column < '(b,5,c)'::composite_type; WHERE composite_column < '(b,5,c)'::composite_type;
QUERY PLAN QUERY PLAN
--------------------------------------------------------------------- ---------------------------------------------------------------------
Aggregate Custom Scan (Citus Adaptive)
-> Custom Scan (Citus Adaptive) Task Count: 1
Task Count: 1 Tasks Shown: All
Tasks Shown: All -> Task
-> Task Error: Could not get remote plan.
Error: Could not get remote plan. (5 rows)
(6 rows)
SET client_min_messages TO NOTICE; SET client_min_messages TO NOTICE;

View File

@ -16,7 +16,7 @@ CREATE TABLE multi_outer_join_left
l_mktsegment char(10) not null, l_mktsegment char(10) not null,
l_comment varchar(117) not null l_comment varchar(117) not null
); );
SELECT master_create_distributed_table('multi_outer_join_left', 'l_custkey', 'append'); SELECT create_distributed_table('multi_outer_join_left', 'l_custkey', 'hash');
CREATE TABLE multi_outer_join_right CREATE TABLE multi_outer_join_right
( (
@ -29,7 +29,7 @@ CREATE TABLE multi_outer_join_right
r_mktsegment char(10) not null, r_mktsegment char(10) not null,
r_comment varchar(117) not null r_comment varchar(117) not null
); );
SELECT master_create_distributed_table('multi_outer_join_right', 'r_custkey', 'append'); SELECT create_distributed_table('multi_outer_join_right', 'r_custkey', 'hash');
CREATE TABLE multi_outer_join_right_reference CREATE TABLE multi_outer_join_right_reference
( (
@ -55,7 +55,7 @@ CREATE TABLE multi_outer_join_third
t_mktsegment char(10) not null, t_mktsegment char(10) not null,
t_comment varchar(117) not null t_comment varchar(117) not null
); );
SELECT master_create_distributed_table('multi_outer_join_third', 't_custkey', 'append'); SELECT create_distributed_table('multi_outer_join_third', 't_custkey', 'hash');
CREATE TABLE multi_outer_join_third_reference CREATE TABLE multi_outer_join_third_reference
( (
@ -70,18 +70,8 @@ CREATE TABLE multi_outer_join_third_reference
); );
SELECT create_reference_table('multi_outer_join_third_reference'); SELECT create_reference_table('multi_outer_join_third_reference');
-- Make sure we do not crash if both tables have no shards
SELECT
min(l_custkey), max(l_custkey)
FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_third b ON (l_custkey = t_custkey);
-- Left table is a large table
\copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-1-10.data' with delimiter '|' \copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-1-10.data' with delimiter '|'
\copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-11-20.data' with delimiter '|' \copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-11-20.data' with delimiter '|'
-- Right table is a small table
\copy multi_outer_join_right FROM '@abs_srcdir@/data/customer-1-15.data' with delimiter '|' \copy multi_outer_join_right FROM '@abs_srcdir@/data/customer-1-15.data' with delimiter '|'
\copy multi_outer_join_right_reference FROM '@abs_srcdir@/data/customer-1-15.data' with delimiter '|' \copy multi_outer_join_right_reference FROM '@abs_srcdir@/data/customer-1-15.data' with delimiter '|'
@ -187,8 +177,8 @@ FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_custkey = r_custkey); multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_custkey = r_custkey);
-- empty tables -- empty tables
SELECT * FROM master_apply_delete_command('DELETE FROM multi_outer_join_left'); TRUNCATE multi_outer_join_left;
SELECT * FROM master_apply_delete_command('DELETE FROM multi_outer_join_right'); TRUNCATE multi_outer_join_right;
-- reload shards with 1-1 matching -- reload shards with 1-1 matching
\copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-subset-11-20.data' with delimiter '|' \copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-subset-11-20.data' with delimiter '|'
@ -482,7 +472,8 @@ FROM
(multi_outer_join_right r1 (multi_outer_join_right r1
LEFT OUTER JOIN multi_outer_join_left l1 ON (l1.l_custkey = r1.r_custkey)) AS LEFT OUTER JOIN multi_outer_join_left l1 ON (l1.l_custkey = r1.r_custkey)) AS
test(c_custkey, c_nationkey) test(c_custkey, c_nationkey)
INNER JOIN multi_outer_join_third t1 ON (test.c_custkey = t1.t_custkey); INNER JOIN multi_outer_join_third t1 ON (test.c_custkey = t1.t_custkey)
ORDER BY 1;
-- simple test to ensure anti-joins work with hash-partitioned tables -- simple test to ensure anti-joins work with hash-partitioned tables
CREATE TABLE left_values(val int); CREATE TABLE left_values(val int);

View File

@ -12,9 +12,9 @@ CREATE TABLE multi_outer_join_left
l_mktsegment char(10) not null, l_mktsegment char(10) not null,
l_comment varchar(117) not null l_comment varchar(117) not null
); );
SELECT master_create_distributed_table('multi_outer_join_left', 'l_custkey', 'append'); SELECT create_distributed_table('multi_outer_join_left', 'l_custkey', 'hash');
master_create_distributed_table create_distributed_table
--------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -29,9 +29,9 @@ CREATE TABLE multi_outer_join_right
r_mktsegment char(10) not null, r_mktsegment char(10) not null,
r_comment varchar(117) not null r_comment varchar(117) not null
); );
SELECT master_create_distributed_table('multi_outer_join_right', 'r_custkey', 'append'); SELECT create_distributed_table('multi_outer_join_right', 'r_custkey', 'hash');
master_create_distributed_table create_distributed_table
--------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -48,7 +48,7 @@ CREATE TABLE multi_outer_join_right_reference
); );
SELECT create_reference_table('multi_outer_join_right_reference'); SELECT create_reference_table('multi_outer_join_right_reference');
create_reference_table create_reference_table
------------------------ ---------------------------------------------------------------------
(1 row) (1 row)
@ -63,9 +63,9 @@ CREATE TABLE multi_outer_join_third
t_mktsegment char(10) not null, t_mktsegment char(10) not null,
t_comment varchar(117) not null t_comment varchar(117) not null
); );
SELECT master_create_distributed_table('multi_outer_join_third', 't_custkey', 'append'); SELECT create_distributed_table('multi_outer_join_third', 't_custkey', 'hash');
master_create_distributed_table create_distributed_table
--------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -82,24 +82,12 @@ CREATE TABLE multi_outer_join_third_reference
); );
SELECT create_reference_table('multi_outer_join_third_reference'); SELECT create_reference_table('multi_outer_join_third_reference');
create_reference_table create_reference_table
------------------------ ---------------------------------------------------------------------
(1 row) (1 row)
-- Make sure we do not crash if both tables have no shards
SELECT
min(l_custkey), max(l_custkey)
FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_third b ON (l_custkey = t_custkey);
min | max
-----+-----
|
(1 row)
-- Left table is a large table
\copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-1-10.data' with delimiter '|' \copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-1-10.data' with delimiter '|'
\copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-11-20.data' with delimiter '|' \copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-11-20.data' with delimiter '|'
-- Right table is a small table
\copy multi_outer_join_right FROM '@abs_srcdir@/data/customer-1-15.data' with delimiter '|' \copy multi_outer_join_right FROM '@abs_srcdir@/data/customer-1-15.data' with delimiter '|'
\copy multi_outer_join_right_reference FROM '@abs_srcdir@/data/customer-1-15.data' with delimiter '|' \copy multi_outer_join_right_reference FROM '@abs_srcdir@/data/customer-1-15.data' with delimiter '|'
-- Make sure we do not crash if one table has no shards -- Make sure we do not crash if one table has no shards
@ -107,13 +95,17 @@ SELECT
min(l_custkey), max(l_custkey) min(l_custkey), max(l_custkey)
FROM FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_third b ON (l_custkey = t_custkey); multi_outer_join_left a LEFT JOIN multi_outer_join_third b ON (l_custkey = t_custkey);
ERROR: shard counts of co-located tables do not match min | max
---------------------------------------------------------------------
1 | 20
(1 row)
SELECT SELECT
min(t_custkey), max(t_custkey) min(t_custkey), max(t_custkey)
FROM FROM
multi_outer_join_third a LEFT JOIN multi_outer_join_right_reference b ON (r_custkey = t_custkey); multi_outer_join_third a LEFT JOIN multi_outer_join_right_reference b ON (r_custkey = t_custkey);
min | max min | max
-----+----- ---------------------------------------------------------------------
| |
(1 row) (1 row)
@ -126,7 +118,7 @@ SELECT
FROM FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b ON (l_custkey = r_custkey); multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b ON (l_custkey = r_custkey);
min | max min | max
-----+----- ---------------------------------------------------------------------
1 | 20 1 | 20
(1 row) (1 row)
@ -136,7 +128,7 @@ SELECT
FROM FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b ON (l_nationkey = r_nationkey); multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b ON (l_nationkey = r_nationkey);
count count
------- ---------------------------------------------------------------------
28 28
(1 row) (1 row)
@ -148,7 +140,7 @@ FROM
WHERE WHERE
r_custkey IS NULL; r_custkey IS NULL;
min | max min | max
-----+----- ---------------------------------------------------------------------
16 | 20 16 | 20
(1 row) (1 row)
@ -160,7 +152,7 @@ FROM
WHERE WHERE
r_custkey IS NULL OR r_custkey = 5; r_custkey IS NULL OR r_custkey = 5;
min | max min | max
-----+----- ---------------------------------------------------------------------
5 | 20 5 | 20
(1 row) (1 row)
@ -173,7 +165,7 @@ FROM
WHERE WHERE
r_custkey = 5 or r_custkey > 15; r_custkey = 5 or r_custkey > 15;
min | max min | max
-----+----- ---------------------------------------------------------------------
5 | 5 5 | 5
(1 row) (1 row)
@ -184,7 +176,7 @@ FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b
ON (l_custkey = r_custkey AND r_custkey = 5); ON (l_custkey = r_custkey AND r_custkey = 5);
count | count count | count
-------+------- ---------------------------------------------------------------------
20 | 1 20 | 1
(1 row) (1 row)
@ -195,7 +187,7 @@ FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b
ON (l_custkey = r_custkey AND r_custkey = -1 /* nonexistant */); ON (l_custkey = r_custkey AND r_custkey = -1 /* nonexistant */);
count | count count | count
-------+------- ---------------------------------------------------------------------
20 | 0 20 | 0
(1 row) (1 row)
@ -206,7 +198,7 @@ FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b multi_outer_join_left a LEFT JOIN multi_outer_join_right_reference b
ON (l_custkey = r_custkey AND l_custkey = -1 /* nonexistant */); ON (l_custkey = r_custkey AND l_custkey = -1 /* nonexistant */);
count | count count | count
-------+------- ---------------------------------------------------------------------
20 | 0 20 | 0
(1 row) (1 row)
@ -215,14 +207,18 @@ SELECT
min(r_custkey), max(r_custkey) min(r_custkey), max(r_custkey)
FROM FROM
multi_outer_join_left a RIGHT JOIN multi_outer_join_right b ON (l_custkey = r_custkey); multi_outer_join_left a RIGHT JOIN multi_outer_join_right b ON (l_custkey = r_custkey);
ERROR: shard counts of co-located tables do not match min | max
---------------------------------------------------------------------
1 | 15
(1 row)
-- Reverse right join should be same as left join -- Reverse right join should be same as left join
SELECT SELECT
min(l_custkey), max(l_custkey) min(l_custkey), max(l_custkey)
FROM FROM
multi_outer_join_right_reference a RIGHT JOIN multi_outer_join_left b ON (l_custkey = r_custkey); multi_outer_join_right_reference a RIGHT JOIN multi_outer_join_left b ON (l_custkey = r_custkey);
min | max min | max
-----+----- ---------------------------------------------------------------------
1 | 20 1 | 20
(1 row) (1 row)
@ -234,23 +230,13 @@ SELECT
FROM FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_custkey = r_custkey); multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_custkey = r_custkey);
min | max min | max
-----+----- ---------------------------------------------------------------------
1 | 20 1 | 20
(1 row) (1 row)
-- empty tables -- empty tables
SELECT * FROM master_apply_delete_command('DELETE FROM multi_outer_join_left'); TRUNCATE multi_outer_join_left;
master_apply_delete_command TRUNCATE multi_outer_join_right;
-----------------------------
2
(1 row)
SELECT * FROM master_apply_delete_command('DELETE FROM multi_outer_join_right');
master_apply_delete_command
-----------------------------
2
(1 row)
-- reload shards with 1-1 matching -- reload shards with 1-1 matching
\copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-subset-11-20.data' with delimiter '|' \copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-subset-11-20.data' with delimiter '|'
\copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-21-30.data' with delimiter '|' \copy multi_outer_join_left FROM '@abs_srcdir@/data/customer-21-30.data' with delimiter '|'
@ -263,7 +249,7 @@ SELECT
FROM FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_custkey = r_custkey); multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_custkey = r_custkey);
min | max min | max
-----+----- ---------------------------------------------------------------------
11 | 30 11 | 30
(1 row) (1 row)
@ -281,7 +267,7 @@ FROM
WHERE WHERE
r_custkey IS NULL; r_custkey IS NULL;
min | max min | max
-----+----- ---------------------------------------------------------------------
23 | 29 23 | 29
(1 row) (1 row)
@ -293,7 +279,7 @@ FROM
WHERE WHERE
r_custkey IS NULL OR r_custkey = 15; r_custkey IS NULL OR r_custkey = 15;
min | max min | max
-----+----- ---------------------------------------------------------------------
23 | 29 23 | 29
(1 row) (1 row)
@ -306,7 +292,7 @@ FROM
WHERE WHERE
r_custkey = 21 or r_custkey < 10; r_custkey = 21 or r_custkey < 10;
min | max min | max
-----+----- ---------------------------------------------------------------------
21 | 21 21 | 21
(1 row) (1 row)
@ -317,7 +303,7 @@ FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right b multi_outer_join_left a LEFT JOIN multi_outer_join_right b
ON (l_custkey = r_custkey AND r_custkey = 21); ON (l_custkey = r_custkey AND r_custkey = 21);
count | count count | count
-------+------- ---------------------------------------------------------------------
17 | 1 17 | 1
(1 row) (1 row)
@ -327,7 +313,7 @@ SELECT
FROM FROM
multi_outer_join_left a RIGHT JOIN multi_outer_join_right b ON (l_custkey = r_custkey); multi_outer_join_left a RIGHT JOIN multi_outer_join_right b ON (l_custkey = r_custkey);
min | max min | max
-----+----- ---------------------------------------------------------------------
11 | 30 11 | 30
(1 row) (1 row)
@ -337,7 +323,7 @@ SELECT
FROM FROM
multi_outer_join_right a RIGHT JOIN multi_outer_join_left b ON (l_custkey = r_custkey); multi_outer_join_right a RIGHT JOIN multi_outer_join_left b ON (l_custkey = r_custkey);
min | max min | max
-----+----- ---------------------------------------------------------------------
11 | 30 11 | 30
(1 row) (1 row)
@ -352,7 +338,7 @@ FROM
ORDER BY 1 ORDER BY 1
LIMIT 1; LIMIT 1;
l_custkey l_custkey
----------- ---------------------------------------------------------------------
11 11
(1 row) (1 row)
@ -369,7 +355,7 @@ WHERE
ORDER BY 1 ORDER BY 1
LIMIT 1; LIMIT 1;
l_custkey l_custkey
----------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -382,7 +368,7 @@ FROM
LEFT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey) LEFT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey)
ORDER BY l_custkey, r_custkey, t_custkey; ORDER BY l_custkey, r_custkey, t_custkey;
l_custkey | r_custkey | t_custkey l_custkey | r_custkey | t_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
11 | 11 | 11 11 | 11 | 11
12 | 12 | 12 12 | 12 | 12
14 | 14 | 14 14 | 14 | 14
@ -421,7 +407,7 @@ FROM
LEFT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey) LEFT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey)
ORDER BY t_custkey, r_custkey, l_custkey; ORDER BY t_custkey, r_custkey, l_custkey;
t_custkey | r_custkey | l_custkey t_custkey | r_custkey | l_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
11 | 11 | 11 11 | 11 | 11
12 | 12 | 12 12 | 12 | 12
13 | 13 | 13 | 13 |
@ -452,7 +438,7 @@ WHERE
l_custkey is NULL l_custkey is NULL
ORDER BY t_custkey, r_custkey, l_custkey; ORDER BY t_custkey, r_custkey, l_custkey;
t_custkey | r_custkey | l_custkey t_custkey | r_custkey | l_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
13 | 13 | 13 | 13 |
15 | 15 | 15 | 15 |
19 | 19 | 19 | 19 |
@ -467,7 +453,7 @@ FROM
RIGHT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey) RIGHT JOIN multi_outer_join_left l1 ON (r1.r_custkey = l1.l_custkey)
ORDER BY 1,2,3; ORDER BY 1,2,3;
t_custkey | r_custkey | l_custkey t_custkey | r_custkey | l_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
11 | 11 | 11 11 | 11 | 11
12 | 12 | 12 12 | 12 | 12
14 | 14 | 14 14 | 14 | 14
@ -495,7 +481,7 @@ FROM
FULL JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey) FULL JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey)
ORDER BY 1 DESC, 2 DESC; ORDER BY 1 DESC, 2 DESC;
l_custkey | r_custkey l_custkey | r_custkey
-----------+----------- ---------------------------------------------------------------------
| 19 | 19
| 15 | 15
| 13 | 13
@ -528,7 +514,7 @@ WHERE
r_custkey is NULL r_custkey is NULL
ORDER BY 1 DESC, 2 DESC; ORDER BY 1 DESC, 2 DESC;
l_custkey | r_custkey l_custkey | r_custkey
-----------+----------- ---------------------------------------------------------------------
29 | 29 |
25 | 25 |
23 | 23 |
@ -544,7 +530,7 @@ WHERE
l_custkey is NULL l_custkey is NULL
ORDER BY 1 DESC, 2 DESC; ORDER BY 1 DESC, 2 DESC;
l_custkey | r_custkey l_custkey | r_custkey
-----------+----------- ---------------------------------------------------------------------
| 19 | 19
| 15 | 15
| 13 | 13
@ -560,7 +546,7 @@ WHERE
l_custkey is NULL or r_custkey is NULL l_custkey is NULL or r_custkey is NULL
ORDER BY 1 DESC, 2 DESC; ORDER BY 1 DESC, 2 DESC;
l_custkey | r_custkey l_custkey | r_custkey
-----------+----------- ---------------------------------------------------------------------
| 19 | 19
| 15 | 15
| 13 | 13
@ -576,7 +562,40 @@ FROM
multi_outer_join_left l1 multi_outer_join_left l1
FULL JOIN multi_outer_join_third t1 ON (l1.l_custkey = t1.t_custkey) FULL JOIN multi_outer_join_third t1 ON (l1.l_custkey = t1.t_custkey)
ORDER BY 1 DESC, 2 DESC; ORDER BY 1 DESC, 2 DESC;
ERROR: shard counts of co-located tables do not match l_custkey | t_custkey
---------------------------------------------------------------------
| 19
| 15
| 13
| 10
| 9
| 8
| 7
| 6
| 5
| 4
| 3
| 2
| 1
30 | 30
29 | 29
28 | 28
27 | 27
26 | 26
25 | 25
24 | 24
23 | 23
22 | 22
21 | 21
20 | 20
18 | 18
17 | 17
16 | 16
14 | 14
12 | 12
11 | 11
(30 rows)
-- inner join + single shard left join should work -- inner join + single shard left join should work
SELECT SELECT
l_custkey, r_custkey, t_custkey l_custkey, r_custkey, t_custkey
@ -586,7 +605,7 @@ FROM
LEFT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey) LEFT JOIN multi_outer_join_third_reference t1 ON (r1.r_custkey = t1.t_custkey)
ORDER BY 1 DESC, 2 DESC, 3 DESC; ORDER BY 1 DESC, 2 DESC, 3 DESC;
l_custkey | r_custkey | t_custkey l_custkey | r_custkey | t_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
30 | 30 | 30 30 | 30 | 30
28 | 28 | 28 28 | 28 | 28
27 | 27 | 27 27 | 27 | 27
@ -612,7 +631,7 @@ FROM
LEFT JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey) LEFT JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey)
ORDER BY 1 DESC, 2 DESC, 3 DESC; ORDER BY 1 DESC, 2 DESC, 3 DESC;
l_custkey | t_custkey | r_custkey l_custkey | t_custkey | r_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
30 | 30 | 30 30 | 30 | 30
29 | 29 | 29 | 29 |
28 | 28 | 28 28 | 28 | 28
@ -642,7 +661,7 @@ FROM
ORDER BY ORDER BY
t_custkey, l_custkey, r_custkey; t_custkey, l_custkey, r_custkey;
t_custkey | l_custkey | r_custkey t_custkey | l_custkey | r_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
11 | 11 | 11 11 | 11 | 11
12 | 12 | 12 12 | 12 | 12
14 | 14 | 14 14 | 14 | 14
@ -671,7 +690,7 @@ FROM
LEFT JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey) LEFT JOIN multi_outer_join_right r1 ON (l1.l_custkey = r1.r_custkey)
ORDER BY 1 DESC, 2 DESC, 3 DESC; ORDER BY 1 DESC, 2 DESC, 3 DESC;
l_custkey | t_custkey | r_custkey l_custkey | t_custkey | r_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
30 | 30 | 30 30 | 30 | 30
29 | 29 | 29 | 29 |
28 | 28 | 28 28 | 28 | 28
@ -702,7 +721,7 @@ WHERE
r_custkey is NULL r_custkey is NULL
ORDER BY 1 DESC, 2 DESC, 3 DESC; ORDER BY 1 DESC, 2 DESC, 3 DESC;
l_custkey | t_custkey | r_custkey l_custkey | t_custkey | r_custkey
-----------+-----------+----------- ---------------------------------------------------------------------
29 | 29 | 29 | 29 |
25 | 25 | 25 | 25 |
23 | 23 | 23 | 23 |
@ -718,7 +737,7 @@ FROM
INNER JOIN multi_outer_join_third_reference t1 ON (test.c_custkey = t1.t_custkey) INNER JOIN multi_outer_join_third_reference t1 ON (test.c_custkey = t1.t_custkey)
ORDER BY 1 DESC; ORDER BY 1 DESC;
t_custkey t_custkey
----------- ---------------------------------------------------------------------
30 30
28 28
27 27
@ -756,7 +775,7 @@ GROUP BY l1.l_custkey
ORDER BY cnt DESC, l1.l_custkey DESC ORDER BY cnt DESC, l1.l_custkey DESC
LIMIT 20; LIMIT 20;
l_custkey | cnt l_custkey | cnt
-----------+----- ---------------------------------------------------------------------
30 | 1 30 | 1
29 | 1 29 | 1
28 | 1 28 | 1
@ -782,36 +801,79 @@ SELECT
min(l_custkey), max(l_custkey) min(l_custkey), max(l_custkey)
FROM FROM
multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_custkey = r_custkey); multi_outer_join_left a LEFT JOIN multi_outer_join_right b ON (l_custkey = r_custkey);
ERROR: cannot push down this subquery min | max
DETAIL: Currently append partitioned relations with overlapping shard intervals are not supported ---------------------------------------------------------------------
1 | 1000
(1 row)
SELECT SELECT
min(l_custkey), max(l_custkey) min(l_custkey), max(l_custkey)
FROM FROM
multi_outer_join_left a RIGHT JOIN multi_outer_join_right b ON (l_custkey = r_custkey); multi_outer_join_left a RIGHT JOIN multi_outer_join_right b ON (l_custkey = r_custkey);
ERROR: cannot push down this subquery min | max
DETAIL: Currently append partitioned relations with overlapping shard intervals are not supported ---------------------------------------------------------------------
11 | 30
(1 row)
SELECT SELECT
min(l_custkey), max(l_custkey) min(l_custkey), max(l_custkey)
FROM FROM
multi_outer_join_left a FULL JOIN multi_outer_join_right b ON (l_custkey = r_custkey); multi_outer_join_left a FULL JOIN multi_outer_join_right b ON (l_custkey = r_custkey);
ERROR: cannot push down this subquery min | max
DETAIL: Currently append partitioned relations with overlapping shard intervals are not supported ---------------------------------------------------------------------
1 | 1000
(1 row)
SELECT SELECT
t_custkey t_custkey
FROM FROM
(multi_outer_join_right r1 (multi_outer_join_right r1
LEFT OUTER JOIN multi_outer_join_left l1 ON (l1.l_custkey = r1.r_custkey)) AS LEFT OUTER JOIN multi_outer_join_left l1 ON (l1.l_custkey = r1.r_custkey)) AS
test(c_custkey, c_nationkey) test(c_custkey, c_nationkey)
INNER JOIN multi_outer_join_third t1 ON (test.c_custkey = t1.t_custkey); INNER JOIN multi_outer_join_third t1 ON (test.c_custkey = t1.t_custkey)
ERROR: cannot push down this subquery ORDER BY 1;
DETAIL: Currently append partitioned relations with overlapping shard intervals are not supported t_custkey
---------------------------------------------------------------------
11
11
12
12
13
14
14
15
16
16
17
17
18
18
19
20
20
21
21
22
22
24
24
26
26
27
27
28
28
30
30
(31 rows)
-- simple test to ensure anti-joins work with hash-partitioned tables -- simple test to ensure anti-joins work with hash-partitioned tables
CREATE TABLE left_values(val int); CREATE TABLE left_values(val int);
SET citus.shard_count to 16; SET citus.shard_count to 16;
SET citus.shard_replication_factor to 1; SET citus.shard_replication_factor to 1;
SELECT create_distributed_table('left_values', 'val'); SELECT create_distributed_table('left_values', 'val');
create_distributed_table create_distributed_table
-------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -819,7 +881,7 @@ SELECT create_distributed_table('left_values', 'val');
CREATE TABLE right_values(val int); CREATE TABLE right_values(val int);
SELECT create_distributed_table('right_values', 'val'); SELECT create_distributed_table('right_values', 'val');
create_distributed_table create_distributed_table
-------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -833,7 +895,7 @@ WHERE
r.val IS NULL r.val IS NULL
ORDER BY 1 DESC, 2 DESC; ORDER BY 1 DESC, 2 DESC;
val | val val | val
-----+----- ---------------------------------------------------------------------
5 | 5 |
1 | 1 |
(2 rows) (2 rows)

View File

@ -38,7 +38,7 @@ CREATE TABLE varchar_partitioned_table
( (
varchar_column varchar(100) varchar_column varchar(100)
); );
SELECT create_distributed_table('varchar_partitioned_table', 'varchar_column', 'append'); SELECT create_distributed_table('varchar_partitioned_table', 'varchar_column', 'range');
-- Create logical shards and shard placements with shardid 100,101 -- Create logical shards and shard placements with shardid 100,101
@ -67,7 +67,7 @@ CREATE TABLE array_partitioned_table
( (
array_column text[] array_column text[]
); );
SELECT create_distributed_table('array_partitioned_table', 'array_column', 'append'); SELECT create_distributed_table('array_partitioned_table', 'array_column', 'range');
SET client_min_messages TO DEBUG2; SET client_min_messages TO DEBUG2;
-- Create logical shard with shardid 102, 103 -- Create logical shard with shardid 102, 103
@ -105,7 +105,7 @@ CREATE TABLE composite_partitioned_table
( (
composite_column composite_type composite_column composite_type
); );
SELECT create_distributed_table('composite_partitioned_table', 'composite_column', 'append'); SELECT create_distributed_table('composite_partitioned_table', 'composite_column', 'range');
SET client_min_messages TO DEBUG2; SET client_min_messages TO DEBUG2;
-- Create logical shard with shardid 104, 105 -- Create logical shard with shardid 104, 105