diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result index 71b99d066ff..0711e10ddde 100644 --- a/mysql-test/main/limit_rows_examined.result +++ b/mysql-test/main/limit_rows_examined.result @@ -864,3 +864,18 @@ Warnings: Warning 1931 Query execution was interrupted. The query examined at least 22 rows, which exceeds LIMIT ROWS EXAMINED (21). The query result may be incomplete drop view v; drop table t1, t2; +# +# MDEV-18117: Crash with Explain extended when using limit rows examined +# +create table t1 (c1 char(2)); +create table t2 (c2 char(2)); +insert into t1 values ('bb'), ('cc'), ('aa'), ('dd'); +insert into t2 values ('bb'), ('cc'), ('dd'), ('ff'); +explain extended +select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 2; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 100.00 +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where; Using join buffer (flat, BNL join) +Warnings: +Note 1003 select `test`.`t1`.`c1` AS `c1`,`test`.`t2`.`c2` AS `c2` from `test`.`t1` join `test`.`t2` where `test`.`t2`.`c2` = `test`.`t1`.`c1` +drop table t1,t2; diff --git a/mysql-test/main/limit_rows_examined.test b/mysql-test/main/limit_rows_examined.test index 815394aec5c..528bb8c7b3d 100644 --- a/mysql-test/main/limit_rows_examined.test +++ b/mysql-test/main/limit_rows_examined.test @@ -576,3 +576,15 @@ EXECUTE ps; drop view v; drop table t1, t2; + +--echo # +--echo # MDEV-18117: Crash with Explain extended when using limit rows examined +--echo # + +create table t1 (c1 char(2)); +create table t2 (c2 char(2)); +insert into t1 values ('bb'), ('cc'), ('aa'), ('dd'); +insert into t2 values ('bb'), ('cc'), ('dd'), ('ff'); +explain extended +select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 2; +drop table t1,t2; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 7be705a9090..d09aa85d402 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -12653,7 +12653,7 @@ limit_clause: { $$.select_limit= 0; $$.offset_limit= 0; - $$.explicit_limit= 1; + $$.explicit_limit= 0; Lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_LIMIT); } ;