Commit 4ae2a9a7 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-4610 SQL query crashes MariaDB with derived_with_keys

MDEV-4643 MariaDB crashes consistently when trying a SELECT on VIEW with a UNION and an additional JOIN in SELECT

open derived temp tables *before* trying QUICK_SELECT for them,
handler::multi_range_read_info() needs an open table.
parent 45809273
create table t1 (f1 char(4) primary key) engine=innodb charset=utf8 ;
insert into t1 values ('aaaa');
create table t2 (f2 text, f3 char(4) not null) engine=innodb charset=utf8 ;
create table t3 (id int not null) engine=innodb charset=utf8 ;
create table t4 (val int not null) engine=innodb charset=utf8;
explain select 1 from
(select f2, f3, val, count(id) from t4 join t2 left join t3 on 0) top
join t1 on f1 = f3 where f3 = 'aaaa' order by val;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 const PRIMARY PRIMARY 12 const 1 Using index; Using filesort
1 PRIMARY <derived2> ref key0 key0 13 const 0 Using where
2 DERIVED t4 ALL NULL NULL NULL NULL 1
2 DERIVED t2 ALL NULL NULL NULL NULL 1 Using join buffer (flat, BNL join)
2 DERIVED t3 ALL NULL NULL NULL NULL 1 Using where; Using join buffer (incremental, BNL join)
select 1 from
(select f2, f3, val, count(id) from t4 join t2 left join t3 on 0) top
join t1 on f1 = f3 where f3 = 'aaaa' order by val;
1
drop table t1, t2, t3, t4;
#
# MDEV-4610 SQL query crashes MariaDB with derived_with_keys
#
--source include/have_innodb.inc
create table t1 (f1 char(4) primary key) engine=innodb charset=utf8 ;
insert into t1 values ('aaaa');
create table t2 (f2 text, f3 char(4) not null) engine=innodb charset=utf8 ;
create table t3 (id int not null) engine=innodb charset=utf8 ;
create table t4 (val int not null) engine=innodb charset=utf8;
explain select 1 from
(select f2, f3, val, count(id) from t4 join t2 left join t3 on 0) top
join t1 on f1 = f3 where f3 = 'aaaa' order by val;
select 1 from
(select f2, f3, val, count(id) from t4 join t2 left join t3 on 0) top
join t1 on f1 = f3 where f3 = 'aaaa' order by val;
drop table t1, t2, t3, t4;
......@@ -18941,6 +18941,9 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
MYF(MY_WME | MY_ZEROFILL));
table->status=0; // May be wrong if quick_select
if (!tab->preread_init_done && tab->preread_init())
goto err;
// If table has a range, move it to select
if (select && !select->quick && tab->ref.key >= 0)
{
......@@ -18977,8 +18980,6 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order,
get_schema_tables_result(join, PROCESSED_BY_CREATE_SORT_INDEX))
goto err;
if (!tab->preread_init_done && tab->preread_init())
goto err;
if (table->s->tmp_table)
table->file->info(HA_STATUS_VARIABLE); // Get record count
table->sort.found_records=filesort(thd, table,join->sortorder, length,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment