Skip to content

Commit dd2cf5a

Browse files
author
Steinar H. Gunderson
committed
Bug #31790217: REWRITE STREAMING AGGREGATION
Bug #22588319: OUTER REFERENCE TO AGGREGATE INCORRECTLY 0 OR NULL IN SUBQUERY [noclose] Bug #27272052: REGRESSION: GOT NULL WHEN ROW() FUNCTION USED WITH IN OPERATOR FOR INNODB TABLE Bug #31073167: WRONG RESULT FOR EXPRESSION INVOLVING GROUP BY COLUMNS WITH ROLLUP Bug #31868610: DATA TYPE CHANGED IN A GROUP BY WITH ROLLUP Rewrite streaming aggregation, for simplicity and increased modularity. When aggregating already-sorted data (so-called streaming aggregation, ie., not using a temporary table), we have a fundamental problem: We don't know when a group ends until it's too late. When we see the first row in the next group (or EOF), we know that the current group has ended, but by then, the group expressions that we would like to output are usually already overwritten. We don't have a good way of simply asking the storage engine to keep both rows around (everything points implicitly into table->record[0]), so we need to deal with this ourselves. The current code solves this in two different ways, depending on whether we are outputting to a temporary table or not. If we are, then AggregateIterator takes over part of MaterializeIterator's (or StreamingIterator's) job of copying the data into the destination table's records. This is fairly complex, especially as group expressions and aggregate values need to be copied at different times and in specific internal orders. (It is also a modularity violation. In the pre-iterator executor, group + HAVING + send was in one combined function, and group + HAVING + write was in another combined function. That was even less modular, but the split into iterators also then spread some of the logic out in unfortunate ways, since AggregatorIterator ended up taking on some of MaterializeIterator's duties.) If output goes directly to the client with no temporary table in-between, we set up a special slice (REF_SLICE_ORDERED_GROUP_BY) of Item_copy_* items that keep the previous values of the group expressions. In some places, this is referred to as a “virtual one-row temporary table”. Replace all of this by simply saving a representative row for the group when we encounter it the first time, so that we can easily get its fields back for the output row. We reuse some infrastructure from hash join for doing this, and it simplifies a lot of the logic: - MaterializeIterator/StreamingIterator now always does the copying job (except for windowing functions, which keeps its separate logic here). AggregateIterator now never needs to worry about it. - PrecomputedAggregateIterator, which existed to copy group expressions into a destination table in certain situations, goes away due to the previous point. (This may make EXPLAIN FORMAT=tree more confusing, as the user may wonder where the group step went, but it's an accurate representation of the work we are doing.) - All of Item_copy_* goes away. In its place is only a thin shell called Item_metadata_copy, which serves a role for keeping track of metadata in GREATEST/LEAST type aggregation (Item_copy_* was reused for this). - The entire REF_SLICE_ORDERED_GROUP_BY slice goes away; AggregateIterator now no longer needs to think about slices at all. We also don't need setup_copy_fields(), its item-sorting logic, and the slice switching in the code calling it. In the process, we automatically get a fix for most of bug #22588319 (OUTER REFERENCE TO AGGREGATE INCORRECTLY 0 OR NULL IN SUBQUERY); outer references to aggregates in SELECT lists now work properly, although they are still broken in ORDER BY. A few such queries in the RAPID test suite were recorded with wrong answers. Similarly, this fixes bug #27272052 (REGRESSION: GOT NULL WHEN ROW() FUNCTION USED WITH IN OPERATOR FOR INNODB TABLE). Again, rapid.row was recorded with the wrong answer. It also fixes bug #31073167 (WRONG RESULT FOR EXPRESSION INVOLVING GROUP BY COLUMNS WITH ROLLUP), since it's no longer tricky to know when to copy expressions that depend on both ROLLUP NULLs and other group values (all copying, if any, happens in MaterializeIterator). There is one new tricky thing around slices. Previously, with rollup, we'd first set up the base slice, and then start wrapping certain fields into rollup items (for NULL adding and switching between different aggregates). This would cause the items in the base slice to no longer be a match with the field list; however, it would be fine, since rollup would cause us to always make the REF_SLICE_ORDERED_GROUP_BY slice, which would use the updated field list as its source. We no longer have that, so we need to go back and update the base slice(s) after-the-fact. However, GROUP BY and ORDER BY items could be pointing into that (they always point into slices, probably for historical reasons), and some of the rollup processing code depends on _not_ seeing rollup wrapper items in GROUP BY items. Thus, we have to be careful about updating those slices only after all the other processing. The rollup wrappers in HAVING filters are now generally more visible in EXPLAIN FORMAT=tree, which is probably a good thing. There is one semi-regression. If you have a nondeterministic expression in the SELECT list with an alias, and use HAVING against that alias (a MySQL extension), one might want the expression to only be evaluated once. WL #12074 caused this to not be true in some cases involving SELECT DISTINCT, and we decided that this was okay back then. Now, since we no longer have the Item_copy_* fields snapshotting group expressions, we get evaluating twice in more situations, notably when HAVING expressions mix group expressions and aggregates. (The root cause is that we need to evaluate the item for HAVING, and then don't store the value we chose when we are to send or materialize the row immediately afterwards.) We don't have documented behavior around this, so it should be fine, but it is worth noting. A potential fix could involve snapshotting the row after GROUP BY and before HAVING, possibly by means of a StreamingIterator, but it would involve rewriting the HAVING to point to that snapshot, which we shouldn't do before we have gotten rid of slices entirely and can do such things without introducing more of them. Performance is pretty much neutral; we spend a tiny bit of time saving and loading the rows (~0.5% on DBT-3 Q16), and win some of it back by means of reduced complexity in AggregateIterator, in not going through Item_copy_*, and during setup. Not accounting for bugs, the AggregateIterator code is now prepared for dealing with inputs from multiple tables, although the current join optimizer never sets that up (if there are two or more, it sets up a temporary table to hold the result of the join). This will be useful for the hypergraph join optimizer, which generally prefers not to set up temporary tables unless it confers a direct advantage in some way. Change-Id: I7297cffde70b83a4042187fe26813301aef9f8ee
1 parent 5a7426b commit dd2cf5a

