revision-id: 571cb7746222ea2e19c0cf220ec54b61da834079 (mariadb-10.1.43-112-g571cb774622) parent(s): ad4b70562bb94dd063eebde5189c6e730d3120a2 author: Varun Gupta committer: Varun Gupta timestamp: 2020-04-20 18:25:19 +0530 message: MDEV-22241: Assertion `0' failed in Protocol::end_statement after query with LIMIT ROWS EXAMINED When the query is aborted because the rows examined are greater than what was specified by the user, make sure to not throw an error at the JOIN::optimize phase. This case would only arise when we are trying to open constant tables during the optimization phase. --- mysql-test/r/limit_rows_examined.result | 12 ++++++++++++ mysql-test/t/limit_rows_examined.test | 13 +++++++++++++ sql/sql_select.cc | 11 ++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/limit_rows_examined.result b/mysql-test/r/limit_rows_examined.result index 0b3bc196a31..1c708aaf102 100644 --- a/mysql-test/r/limit_rows_examined.result +++ b/mysql-test/r/limit_rows_examined.result @@ -853,3 +853,15 @@ 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-22241: Assertion `0' failed in Protocol::end_statement after query with LIMIT ROWS EXAMINED +# +CREATE TABLE t1 (a int PRIMARY KEY, b varchar(1)); +INSERT INTO t1 VALUES (262,'8'), (179, '9'); +SELECT 1 FROM t1 +WHERE (1 IN (SELECT 8 UNION SELECT 5)) OR t1.a = 140 +LIMIT ROWS EXAMINED 1; +1 +Warnings: +Warning 1931 Query execution was interrupted. The query examined at least 2 rows, which exceeds LIMIT ROWS EXAMINED (1). The query result may be incomplete. +drop table t1; diff --git a/mysql-test/t/limit_rows_examined.test b/mysql-test/t/limit_rows_examined.test index 45ee483c7aa..9686f9ff132 100644 --- a/mysql-test/t/limit_rows_examined.test +++ b/mysql-test/t/limit_rows_examined.test @@ -576,3 +576,16 @@ EXECUTE ps; drop view v; drop table t1, t2; + +--echo # +--echo # MDEV-22241: Assertion `0' failed in Protocol::end_statement after query with LIMIT ROWS EXAMINED +--echo # + +CREATE TABLE t1 (a int PRIMARY KEY, b varchar(1)); +INSERT INTO t1 VALUES (262,'8'), (179, '9'); + +SELECT 1 FROM t1 +WHERE (1 IN (SELECT 8 UNION SELECT 5)) OR t1.a = 140 +LIMIT ROWS EXAMINED 1; + +drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 647dee80188..d8ff9ac975d 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4279,7 +4279,16 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, DEBUG_SYNC(join->thd, "inside_make_join_statistics"); /* Generate an execution plan from the found optimal join order. */ - DBUG_RETURN(join->thd->check_killed() || get_best_combination(join)); + + if (join->thd->check_killed()) + { + if (join->thd->killed == ABORT_QUERY && !join->thd->no_errors) + error= 0; + else + DBUG_RETURN(1); + } + + DBUG_RETURN(get_best_combination(join)); error: /*