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:
Igor Babaev 2019-05-01 18:20:06 -07:00
commit 2b7e080fae
3 changed files with 79 additions and 3 deletions

View file

@ -393,4 +393,63 @@ EXPLAIN
}
}
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