40 files changed

+404
-1383
lines changed

Diff for: mysql-test/r/const_folding.result

+2-2
Original file line numberDiff line numberDiff line change
@@ -52666,7 +52666,7 @@ EXPLAIN SELECT SUM(i) s, j FROM t GROUP BY j WITH ROLLUP HAVING j != 128;
5266652666
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
5266752667
1 SIMPLE t NULL ALL NULL NULL NULL NULL 4 100.00 Using filesort
5266852668
Warnings:
52669-
Note 1003 /* select#1 */ select rollup_sum_switcher(sum(`test`.`t`.`i`)) AS `s`,rollup_group_item(`test`.`t`.`j`,0) AS `j` from `test`.`t` group by `test`.`t`.`j` with rollup having (rollup_group_item(`test`.`t`.`j`,0) <> 128)
52669+
Note 1003 /* select#1 */ select rollup_sum_switcher(sum(`test`.`t`.`i`)) AS `s`,rollup_group_item(`test`.`t`.`j`,0) AS `j` from `test`.`t` group by `test`.`t`.`j` with rollup having (rollup_group_item(rollup_group_item(`test`.`t`.`j`,0),0) <> 128)
5267052670
SELECT SUM(i) s, j FROM t GROUP BY j WITH ROLLUP HAVING j IS NOT NULL;
5267152671
s j
5267252672
3 1
@@ -52675,7 +52675,7 @@ EXPLAIN SELECT SUM(i) s, j FROM t GROUP BY j WITH ROLLUP HAVING j IS NOT NULL;
5267552675
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
5267652676
1 SIMPLE t NULL ALL NULL NULL NULL NULL 4 100.00 Using filesort
5267752677
Warnings:
52678-
Note 1003 /* select#1 */ select rollup_sum_switcher(sum(`test`.`t`.`i`)) AS `s`,rollup_group_item(`test`.`t`.`j`,0) AS `j` from `test`.`t` group by `test`.`t`.`j` with rollup having (rollup_group_item(`test`.`t`.`j`,0) is not null)
52678+
Note 1003 /* select#1 */ select rollup_sum_switcher(sum(`test`.`t`.`i`)) AS `s`,rollup_group_item(`test`.`t`.`j`,0) AS `j` from `test`.`t` group by `test`.`t`.`j` with rollup having (rollup_group_item(rollup_group_item(`test`.`t`.`j`,0),0) is not null)
5267952679
DROP TABLE t;
5268052680
CREATE TABLE a(col_int INT, col_date DATE);
5268152681
SELECT col_date FROM a WHERE

