-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-40698 ROLLUP query returns incorrect result with empty result set #5542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 10.11
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # | ||
| # MDEV-40698: ROLLUP query returns incorrect result with empty result set | ||
| # | ||
| CREATE TABLE t0(a INT, b INT, c INT); | ||
| SELECT *, COUNT(0) FROM t0 GROUP BY a, b, c WITH ROLLUP; | ||
| a b c COUNT(0) | ||
| NULL NULL NULL 0 | ||
| SELECT *, COUNT(0) FROM t0 WHERE 1=0 GROUP BY a, b, c WITH ROLLUP; | ||
| a b c COUNT(0) | ||
| NULL NULL NULL 0 | ||
| SELECT *, COUNT(0), ROW_NUMBER() OVER () FROM t0 GROUP BY a, b, c WITH ROLLUP; | ||
| a b c COUNT(0) ROW_NUMBER() OVER () | ||
| NULL NULL NULL 0 1 | ||
| SELECT 1 IN (SELECT a FROM t0 WHERE a>0 GROUP BY a WITH ROLLUP); | ||
| 1 IN (SELECT a FROM t0 WHERE a>0 GROUP BY a WITH ROLLUP) | ||
| NULL | ||
| INSERT INTO t0 VALUES (0, 0, 0),(0, 0, 0); | ||
| SELECT *, COUNT(0) FROM t0 WHERE a > 0 GROUP BY a, b, c WITH ROLLUP; | ||
| a b c COUNT(0) | ||
| NULL NULL NULL 0 | ||
| SELECT EXISTS (SELECT t0.a FROM t0 x WHERE 1=0 GROUP BY x.a WITH ROLLUP) AS e | ||
| FROM t0; | ||
| e | ||
| 1 | ||
| 1 | ||
| SELECT DISTINCT a FROM t0 GROUP BY a, b WITH ROLLUP; | ||
| a | ||
| 0 | ||
| NULL | ||
| CREATE TABLE t1 (a INT, b INT, c INT) ENGINE=InnoDB; | ||
| SELECT *, COUNT(0) FROM t1 GROUP BY a, b, c WITH ROLLUP; | ||
| a b c COUNT(0) | ||
| NULL NULL NULL 0 | ||
| SELECT *, COUNT(0) FROM t1 WHERE 1=0 GROUP BY a, b, c WITH ROLLUP; | ||
| a b c COUNT(0) | ||
| NULL NULL NULL 0 | ||
| SELECT *, COUNT(0), ROW_NUMBER() OVER () FROM t1 GROUP BY a, b, c WITH ROLLUP; | ||
| a b c COUNT(0) ROW_NUMBER() OVER () | ||
| NULL NULL NULL 0 1 | ||
| INSERT INTO t1 VALUES (0, 0, 0),(0, 0, 0); | ||
| SELECT *, COUNT(0) FROM t1 WHERE a > 0 GROUP BY a, b, c WITH ROLLUP; | ||
| a b c COUNT(0) | ||
| NULL NULL NULL 0 | ||
| SELECT EXISTS (SELECT t1.a FROM t1 x WHERE 1=0 GROUP BY x.a WITH ROLLUP) AS e | ||
| FROM t1; | ||
| e | ||
| 1 | ||
| 1 | ||
| SELECT DISTINCT a FROM t1 GROUP BY a, b WITH ROLLUP; | ||
| a | ||
| 0 | ||
| NULL | ||
| DROP TABLE t0, t1; | ||
| # End of 10.11 tests |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --source include/have_innodb.inc | ||
|
|
||
| --echo # | ||
| --echo # MDEV-40698: ROLLUP query returns incorrect result with empty result set | ||
| --echo # | ||
|
|
||
| CREATE TABLE t0(a INT, b INT, c INT); | ||
| SELECT *, COUNT(0) FROM t0 GROUP BY a, b, c WITH ROLLUP; | ||
| SELECT *, COUNT(0) FROM t0 WHERE 1=0 GROUP BY a, b, c WITH ROLLUP; | ||
| SELECT *, COUNT(0), ROW_NUMBER() OVER () FROM t0 GROUP BY a, b, c WITH ROLLUP; | ||
| SELECT 1 IN (SELECT a FROM t0 WHERE a>0 GROUP BY a WITH ROLLUP); | ||
| INSERT INTO t0 VALUES (0, 0, 0),(0, 0, 0); | ||
| SELECT *, COUNT(0) FROM t0 WHERE a > 0 GROUP BY a, b, c WITH ROLLUP; | ||
| SELECT EXISTS (SELECT t0.a FROM t0 x WHERE 1=0 GROUP BY x.a WITH ROLLUP) AS e | ||
| FROM t0; | ||
| SELECT DISTINCT a FROM t0 GROUP BY a, b WITH ROLLUP; | ||
|
|
||
| CREATE TABLE t1 (a INT, b INT, c INT) ENGINE=InnoDB; | ||
| SELECT *, COUNT(0) FROM t1 GROUP BY a, b, c WITH ROLLUP; | ||
| SELECT *, COUNT(0) FROM t1 WHERE 1=0 GROUP BY a, b, c WITH ROLLUP; | ||
| SELECT *, COUNT(0), ROW_NUMBER() OVER () FROM t1 GROUP BY a, b, c WITH ROLLUP; | ||
| INSERT INTO t1 VALUES (0, 0, 0),(0, 0, 0); | ||
| SELECT *, COUNT(0) FROM t1 WHERE a > 0 GROUP BY a, b, c WITH ROLLUP; | ||
| SELECT EXISTS (SELECT t1.a FROM t1 x WHERE 1=0 GROUP BY x.a WITH ROLLUP) AS e | ||
| FROM t1; | ||
| SELECT DISTINCT a FROM t1 GROUP BY a, b WITH ROLLUP; | ||
|
|
||
| DROP TABLE t0, t1; | ||
|
|
||
| --echo # End of 10.11 tests | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just single line on Can the tests be appended to mysql-test/main/olap.test instead of a new file.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I initially had it that way, but the olap tests don't include innodb and I wasn't sure about including it for the whole file just for these tests |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1746,12 +1746,27 @@ class JOIN :public Sql_alloc | |
| void cleanup(bool full); | ||
| void clear(table_map *cleared_tables); | ||
| void inline clear_sum_funcs(); | ||
| bool need_empty_set_row(bool end_of_records, | ||
| bool *empty_set_send_rollup_total) const | ||
| { | ||
| *empty_set_send_rollup_total= | ||
| end_of_records && !first_record && rollup.state != ROLLUP::STATE_NONE; | ||
| return (end_of_records && !first_record && !group && | ||
| !group_optimized_away) || | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a new condition. Do we need this?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's mainly for code cleanliness. Previously the need_empty_set_row condition was present directly in the if statement in end_send_group/end_write_group. But I figured with the extra condition for empty_set_rollup_total, which needs to be referenced again later, the code would start having many duplicated expressions.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, i meant
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohh i see. actually I am curious too because group_optimized_away was included in the conditional in end_send_group but not end_write_group. But I believe it should be included in both to be consistent with send_row_on_empty_set |
||
| *empty_set_send_rollup_total; | ||
| } | ||
| bool send_row_on_empty_set() | ||
| { | ||
| return (do_send_rows && implicit_grouping && !group_optimized_away && | ||
| return (do_send_rows && | ||
| (select_lex->olap == ROLLUP_TYPE || | ||
| (implicit_grouping && !group_optimized_away)) && | ||
| having_value != Item::COND_FALSE); | ||
| } | ||
| bool empty_result() { return (zero_result_cause && !implicit_grouping); } | ||
| bool empty_result() | ||
| { | ||
| return (zero_result_cause && !implicit_grouping && | ||
| select_lex->olap != ROLLUP_TYPE); | ||
| } | ||
| bool change_result(select_result *new_result, select_result *old_result); | ||
| bool is_top_level_join() const | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.