Merge pull request #2102 from citusdata/push_down_multiple_having

This is a fairly simple PR that changes the AND clauses in having explicit for worker queries for pushdown planner. Since, they are going to be switched back to be implicit in worker itself, we should provide them in explicit form. Otherwise, the worker errors-out saying the query syntax is wrong.
pull/2109/head
Mehmet Furkan ŞAHİN 2018-04-16 15:30:05 +03:00 committed by GitHub
commit de6d3f2d33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 81 additions and 0 deletions

View File

@ -2133,6 +2133,19 @@ WorkerExtendedOpNode(MultiExtendedOp *originalOpNode,
(groupedByDisjointPartitionColumn || pushDownWindowFunction))
{
workerExtendedOpNode->havingQual = originalOpNode->havingQual;
/*
* We converted the having expression to a list in subquery pushdown
* planner. However, this query cannot be parsed as it is in the worker.
* We should convert this back to being explicit for worker query
* so that it can be parsed when it hits to the standard planner in
* worker.
*/
if (IsA(workerExtendedOpNode->havingQual, List))
{
workerExtendedOpNode->havingQual =
(Node *) make_ands_explicit((List *) workerExtendedOpNode->havingQual);
}
}
return workerExtendedOpNode;

View File

@ -183,3 +183,48 @@ EXPLAIN (COSTS FALSE)
DROP TABLE lineitem_hash;
DROP TABLE orders_hash;
SELECT max(value_1)
FROM users_table
GROUP BY user_id
HAVING max(value_2) > 4 AND min(value_2) < 1
ORDER BY 1;
max
-----
4
5
5
(3 rows)
SELECT max(value_1)
FROM users_table
GROUP BY user_id
HAVING max(value_2) > 4 AND min(value_2) < 1 OR count(*) > 10
ORDER BY 1;
max
-----
4
5
5
5
(4 rows)
SELECT max(value_1)
FROM users_table
GROUP BY user_id
HAVING max(value_2) > 4 AND min(value_2) < 1 AND count(*) > 20
ORDER BY 1;
max
-----
5
5
(2 rows)
SELECT max(value_1)
FROM users_table
GROUP BY user_id
HAVING max(value_2) > 0 AND count(*) FILTER (WHERE value_3=2) > 3 AND min(value_2) IN (0,1,2,3);
max
-----
5
(1 row)

View File

@ -55,3 +55,26 @@ EXPLAIN (COSTS FALSE)
DROP TABLE lineitem_hash;
DROP TABLE orders_hash;
SELECT max(value_1)
FROM users_table
GROUP BY user_id
HAVING max(value_2) > 4 AND min(value_2) < 1
ORDER BY 1;
SELECT max(value_1)
FROM users_table
GROUP BY user_id
HAVING max(value_2) > 4 AND min(value_2) < 1 OR count(*) > 10
ORDER BY 1;
SELECT max(value_1)
FROM users_table
GROUP BY user_id
HAVING max(value_2) > 4 AND min(value_2) < 1 AND count(*) > 20
ORDER BY 1;
SELECT max(value_1)
FROM users_table
GROUP BY user_id
HAVING max(value_2) > 0 AND count(*) FILTER (WHERE value_3=2) > 3 AND min(value_2) IN (0,1,2,3);