Diff for: mysql-test/r/derived_condition_pushdown.result

+7-8
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ WHERE f1 IS NULL;
377377
EXPLAIN
378378
-> Table scan on dt (cost=*** rows=***)
379379
-> Materialize
380-
-> Filter: (t1.f1 is null)
380+
-> Filter: (rollup_group_item(t1.f1,0) is null)
381381
-> Group aggregate with rollup: sum(t1.f2)
382382
-> Index scan on t1 using f1_2 (cost=*** rows=***)
383383

@@ -394,7 +394,7 @@ j IS NULL;
394394
EXPLAIN
395395
-> Table scan on dt (cost=*** rows=***)
396396
-> Materialize
397-
-> Filter: (((t1.f1 + sum(t1.f2)) > 50) or (t1.f1 is null))
397+
-> Filter: (((rollup_group_item(t1.f1,0) + rollup_sum_switcher(sum(t1.f2))) > 50) or (rollup_group_item(t1.f1,0) is null))
398398
-> Group aggregate with rollup: sum(t1.f2)
399399
-> Index scan on t1 using f1_2 (cost=*** rows=***)
400400

@@ -415,7 +415,7 @@ j IS NULL;
415415
EXPLAIN
416416
-> Table scan on dt (cost=*** rows=***)
417417
-> Materialize
418-
-> Filter: ((avg(t1.f2) > 1) and (((t1.f1 + sum(t1.f2)) > 50) or (t1.f1 is null)))
418+
-> Filter: ((rollup_sum_switcher(avg(t1.f2)) > 1) and (((rollup_group_item(t1.f1,0) + rollup_sum_switcher(sum(t1.f2))) > 50) or (rollup_group_item(t1.f1,0) is null)))
419419
-> Group aggregate with rollup: avg(t1.f2), sum(t1.f2)
420420
-> Index scan on t1 using f1_2 (cost=*** rows=***)
421421

@@ -472,11 +472,10 @@ EXPLAIN
472472
-> Filter: (dt.f1 > 2)
473473
-> Table scan on dt (cost=*** rows=***)
474474
-> Materialize
475-
-> Group (computed in earlier step, no aggregates)
476-
-> Window aggregate with buffering: sum(t1.f2) OVER ()
477-
-> Table scan on <temporary>
478-
-> Temporary table with deduplication (cost=*** rows=***)
479-
-> Index range scan on t1 using index_for_group_by(f1_2) (cost=*** rows=***)
475+
-> Window aggregate with buffering: sum(t1.f2) OVER ()
476+
-> Table scan on <temporary>
477+
-> Temporary table with deduplication (cost=*** rows=***)
478+
-> Index range scan on t1 using index_for_group_by(f1_2) (cost=*** rows=***)
480479

481480
SELECT * FROM (SELECT f1, SUM(f2) OVER() FROM t1 GROUP BY f1) as dt
482481
WHERE f1 > 2;

Diff for: mysql-test/r/functional_index.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ EXPLAIN SELECT col1 FROM t1 WHERE ABS(col1) < 1 ORDER BY ABS(col1) DESC;
186186
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
187187
1 SIMPLE t1 NULL range functional_index functional_index 5 NULL 1 100.00 Using where
188188
Warnings:
189-
Note 1003 /* select#1 */ select `test`.`t1`.`col1` AS `col1` from `test`.`t1` where (abs(`col1`) < 1) order by abs(`col1`) desc
189+
Note 1003 /* select#1 */ select `test`.`t1`.`col1` AS `col1` from `test`.`t1` where (abs(`col1`) < 1) order by abs(`test`.`t1`.`col1`) desc
190190
DROP TABLE t1;
191191
# Test integer index over a JSON key
192192
CREATE TABLE t1(f1 JSON, INDEX idx1 ((CAST(f1->"$.id" AS UNSIGNED))));

Diff for: mysql-test/r/group_by.result

