1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

MDEV-31162 Crash for query using ROWNUM over multi-table view with ORDER BY

This bug could cause a crash of the server when processing a query with
ROWNUM() if it used in its FROM list a reference to a mergeable view
defined as SELECT over more than one table that contained ORDER BY clause.
When a mergeable view with ORDER BY clause and without LIMIT clause is used
in the FROM list of a query that does not have ORDER BY clause the ORDER BY
clause of the view is moved to the query. The code that performed this
transformation forgot to delete the moved ORDER BY list from the view.
If a query contains ROWNUM() and uses a mergeable multi-table view with
ORDER BY then according to the current code of TABLE_LIST::init_derived()
the view has to be forcibly materialized. As the query and the view shared
the same items in its ORDER BY lists they could not be properly resolved
either in the query or in the view. This led to a crash of the server.

This patch has returned back the original signature of LEX::can_not_use_merged()
to comply with 10.4 code of the condition that checks whether a megeable
view has to be forcibly materialized.

Approved by Oleksandr Byelkin <sanja@mariadb.com>
This commit is contained in:
Igor Babaev
2023-05-02 00:31:57 -07:00
parent 5f3a4beb9d
commit fe89df4268
6 changed files with 98 additions and 9 deletions

View File

@ -4190,4 +4190,52 @@ Warnings:
Warning 1287 '@@big_tables' is deprecated and will be removed in a future release
drop view v;
drop table t1, t2;
#
# MDEV-31162: multi-table mergeable view with ORDER BY used
# in query with rownum() in WHERE
#
create table t1 (a INT) engine=MyISAM;
insert into t1 values (1),(2);
create table t2 (b INT) engine=MyISAM;
insert into t2 values (3),(4);
create view v1 AS select * from t1 join t2 order by b;
explain select * from v1 where rownum() <= 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
select * from v1 where rownum() <= 2;
a b
1 3
2 3
prepare stmt from "select * from v1 where rownum() <= 2";
execute stmt;
a b
1 3
2 3
execute stmt;
a b
1 3
2 3
deallocate prepare stmt;
create view v2 AS select * from t1 join t2 order by b/a;
explain select * from v2 where rownum() <= 2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
1 SIMPLE t2 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
select * from v2 where rownum() <= 2;
a b
2 3
1 3
prepare stmt from "select * from v2 where rownum() <= 2";
execute stmt;
a b
2 3
1 3
execute stmt;
a b
2 3
1 3
deallocate prepare stmt;
drop view v1,v2;
drop table t1,t2;
# End of 10.6 tests