mirror of
https://github.com/MariaDB/server.git
synced 2025-01-17 12:32:27 +01:00
cf79c01cc7
Analysis: The crash is a result of incorrect analysis of whether a secondary key can be extended with a primary in order to compute ORDER BY. The analysis is done in test_if_order_by_key(). This function doesn't take into account that the primary key may in fact index the same columns as the secondary key. For the test query test_if_order_by_key says that there is an extended key with total 2 keyparts. At the same time, the condition if (pkinfo->key_part[i].field->key_start.is_set(nr)) in test_if_cheaper_oredring() becomes true for (i == 0), which results in an invalid access to rec_per_key[-1]. Solution: The best solution would be to reuse KEY::ext_key_parts that is already computed by open_binary_frm(), however after detailed analysis the conclusion is that the change would be too intrusive for a GA release. The solution for 5.5 is to add a guard for the case when the 0-th key part is considered, and to assume that all keys will be scanned in this case.
30 lines
970 B
Text
30 lines
970 B
Text
#
|
|
# MDEV-3992 Server crash or valgrind errors in test_if_skip_sort_order/test_if_cheaper_ordering
|
|
# on GROUP BY with indexes on InnoDB table
|
|
#
|
|
CREATE TABLE t1 (
|
|
pk INT PRIMARY KEY,
|
|
a VARCHAR(1) NOT NULL,
|
|
KEY (pk)
|
|
) ENGINE=InnoDB;
|
|
INSERT INTO t1 VALUES (1,'a'),(2,'b');
|
|
EXPLAIN
|
|
SELECT COUNT(*), pk field1, pk AS field2
|
|
FROM t1 WHERE a = 'r' OR pk = 183
|
|
GROUP BY field1, field2;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index PRIMARY,pk pk 4 NULL 2 Using where
|
|
SELECT COUNT(*), pk field1, pk AS field2
|
|
FROM t1 WHERE a = 'r' OR pk = 183
|
|
GROUP BY field1, field2;
|
|
COUNT(*) field1 field2
|
|
EXPLAIN
|
|
SELECT COUNT(*), pk field1 FROM t1
|
|
WHERE a = 'r' OR pk = 183 GROUP BY field1, field1;
|
|
id select_type table type possible_keys key key_len ref rows Extra
|
|
1 SIMPLE t1 index PRIMARY,pk pk 4 NULL 2 Using where
|
|
SELECT COUNT(*), pk field1 FROM t1
|
|
WHERE a = 'r' OR pk = 183 GROUP BY field1, field1;
|
|
COUNT(*) field1
|
|
drop table t1;
|
|
End of 5.5 tests
|