+19-12
Original file line numberDiff line numberDiff line change
@@ -781,11 +781,11 @@ a r2 r1
781781
SELECT a, ROUND(RAND(100)*10) r2, SUM(1) r1 FROM t1 WHERE a = 1
782782
GROUP BY a HAVING r1>1 AND r2<=2;
783783
a r2 r1
784-
1 2 2
784+
1 7 2
785785
SELECT a, ROUND(RAND(100)*10) r2, SUM(1) r1 FROM t1 WHERE a = 1
786786
GROUP BY a HAVING r1>1 AND r2<=2 ORDER BY a+r2+r1;
787787
a r2 r1
788-
1 2 2
788+
1 7 2
789789
SELECT a,SUM(b) FROM t1 WHERE a=1 GROUP BY c;
790790
a SUM(b)
791791
1 5
@@ -2039,15 +2039,15 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
20392039
Warnings:
20402040
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
20412041
Note 1249 Select 2 was reduced during optimization
2042-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by (`test`.`t1`.`a` + 0)
2042+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by (`a` + 0)
20432043
EXPLAIN
20442044
SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) FROM t1 GROUP BY -aa;
20452045
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
20462046
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 100.00 Using temporary; Using filesort
20472047
Warnings:
20482048
Note 1276 Field or reference 'test.t1.a' of SELECT #2 was resolved in SELECT #1
20492049
Note 1249 Select 2 was reduced during optimization
2050-
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by -(`test`.`t1`.`a`)
2050+
Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `aa`,count(distinct `test`.`t1`.`b`) AS `COUNT(DISTINCT b)` from `test`.`t1` group by -(`a`)
20512051
# should return only one record
20522052
SELECT (SELECT tt.a FROM t1 tt LIMIT 1) aa, COUNT(DISTINCT b) FROM t1
20532053
GROUP BY aa;
@@ -3601,13 +3601,20 @@ SELECT 1 FROM t HAVING (SELECT SUM(a)) > 0;
36013601
SELECT (SELECT SUM(a)) FROM t;
36023602
(SELECT SUM(a))
36033603
4
3604-
# These queries where accepted before the fix, and they still are,
3605-
# but their results are wrong both before and after the fix
3606-
# because of bug#22588319.
3607-
# Returns (4, NULL), should have returned (4, 1):
3608-
SELECT SUM(a) s, (SELECT 1 HAVING s > 0) s2 FROM t;
3609-
s s2
3604+
# Bug #22588319: OUTER REFERENCE TO AGGREGATE INCORRECTLY 0 OR NULL IN SUBQUERY
3605+
SELECT SUM(a) AS s, (SELECT 1 HAVING s) FROM t;
3606+
s (SELECT 1 HAVING s)
3607+
4 1
3608+
SELECT SUM(a) AS s, (SELECT 1 HAVING s IS NULL) FROM t;
3609+
s (SELECT 1 HAVING s IS NULL)
3610+
4 NULL
3611+
SELECT COUNT(a) AS c, (SELECT 1 HAVING c) FROM t;
3612+
c (SELECT 1 HAVING c)
3613+
4 1
3614+
SELECT COUNT(a) AS c, (SELECT 1 HAVING c = 0) FROM t;
3615+
c (SELECT 1 HAVING c = 0)
36103616
4 NULL
3617+
# Shows that #22588319 isn't fixed for ORDER BY.
36113618
# Should have ordered ascending on -a, but comes out in random order
36123619
# because the ORDER BY clause always evaluates to NULL. Have to use
36133620
# the --sorted_result directive to produce stable test results.
@@ -3786,7 +3793,7 @@ INSERT INTO t VALUES ('1', 10), ('1', 11), ('2', 20), ('2', 20), ('3', 30);
37863793
EXPLAIN FORMAT=tree SELECT (SELECT a) AS col1, COUNT(DISTINCT b) FROM t GROUP BY -col1;
37873794
EXPLAIN
37883795
-> Group aggregate: count(distinct t.b)
3789-
-> Sort: `-(t.a)`
3796+
-> Sort: `-(a)`
37903797
-> Stream results (cost=*** rows=***)
37913798
-> Table scan on t (cost=*** rows=***)
37923799

