Skip to content

Commit 706fb79

Browse files
committed
MDEV-10927: Crash When Using sort_union Optimization
In file sql/filesort.cc,when merge_buffers() is called then - queue_remove(&queue,0) is called - For the function queue_remove there is assertion states that the element to be removed should have index >=1 - this is causing the assertion to fail. Fixed by removing the top element.
1 parent 5e051bf commit 706fb79

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

mysql-test/r/index_merge_innodb.result

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,3 +793,32 @@ a b c
793793
9 d d
794794
DROP TABLE t1;
795795
set optimizer_switch= @optimizer_switch_save;
796+
#
797+
# MDEV-10927: Crash When Using sort_union Optimization
798+
#
799+
set @tmp_optimizer_switch=@@optimizer_switch;
800+
SET optimizer_switch='index_merge_sort_intersection=on';
801+
SET SESSION sort_buffer_size = 1024;
802+
create table t1 (
803+
pk int(11) NOT NULL AUTO_INCREMENT,
804+
col1 int(11) NOT NULL,
805+
col2 int(11) NOT NULL,
806+
col3 int(11) NOT NULL,
807+
key2 int(11) NOT NULL,
808+
col4 int(11) NOT NULL,
809+
key1 int(11) NOT NULL,
810+
PRIMARY KEY (pk),
811+
KEY key1 (key1),
812+
KEY key2 (key2)
813+
) ENGINE=InnoDB AUTO_INCREMENT=12860259 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
814+
create table t2(a int);
815+
insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
816+
create table t3(a int);
817+
insert into t3 select A.a + B.a* 10 + C.a * 100 + D.a*1000 from t2 A, t2 B, t2 C, t2 D;
818+
insert into t1 (key1, key2, col1,col2,col3,col4)
819+
select a,a, a,a,a,a from t3;
820+
SELECT sum(col1) FROM t1 FORCE INDEX (key1,key2) WHERE (key1 between 10 and 8191+10) or (key2= 5);
821+
sum(col1)
822+
33632261
823+
drop table t1,t2,t3;
824+
set optimizer_switch=@tmp_optimizer_switch;

mysql-test/t/index_merge_innodb.test

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,37 @@ WHERE ( tb.b != ta.b OR tb.a = ta.a )
171171
AND ( tb.b = ta.c OR tb.b = ta.b );
172172

173173
DROP TABLE t1;
174-
175174
set optimizer_switch= @optimizer_switch_save;
176175

176+
--echo #
177+
--echo # MDEV-10927: Crash When Using sort_union Optimization
178+
--echo #
179+
180+
set @tmp_optimizer_switch=@@optimizer_switch;
181+
SET optimizer_switch='index_merge_sort_intersection=on';
182+
SET SESSION sort_buffer_size = 1024;
183+
184+
create table t1 (
185+
pk int(11) NOT NULL AUTO_INCREMENT,
186+
col1 int(11) NOT NULL,
187+
col2 int(11) NOT NULL,
188+
col3 int(11) NOT NULL,
189+
key2 int(11) NOT NULL,
190+
col4 int(11) NOT NULL,
191+
key1 int(11) NOT NULL,
192+
PRIMARY KEY (pk),
193+
KEY key1 (key1),
194+
KEY key2 (key2)
195+
) ENGINE=InnoDB AUTO_INCREMENT=12860259 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
196+
197+
create table t2(a int);
198+
insert into t2 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
199+
200+
create table t3(a int);
201+
insert into t3 select A.a + B.a* 10 + C.a * 100 + D.a*1000 from t2 A, t2 B, t2 C, t2 D;
202+
203+
insert into t1 (key1, key2, col1,col2,col3,col4)
204+
select a,a, a,a,a,a from t3;
205+
SELECT sum(col1) FROM t1 FORCE INDEX (key1,key2) WHERE (key1 between 10 and 8191+10) or (key2= 5);
206+
drop table t1,t2,t3;
207+
set optimizer_switch=@tmp_optimizer_switch;

sql/filesort.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ int merge_buffers(SORTPARAM *param, IO_CACHE *from_file,
14111411
if (!(error= (int) read_to_buffer(from_file, buffpek,
14121412
rec_length)))
14131413
{
1414-
queue_remove(&queue,0);
1414+
(void) queue_remove_top(&queue);
14151415
reuse_freed_buff(&queue, buffpek, rec_length);
14161416
}
14171417
else if (error == -1)

0 commit comments

Comments
 (0)