IMPALA-1550: Invalid rewrite when EXISTS subqueries contain aggregate

functions

This commit fixes an issue where a [NOT] EXISTS subquery that contains
an aggregate function will sometimes be incorrectly rewritten into a
join, thereby returning incorrect results.

Change-Id: I18b211d76ee3de77d8061603ff5bb1fbceae2e60
Reviewed-on: http://gerrit.cloudera.org:8080/266
Reviewed-by: Dimitris Tsirogiannis <dtsirogiannis@cloudera.com>
Tested-by: Internal Jenkins
This commit is contained in:
Dimitris Tsirogiannis
2015-03-18 17:05:59 -07:00
committed by Internal Jenkins
parent 672ae91732
commit 4eceeacf16
4 changed files with 157 additions and 14 deletions

View File

@@ -759,3 +759,31 @@ UNION ALL SELECT 3
---- TYPES
TINYINT
====
---- QUERY
# Correlated NOT EXISTS subquery with an aggregate function (IMPALA-1550)
SELECT t1.bigint_col
FROM alltypestiny t1
WHERE NOT EXISTS
(SELECT SUM(smallint_col) AS int_col
FROM alltypestiny
WHERE t1.date_string_col = string_col AND t1.timestamp_col = timestamp_col)
GROUP BY t1.bigint_col
---- RESULTS
---- TYPES
BIGINT
====
---- QUERY
# Correlated EXISTS subquery with an aggregate function (IMPALA-1550)
SELECT t1.bigint_col
FROM alltypestiny t1
WHERE EXISTS
(SELECT SUM(smallint_col) AS int_col
FROM alltypestiny
WHERE t1.date_string_col = string_col AND t1.timestamp_col = timestamp_col)
GROUP BY t1.bigint_col
---- RESULTS
0
10
---- TYPES
BIGINT
====