@@ -3820,7 +3827,7 @@ INSERT INTO t VALUES ('1', 10), ('1', 11), ('2', 20), ('2', 20), ('3', 30);
38203827
EXPLAIN FORMAT=tree SELECT (SELECT a) AS col1, COUNT(DISTINCT b) FROM t GROUP BY -col1;
38213828
EXPLAIN
38223829
-> Group aggregate: count(distinct t.b)
3823-
-> Sort: `-(t.a)`
3830+
-> Sort: `-(a)`
38243831
-> Stream results (cost=*** rows=***)
38253832
-> Table scan on t (cost=*** rows=***)
38263833

Diff for: mysql-test/r/group_min_max.result

+3-5
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ Warnings:
138138
Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,min(`test`.`t1`.`a2`) AS `min(a2)` from `test`.`t1` group by `test`.`t1`.`a1`
139139
explain format=tree select a1, min(a2) from t1 group by a1;
140140
EXPLAIN
141-
-> Group aggregate (computed in earlier step): min(t1.a2)
142-
-> Index range scan on t1 using index_for_group_by(idx_t1_1) (cost=3.25 rows=5)
141+
-> Index range scan on t1 using index_for_group_by(idx_t1_1) (cost=3.25 rows=5)
143142

144143
explain select a1, max(a2) from t1 group by a1;
145144
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
@@ -1697,9 +1696,8 @@ Warnings:
16971696
Note 1003 /* select#1 */ select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t1`.`b` AS `b` from `test`.`t1` where (((`test`.`t1`.`a1` >= 'c') or (`test`.`t1`.`a2` < 'b')) and (`test`.`t1`.`b` > 'a')) group by `test`.`t1`.`a1`,`test`.`t1`.`a2`,`test`.`t1`.`b`
16981697
explain format=tree select a1,a2,b from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b;
16991698
EXPLAIN
1700-
-> Group (computed in earlier step, no aggregates)
1701-
-> Filter: (((t1.a1 >= 'c') or (t1.a2 < 'b')) and (t1.b > 'a')) (cost=11.05 rows=17)
1702-
-> Index range scan on t1 using index_for_group_by(idx_t1_1) (cost=11.05 rows=17)
1699+
-> Filter: (((t1.a1 >= 'c') or (t1.a2 < 'b')) and (t1.b > 'a')) (cost=11.05 rows=17)
1700+
-> Index range scan on t1 using index_for_group_by(idx_t1_1) (cost=11.05 rows=17)
17031701

17041702
explain select a1,a2,b from t1 where (a2 >= 'b') and (b = 'a') group by a1,a2,b;
17051703
id select_type table partitions type possible_keys key key_len ref rows filtered Extra

Diff for: mysql-test/r/having.result

+6-3
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,12 @@ val c
796796
UPDATE series set val=0;
797797
SELECT next_seq_value() r, MIN(u) FROM t1 GROUP BY t HAVING r = 1;
798798
r MIN(u)
799-
1 11
800-
1 15
801-
1 17
799+
0 11
800+
0 12
801+
0 15
802+
0 16
803+
0 17
804+
0 18
802805
DROP TABLE t1;
803806
DROP FUNCTION next_seq_value;
804807
DROP TABLE series, seq_calls;

Diff for: mysql-test/r/metadata_myisam.result

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CREATE VIEW v2 AS select t1.id as renamed from t1;
77
CREATE VIEW v3 AS select t1.id + 12 as renamed from t1;
88
select * from v1 group by id limit 1;
99
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
10-
def test t1 v1 id id 3 10 1 Y 32768 0 63
10+
def test v1 v1 id id 3 10 1 Y 32768 0 63
1111
id
1212
1
1313
select * from v1 group by id limit 0;
@@ -20,12 +20,12 @@ def test v1 v1 id id 3 10 0 Y 32768 0 63
2020
id
2121
select * from v1 where id=1 group by id;
2222
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
23-
def test t1 v1 id id 3 10 1 Y 32768 0 63
23+
def test v1 v1 id id 3 10 1 Y 32768 0 63
2424
id
2525
1
2626
select * from v2 where renamed=1 group by renamed;
2727
Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr
28-
def test t1 v2 id renamed 3 10 1 Y 32768 0 63
28+
def test v2 v2 renamed renamed 3 10 1 Y 32768 0 63
2929
renamed
3030
1
3131
select * from v3 where renamed=1 group by renamed;

Diff for: mysql-test/r/olap.result

+35
Original file line numberDiff line numberDiff line change
@@ -1322,6 +1322,31 @@ NULL NULL NULL 0 1
13221322
555 NULL 168 0 1
13231323
1111 NULL 112 0 1
13241324
NULL NULL 622 1 1
1325+
#
1326+
# Bug #31073167: WRONG RESULT FOR EXPRESSION INVOLVING GROUP BY COLUMNS WITH ROLLUP
1327+
#
1328+
SELECT a, b, a + COALESCE(b, 0), AVG(b) OVER () FROM t1 GROUP BY a, b WITH ROLLUP;
1329+
a b a + COALESCE(b, 0) AVG(b) OVER ()
1330+
NULL 112 NULL 40.6364
1331+
NULL NULL NULL 40.6364
1332+
111 11 122 40.6364
1333+
111 12 123 40.6364
1334+
111 NULL 111 40.6364
1335+
222 22 244 40.6364
1336+
222 23 245 40.6364
1337+
222 NULL 222 40.6364
1338+
333 33 366 40.6364
1339+
333 34 367 40.6364
1340+
333 NULL 333 40.6364
1341+
444 44 488 40.6364
1342+
444 45 489 40.6364
1343+
444 NULL 444 40.6364
1344+
555 55 610 40.6364
1345+
555 56 611 40.6364
1346+
555 NULL 555 40.6364
1347+
1111 NULL 1111 40.6364
1348+
1111 NULL 1111 40.6364
1349+
NULL NULL NULL 40.6364
13251350
DROP TABLE t0,t1;
13261351
#
13271352
# Bug#25174118 ROLLUP NULL'S GET REPLACED WITH LAST ROW'S VALUE FOR PREPARED STMTS ON A VIEW
@@ -2129,3 +2154,13 @@ a b 2*a+b SUM(a+b) OVER ()
21292154
2 NULL NULL 16
21302155
NULL NULL NULL 16
21312156
DROP TABLE t1;
2157+
#
2158+
# Bug #31868610: DATA TYPE CHANGED IN A GROUP BY WITH ROLLUP
2159+
#
2160+
CREATE TABLE IF NOT EXISTS t1 (a DECIMAL(6,3));
2161+
INSERT INTO t1 VALUES (1.1);
2162+
SELECT a FROM t1 GROUP BY a WITH ROLLUP;
2163+
a
2164+
1.100
2165+
NULL
2166+
DROP TABLE t1;

Diff for: mysql-test/r/row.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ SELECT @x;
476476
@x
477477
99
478478
DROP TABLE t1;
479-
CREATE TABLE t1 (a INT, b INT) ENGINE=MyISAM;
479+
CREATE TABLE t1 (a INT, b INT);
480480
INSERT INTO t1 VALUES (1,1);
481481
SELECT ROW(a, 1) IN (SELECT SUM(b), 1) FROM t1 GROUP BY a;
482482
ROW(a, 1) IN (SELECT SUM(b), 1)

Diff for: mysql-test/r/subquery_scalar_to_derived.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
13891389
1 PRIMARY <derived2> NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (hash join)
13901390
2 DERIVED t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL
13911391
Warnings:
1392-
Note 1003 /* select#1 */ select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1` left join (/* select#2 */ select sum(`test`.`t2`.`i`) AS `SUM(t2.i)` from `test`.`t2`) `derived_1_2` on(true) where true group by `test`.`t1`.`i`,`test`.`t1`.`j` with rollup having (sum(`test`.`t1`.`j`) > `derived_1_2`.`SUM(t2.i)`)
1392+
Note 1003 /* select#1 */ select `test`.`t1`.`i` AS `i`,`test`.`t1`.`j` AS `j` from `test`.`t1` left join (/* select#2 */ select sum(`test`.`t2`.`i`) AS `SUM(t2.i)` from `test`.`t2`) `derived_1_2` on(true) where true group by `test`.`t1`.`i`,`test`.`t1`.`j` with rollup having (rollup_sum_switcher(sum(`test`.`t1`.`j`)) > `derived_1_2`.`SUM(t2.i)`)
13931393
DROP TABLE t1, t2;
13941394
Bigger example (TPC-H Q11) where we get a scalar transformation
13951395
in the grouping derived table also, i.e. nested scalar to

