Merge pull request #1653 from citusdata/fix_group_by

Allow pushing down GROUP BYs when at least there is one distribution
pull/1652/head
Önder Kalacı 2017-09-15 19:38:15 +03:00 committed by GitHub
commit c6ec49312c
3 changed files with 47 additions and 3 deletions

View File

@ -1105,12 +1105,14 @@ TargetListOnPartitionColumn(Query *query, List *targetEntryList)
FindReferencedTableColumn(targetExpression, NIL, query, &relationId, &column);
/* if the expression belongs to reference table directly returns false */
/*
* If the expression belongs to a reference table continue searching for
* other partition keys.
*/
if (IsDistributedTable(relationId) && PartitionMethod(relationId) ==
DISTRIBUTE_BY_NONE)
{
targetListOnPartitionColumn = false;
break;
continue;
}
if (isPartitionColumn)

View File

@ -1166,6 +1166,20 @@ SELECT foo.user_id FROM
) as foo;
ERROR: cannot push down this subquery
DETAIL: Group by list without partition column is currently unsupported
-- supported since the group by contains at least one distributed table
SELECT foo.user_id FROM
(
SELECT r.user_id, random() FROM users_table m JOIN events_reference_table r ON int4eq(m.user_id, r.user_id)
GROUP BY r.user_id, m.user_id
) as foo
ORDER BY 1 LIMIT 3;
user_id
---------
0
1
2
(3 rows)
-- not supported since distinct is on the reference table column
SELECT foo.user_id FROM
(
@ -1180,6 +1194,19 @@ SELECT foo.user_id FROM
) as foo;
ERROR: cannot push down this subquery
DETAIL: Distinct on columns without partition column is currently unsupported
-- supported since the distinct on contains at least one distributed table
SELECT foo.user_id FROM
(
SELECT DISTINCT ON(r.user_id, m.user_id) r.user_id, random() FROM users_table m JOIN events_reference_table r ON int4eq(m.user_id, r.user_id)
) as foo
ORDER BY 1 LIMIT 3;
user_id
---------
0
1
2
(3 rows)
DROP TABLE user_buy_test_table;
DROP TABLE users_ref_test_table;
DROP TABLE users_return_test_table;

View File

@ -932,6 +932,14 @@ SELECT foo.user_id FROM
GROUP BY r.user_id
) as foo;
-- supported since the group by contains at least one distributed table
SELECT foo.user_id FROM
(
SELECT r.user_id, random() FROM users_table m JOIN events_reference_table r ON int4eq(m.user_id, r.user_id)
GROUP BY r.user_id, m.user_id
) as foo
ORDER BY 1 LIMIT 3;
-- not supported since distinct is on the reference table column
SELECT foo.user_id FROM
(
@ -944,6 +952,13 @@ SELECT foo.user_id FROM
SELECT DISTINCT ON(r.user_id) r.user_id, random() FROM users_table m JOIN events_reference_table r ON int4eq(m.user_id, r.user_id)
) as foo;
-- supported since the distinct on contains at least one distributed table
SELECT foo.user_id FROM
(
SELECT DISTINCT ON(r.user_id, m.user_id) r.user_id, random() FROM users_table m JOIN events_reference_table r ON int4eq(m.user_id, r.user_id)
) as foo
ORDER BY 1 LIMIT 3;
DROP TABLE user_buy_test_table;
DROP TABLE users_ref_test_table;
DROP TABLE users_return_test_table;