Fix of LP BUG#793589 Wrong result with double ORDER BY
Problem was in caching 'eq_ref' dependency between calls of remove_const() for ORDER BY and GROUP BY lists.
This commit is contained in:
parent
98135fed0f
commit
d63fc00f35
@ -1672,3 +1672,57 @@ select 1 order by max(1) + min(1);
|
||||
1
|
||||
1
|
||||
End of 5.1 tests
|
||||
#
|
||||
# Fix of LP BUG#793589 Wrong result with double ORDER BY
|
||||
#
|
||||
CREATE TABLE t1 ( b int) ;
|
||||
INSERT INTO t1 VALUES (8),(9);
|
||||
CREATE TABLE t2 ( a int, b int, PRIMARY KEY (a)) ;
|
||||
INSERT INTO t2 VALUES (6,7),(7,7),(8,1),(9,7),(10,1),(11,5),(12,2),(13,0),(14,1),(15,8),(16,1),(17,1),(18,9),(19,1),(20,5);
|
||||
SELECT t2.b AS field1 FROM t1, t2 WHERE t1.b = t2.a GROUP BY field1 ORDER BY t1.b, field1;
|
||||
field1
|
||||
1
|
||||
7
|
||||
SELECT t2.b, t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b, t2.b;
|
||||
b b
|
||||
1 8
|
||||
7 9
|
||||
SELECT t2.b,t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
|
||||
b b
|
||||
1 8
|
||||
7 9
|
||||
SELECT t2.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
|
||||
b
|
||||
1
|
||||
7
|
||||
# field1 removed from ORDER BY
|
||||
explain extended
|
||||
SELECT t2.b AS field1 FROM t1, t2 WHERE t1.b = t2.a GROUP BY field1 ORDER BY t1.b, field1;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
|
||||
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`b` AS `field1` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`b`) group by `test`.`t2`.`b` order by `test`.`t1`.`b`
|
||||
explain extended
|
||||
SELECT t2.b, t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b, t2.b;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
|
||||
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`b`) group by `test`.`t2`.`b` order by `test`.`t1`.`b`
|
||||
explain extended
|
||||
SELECT t2.b,t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
|
||||
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`b` AS `b`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`b`) group by `test`.`t2`.`b` order by `test`.`t1`.`b`
|
||||
explain extended
|
||||
SELECT t2.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
|
||||
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using temporary; Using filesort
|
||||
1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.b 1 100.00
|
||||
Warnings:
|
||||
Note 1003 select `test`.`t2`.`b` AS `b` from `test`.`t1` join `test`.`t2` where (`test`.`t2`.`a` = `test`.`t1`.`b`) group by `test`.`t2`.`b` order by `test`.`t1`.`b`
|
||||
drop table t1,t2;
|
||||
End of 5.2 tests
|
||||
|
@ -1518,3 +1518,32 @@ DROP TABLE t1;
|
||||
select 1 order by max(1) + min(1);
|
||||
|
||||
--echo End of 5.1 tests
|
||||
|
||||
--echo #
|
||||
--echo # Fix of LP BUG#793589 Wrong result with double ORDER BY
|
||||
--echo #
|
||||
CREATE TABLE t1 ( b int) ;
|
||||
INSERT INTO t1 VALUES (8),(9);
|
||||
|
||||
CREATE TABLE t2 ( a int, b int, PRIMARY KEY (a)) ;
|
||||
INSERT INTO t2 VALUES (6,7),(7,7),(8,1),(9,7),(10,1),(11,5),(12,2),(13,0),(14,1),(15,8),(16,1),(17,1),(18,9),(19,1),(20,5);
|
||||
|
||||
SELECT t2.b AS field1 FROM t1, t2 WHERE t1.b = t2.a GROUP BY field1 ORDER BY t1.b, field1;
|
||||
SELECT t2.b, t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b, t2.b;
|
||||
SELECT t2.b,t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
|
||||
SELECT t2.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
|
||||
|
||||
--echo # field1 removed from ORDER BY
|
||||
explain extended
|
||||
SELECT t2.b AS field1 FROM t1, t2 WHERE t1.b = t2.a GROUP BY field1 ORDER BY t1.b, field1;
|
||||
explain extended
|
||||
SELECT t2.b, t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b, t2.b;
|
||||
explain extended
|
||||
SELECT t2.b,t1.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
|
||||
explain extended
|
||||
SELECT t2.b FROM t1, t2 WHERE t1.b = t2.a GROUP BY t2.b ORDER BY t1.b;
|
||||
|
||||
|
||||
drop table t1,t2;
|
||||
|
||||
--echo End of 5.2 tests
|
||||
|
@ -7368,6 +7368,15 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
|
||||
table_map ref;
|
||||
DBUG_ENTER("remove_const");
|
||||
|
||||
/*
|
||||
Cleanup to avoid interference of calls of this function for
|
||||
ORDER BY and GROUP BY
|
||||
*/
|
||||
for (JOIN_TAB *tab= join->join_tab + join->const_tables;
|
||||
tab < join->join_tab + join->tables;
|
||||
tab++)
|
||||
tab->cached_eq_ref_table= FALSE;
|
||||
|
||||
prev_ptr= &first_order;
|
||||
*simple_order= *join->join_tab[join->const_tables].on_expr_ref ? 0 : 1;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user