mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Bug #41610: key_infix_len can be overwritten causing some group by queries to
return no rows The algorithm of determining the best key for loose index scan is doing a loop over the available indexes and selects the one that has the best cost. It retrieves the parameters of the current index into a set of variables. If the cost of using the current index is lower than the best cost so far it copies these variables into another set of variables that contain the information for the best index so far. After having checked all the indexes it uses these variables (outside of the index loop) to create the table read plan object instance. The was a single omission : the key_infix/key_infix_len variables were used outside of the loop without being preserved in the loop for the best index so far. This causes these variables to get overwritten by the next index(es) checked. Fixed by adding variables to hold the data for the current index, passing the new variables to the function that assigns values to them and copying the new variables into the existing ones when selecting a new current best index. To avoid further such problems moved the declarations of the variables used to keep information about the current index inside the loop's compound statement.
This commit is contained in:
@ -2429,3 +2429,18 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
Warnings:
|
||||
Note 1003 select sql_buffer_result `test`.`t1`.`a` AS `a`,(max(`test`.`t1`.`b`) + 1) AS `max(b)+1` from `test`.`t1` where (`test`.`t1`.`a` = 0) group by `test`.`t1`.`a`
|
||||
drop table t1;
|
||||
CREATE TABLE t1 (a int, b int, c int, d int,
|
||||
KEY foo (c,d,a,b), KEY bar (c,a,b,d));
|
||||
INSERT INTO t1 VALUES (1, 1, 1, 1), (1, 1, 1, 2), (1, 1, 1, 3), (1, 1, 1, 4);
|
||||
INSERT INTO t1 SELECT * FROM t1;
|
||||
INSERT INTO t1 SELECT * FROM t1;
|
||||
INSERT INTO t1 SELECT a,b,c+1,d FROM t1;
|
||||
EXPLAIN SELECT DISTINCT c FROM t1 WHERE d=4;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 range NULL foo 10 NULL 9 Using where; Using index for group-by
|
||||
SELECT DISTINCT c FROM t1 WHERE d=4;
|
||||
c
|
||||
1
|
||||
2
|
||||
DROP TABLE t1;
|
||||
End of 5.0 tests
|
||||
|
@ -935,3 +935,26 @@ insert into t1 (a,b) select a, max(b)+1 from t1 where a = 0 group by a;
|
||||
select * from t1;
|
||||
explain extended select sql_buffer_result a, max(b)+1 from t1 where a = 0 group by a;
|
||||
drop table t1;
|
||||
|
||||
|
||||
#
|
||||
# Bug #41610: key_infix_len can be overwritten causing some group by queries
|
||||
# to return no rows
|
||||
#
|
||||
|
||||
CREATE TABLE t1 (a int, b int, c int, d int,
|
||||
KEY foo (c,d,a,b), KEY bar (c,a,b,d));
|
||||
|
||||
INSERT INTO t1 VALUES (1, 1, 1, 1), (1, 1, 1, 2), (1, 1, 1, 3), (1, 1, 1, 4);
|
||||
INSERT INTO t1 SELECT * FROM t1;
|
||||
INSERT INTO t1 SELECT * FROM t1;
|
||||
INSERT INTO t1 SELECT a,b,c+1,d FROM t1;
|
||||
|
||||
#Should be non-empty
|
||||
--ordered_result
|
||||
EXPLAIN SELECT DISTINCT c FROM t1 WHERE d=4;
|
||||
SELECT DISTINCT c FROM t1 WHERE d=4;
|
||||
|
||||
DROP TABLE t1;
|
||||
|
||||
--echo End of 5.0 tests
|
||||
|
Reference in New Issue
Block a user