mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-19363 Assertion `select_lex' failed in LEX::pop_select
This patch corrects the patch for MDEV-19324. The latter did not work properly in the cases when the transformation (SELECT ... ORDER BY ...) LIMIT ... => SELECT ... ORDER BY ... LIMIT ... was applied to the operands of a set operation.
This commit is contained in:
@ -393,4 +393,63 @@ EXPLAIN
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
#
|
||||||
|
# MDEV-19363: ((SELECT ...) ORDER BY col ) LIMIT n UNION ...
|
||||||
|
#
|
||||||
|
create table t1 (pk int);
|
||||||
|
insert into t1 values (5),(4),(1),(2),(3);
|
||||||
|
((select * from t1 order by pk) limit 2) union (select * from t1 where pk > 4);
|
||||||
|
pk
|
||||||
|
1
|
||||||
|
2
|
||||||
|
5
|
||||||
|
explain extended ((select * from t1 order by pk) limit 2) union (select * from t1 where pk > 4);
|
||||||
|
id select_type table type possible_keys key key_len ref rows filtered Extra
|
||||||
|
1 PRIMARY t1 ALL NULL NULL NULL NULL 5 100.00 Using filesort
|
||||||
|
2 UNION t1 ALL NULL NULL NULL NULL 5 100.00 Using where
|
||||||
|
NULL UNION RESULT <union1,2> ALL NULL NULL NULL NULL NULL NULL
|
||||||
|
Warnings:
|
||||||
|
Note 1003 (/* select#1 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` order by `test`.`t1`.`pk` limit 2) union (/* select#2 */ select `test`.`t1`.`pk` AS `pk` from `test`.`t1` where `test`.`t1`.`pk` > 4)
|
||||||
|
explain format=json ((select * from t1 order by pk) limit 2) union (select * from t1 where pk > 4);
|
||||||
|
EXPLAIN
|
||||||
|
{
|
||||||
|
"query_block": {
|
||||||
|
"union_result": {
|
||||||
|
"table_name": "<union1,2>",
|
||||||
|
"access_type": "ALL",
|
||||||
|
"query_specifications": [
|
||||||
|
{
|
||||||
|
"query_block": {
|
||||||
|
"select_id": 1,
|
||||||
|
"read_sorted_file": {
|
||||||
|
"filesort": {
|
||||||
|
"sort_key": "t1.pk",
|
||||||
|
"table": {
|
||||||
|
"table_name": "t1",
|
||||||
|
"access_type": "ALL",
|
||||||
|
"rows": 5,
|
||||||
|
"filtered": 100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"query_block": {
|
||||||
|
"select_id": 2,
|
||||||
|
"operation": "UNION",
|
||||||
|
"table": {
|
||||||
|
"table_name": "t1",
|
||||||
|
"access_type": "ALL",
|
||||||
|
"rows": 5,
|
||||||
|
"filtered": 100,
|
||||||
|
"attached_condition": "t1.pk > 4"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
drop table t1;
|
||||||
# End of 10.4 tests
|
# End of 10.4 tests
|
||||||
|
@ -139,5 +139,20 @@ eval explain format=json $q2;
|
|||||||
|
|
||||||
drop table t1;
|
drop table t1;
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-19363: ((SELECT ...) ORDER BY col ) LIMIT n UNION ...
|
||||||
|
--echo #
|
||||||
|
|
||||||
|
create table t1 (pk int);
|
||||||
|
insert into t1 values (5),(4),(1),(2),(3);
|
||||||
|
|
||||||
|
let $q=
|
||||||
|
((select * from t1 order by pk) limit 2) union (select * from t1 where pk > 4);
|
||||||
|
eval $q;
|
||||||
|
eval explain extended $q;
|
||||||
|
eval explain format=json $q;
|
||||||
|
|
||||||
|
drop table t1;
|
||||||
|
|
||||||
--echo # End of 10.4 tests
|
--echo # End of 10.4 tests
|
||||||
|
|
||||||
|
@ -9147,13 +9147,15 @@ SELECT_LEX *LEX::parsed_select(SELECT_LEX *sel, Lex_order_limit_lock * l)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SELECT_LEX_UNIT *unit= create_unit(sel);
|
|
||||||
if (!unit)
|
|
||||||
return NULL;
|
|
||||||
if (!l->order_list && !sel->explicit_limit)
|
if (!l->order_list && !sel->explicit_limit)
|
||||||
l->order_list= &sel->order_list;
|
l->order_list= &sel->order_list;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
SELECT_LEX_UNIT *unit= create_unit(sel);
|
||||||
|
if (!unit)
|
||||||
|
return NULL;
|
||||||
sel= wrap_unit_into_derived(unit);
|
sel= wrap_unit_into_derived(unit);
|
||||||
|
}
|
||||||
if (!sel)
|
if (!sel)
|
||||||
return NULL;
|
return NULL;
|
||||||
l->set_to(sel);
|
l->set_to(sel);
|
||||||
|
Reference in New Issue
Block a user