mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-30143 Segfault on select query using index for group-by and filesort
The problem was trying to access JOIN_TAB::select which is set to NULL when using the filesort. The correct way is accessing either JOIN_TAB::select or JOIN_TAB::filesort->select depending on whether the filesort is used. This commit introduces member function JOIN_TAB::get_sql_select() encapsulating that check so the code duplication is eliminated. The new condition (s->table->quick_keys.is_set(best_key->key)) was added to best_access_path() to eliminate a Valgrind error. The cause of that error was using TRASH_ALLOC(quick_key_parts) instead of bzero(quick_key_parts); hence, accessing s->table->quick_key_parts[best_key->key]) without prior checking for quick_keys.is_set() might have caused reading "dirty" memory
This commit is contained in:
@ -251,7 +251,28 @@ insert into t2 values (1,repeat("a",1000)),(2,repeat("a",1000)),(3,repeat("b",10
|
||||
SELECT GROUP_CONCAT(t1.language_id SEPARATOR ',') AS `translation_resources`, `d`.`serialized_c` FROM t2 AS `d` LEFT JOIN t1 ON `d`.`voter_id` = t1.`voter_id` GROUP BY `d`.`voter_id` ORDER BY 10-d.voter_id+RAND()*0;
|
||||
drop table t1,t2;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-30143: Segfault on select query using index for group-by and filesort
|
||||
--echo #
|
||||
CREATE TABLE t1 (a varchar(35), b varchar(4)) ENGINE=InnoDB;
|
||||
INSERT INTO t1 VALUES
|
||||
('Albania','AXA'),('Australia','AUS'),('American Samoa','AMSA'),('Bahamas','BS');
|
||||
|
||||
CREATE TABLE t2 (a varchar(4), b varchar(50), PRIMARY KEY (b,a), KEY (a)) ENGINE=InnoDB;
|
||||
INSERT INTO t2 VALUES
|
||||
('BERM','African Methodist Episcopal'),('AUS','Anglican'),('BERM','Anglican'),('BS','Anglican'),('BS','Baptist'),('BS','Methodist');
|
||||
|
||||
let query=
|
||||
SELECT t1.a
|
||||
FROM (SELECT a FROM t2 GROUP BY a ORDER BY COUNT(DISTINCT b) LIMIT 1) dt
|
||||
JOIN t1 ON dt.a=t1.b;
|
||||
--replace_column 9 #
|
||||
eval EXPLAIN $query;
|
||||
eval $query;
|
||||
|
||||
DROP TABLES t1, t2;
|
||||
|
||||
set global innodb_stats_persistent= @innodb_stats_persistent_save;
|
||||
set global innodb_stats_persistent_sample_pages=
|
||||
@innodb_stats_persistent_sample_pages_save;
|
||||
|
||||
|
Reference in New Issue
Block a user