Diff for: mysql-test/suite/gcol/r/gcol_keys_innodb.result

+4-4
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ EXPLAIN SELECT * FROM t1 ORDER BY f1 + 1;
659659
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
660660
1 SIMPLE t1 NULL index NULL PRIMARY 4 NULL 10 100.00 NULL
661661
Warnings:
662-
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`gc` AS `gc` from `test`.`t1` order by `test`.`t1`.`gc`
662+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`gc` AS `gc` from `test`.`t1` order by (`test`.`t1`.`f1` + 1)
663663
SELECT * FROM information_schema.OPTIMIZER_TRACE;
664664
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
665665
EXPLAIN SELECT * FROM t1 ORDER BY f1 + 1 {
@@ -823,7 +823,7 @@ EXPLAIN SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
823823
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
824824
1 SIMPLE t1 NULL index PRIMARY PRIMARY 4 NULL 10 100.00 NULL
825825
Warnings:
826-
Note 1003 /* select#1 */ select (`test`.`t1`.`f1` + 1) AS `f1 + 1`,max(`test`.`t1`.`gc`) AS `MAX(GC)` from `test`.`t1` group by `test`.`t1`.`gc`
826+
Note 1003 /* select#1 */ select (`test`.`t1`.`f1` + 1) AS `f1 + 1`,max(`test`.`t1`.`gc`) AS `MAX(GC)` from `test`.`t1` group by (`test`.`t1`.`f1` + 1)
827827
SELECT * FROM information_schema.OPTIMIZER_TRACE;
828828
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
829829
EXPLAIN SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1 {
@@ -1082,7 +1082,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
10821082
1 SIMPLE table1 NULL ALL PRIMARY NULL NULL NULL 1 100.00 Using temporary; Using filesort
10831083
1 SIMPLE table2 NULL eq_ref PRIMARY PRIMARY 4 test.table1.pk 1 100.00 NULL
10841084
Warnings:
1085-
Note 1003 /* select#1 */ select (`test`.`table1`.`col_int_key` + 1) AS `field1`,`test`.`table2`.`col_int_key` AS `field2` from `test`.`t1` `table1` join `test`.`t1` `table2` where (`test`.`table2`.`pk` = `test`.`table1`.`pk`) order by `col_int_gc_key`,`field2`
1085+
Note 1003 /* select#1 */ select (`test`.`table1`.`col_int_key` + 1) AS `field1`,`test`.`table2`.`col_int_key` AS `field2` from `test`.`t1` `table1` join `test`.`t1` `table2` where (`test`.`table2`.`pk` = `test`.`table1`.`pk`) order by `field1`,`field2`
10861086
SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
10871087
FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
10881088
GROUP BY field1, field2;
@@ -1095,7 +1095,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
10951095
1 SIMPLE table1 NULL ALL PRIMARY NULL NULL NULL 1 100.00 Using temporary
10961096
1 SIMPLE table2 NULL eq_ref PRIMARY PRIMARY 4 test.table1.pk 1 100.00 NULL
10971097
Warnings:
1098-
Note 1003 /* select#1 */ select (`test`.`table1`.`col_int_key` + 1) AS `field1`,`test`.`table2`.`col_int_key` AS `field2` from `test`.`t1` `table1` join `test`.`t1` `table2` where (`test`.`table2`.`pk` = `test`.`table1`.`pk`) group by `col_int_gc_key`,`field2`
1098+
Note 1003 /* select#1 */ select (`test`.`table1`.`col_int_key` + 1) AS `field1`,`test`.`table2`.`col_int_key` AS `field2` from `test`.`t1` `table1` join `test`.`t1` `table2` where (`test`.`table2`.`pk` = `test`.`table1`.`pk`) group by `field1`,`field2`
10991099
DROP TABLE t1;
11001100
#
11011101
# Bug#21391781 ASSERT WHEN RUNNING ALTER TABLE ON A TABLE WITH INDEX

Diff for: mysql-test/suite/gcol/r/gcol_keys_myisam.result

+4-4
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ EXPLAIN SELECT * FROM t1 ORDER BY f1 + 1;
410410
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
411411
1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 10 100.00 Using filesort
412412
Warnings:
413-
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`gc` AS `gc` from `test`.`t1` order by `test`.`t1`.`gc`
413+
Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`gc` AS `gc` from `test`.`t1` order by (`test`.`t1`.`f1` + 1)
414414
SELECT * FROM information_schema.OPTIMIZER_TRACE;
415415
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
416416
EXPLAIN SELECT * FROM t1 ORDER BY f1 + 1 {
@@ -576,7 +576,7 @@ EXPLAIN SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1;
576576
id select_type table partitions type possible_keys key key_len ref rows filtered Extra
577577
1 SIMPLE t1 NULL index PRIMARY PRIMARY 4 NULL 10 100.00 NULL
578578
Warnings:
579-
Note 1003 /* select#1 */ select (`test`.`t1`.`f1` + 1) AS `f1 + 1`,max(`test`.`t1`.`gc`) AS `MAX(GC)` from `test`.`t1` group by `test`.`t1`.`gc`
579+
Note 1003 /* select#1 */ select (`test`.`t1`.`f1` + 1) AS `f1 + 1`,max(`test`.`t1`.`gc`) AS `MAX(GC)` from `test`.`t1` group by (`test`.`t1`.`f1` + 1)
580580
SELECT * FROM information_schema.OPTIMIZER_TRACE;
581581
QUERY TRACE MISSING_BYTES_BEYOND_MAX_MEM_SIZE INSUFFICIENT_PRIVILEGES
582582
EXPLAIN SELECT f1 + 1, MAX(GC) FROM t1 GROUP BY f1 + 1 {
@@ -835,7 +835,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
835835
1 SIMPLE table1 NULL system PRIMARY NULL NULL NULL 1 100.00 NULL
836836
1 SIMPLE table2 NULL system PRIMARY NULL NULL NULL 1 100.00 NULL
837837
Warnings:
838-
Note 1003 /* select#1 */ select ('7' + 1) AS `field1`,'7' AS `field2` from dual where true order by `col_int_gc_key`,`field2`
838+
Note 1003 /* select#1 */ select ('7' + 1) AS `field1`,'7' AS `field2` from dual where true order by `field1`,`field2`
839839
SELECT table1.col_int_key + 1 AS field1, table2.col_int_key AS field2
840840
FROM (t1 AS table1 JOIN t1 AS table2 ON (table2.pk = table1.pk))
841841
GROUP BY field1, field2;
@@ -848,7 +848,7 @@ id select_type table partitions type possible_keys key key_len ref rows filtered
848848
1 SIMPLE table1 NULL system PRIMARY NULL NULL NULL 1 100.00 NULL
849849
1 SIMPLE table2 NULL system PRIMARY NULL NULL NULL 1 100.00 NULL
850850
Warnings:
851-
Note 1003 /* select#1 */ select ('7' + 1) AS `field1`,'7' AS `field2` from dual where true group by `col_int_gc_key`,`field2`
851+
Note 1003 /* select#1 */ select ('7' + 1) AS `field1`,'7' AS `field2` from dual where true group by `field1`,`field2`
852852
DROP TABLE t1;
853853
#
854854
# Bug#21770798 OPTIMIZER DOES NOT USE INDEX FOR GENERATED EXPRESSIONS

Diff for: mysql-test/suite/json/r/json_functions_innodb.result

+2
Original file line numberDiff line numberDiff line change
@@ -7212,6 +7212,7 @@ NULL 1
72127212
NULL 2
72137213
Warnings:
72147214
Warning 3156 Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column j at row 3
7215+
Warning 3156 Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column j at row 4
72157216
UPDATE tt SET j = CAST(CAST('2015-06-19' AS DATE) AS JSON) WHERE j IS NOT NULL;
72167217
SELECT CAST(j AS DATE), COUNT(*) FROM tt GROUP BY j, i WITH ROLLUP;
72177218
CAST(j AS DATE) COUNT(*)
@@ -7233,6 +7234,7 @@ NULL 1
72337234
Warnings:
72347235
Warning 1235 This version of MySQL doesn't yet support 'sorting of non-scalar JSON values'
72357236
Warning 1301 Result of j() was larger than max_allowed_packet (1024) - truncated
7237+
Warning 1301 Result of j() was larger than max_allowed_packet (1024) - truncated
72367238
SELECT REPEAT(j, 2), COUNT(*) FROM tt GROUP BY j, i;
72377239
REPEAT(j, 2) COUNT(*)
72387240
1

0 commit comments

Comments
 (0)