diff --git a/mysql-test/main/limit_rows_examined.result b/mysql-test/main/limit_rows_examined.result index 50b542fa5fe..7bea8862c18 100644 --- a/mysql-test/main/limit_rows_examined.result +++ b/mysql-test/main/limit_rows_examined.result @@ -895,3 +895,46 @@ 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; # End of 10.4 tests +# +# MDEV-35571: Connection hangs after query on a partitioned table with UNION and LIMIT ROWS EXAMINED +# +create table t1 (a int); +insert into t1 values (1), (2); +select * from t1 UNION ALL select * from t1 LIMIT ROWS EXAMINED 1; +a +1 +Warnings: +Warning 1931 Query execution was interrupted. The query exceeded LIMIT ROWS EXAMINED 1. The query result may be incomplete +select * from t1 UNION DISTINCT select * from t1 LIMIT ROWS EXAMINED 1; +a +1 +Warnings: +Warning 1931 Query execution was interrupted. The query exceeded LIMIT ROWS EXAMINED 1. The query result may be incomplete +DROP TABLE t1; +create table t1 (a int); +insert into t1 values (1), (2); +(select a from t1 UNION ALL select a from t1) order by a desc LIMIT ROWS EXAMINED 2; +a +1 +Warnings: +Warning 1931 Query execution was interrupted. The query exceeded LIMIT ROWS EXAMINED 2. The query result may be incomplete +(select a from t1 UNION DISTINCT select a from t1) order by a desc LIMIT ROWS EXAMINED 2; +a +1 +Warnings: +Warning 1931 Query execution was interrupted. The query exceeded LIMIT ROWS EXAMINED 2. The query result may be incomplete +DROP TABLE t1; +CREATE TABLE t1 (a INT); +INSERT INTO t1 SELECT seq%25 FROM seq_1_to_100; +CREATE TABLE t2 (b INT, c INT, KEY(b)) PARTITION BY HASH(c) PARTITIONS 12; +INSERT INTO t2 SELECT seq, seq FROM seq_1_to_10; +SELECT COUNT(*) FROM t1 JOIN t2 ON (b = a) UNION ALL SELECT COUNT(*) FROM t1 JOIN t2 ON (b = a) LIMIT ROWS EXAMINED 100; +COUNT(*) +Warnings: +Warning 1931 Query execution was interrupted. The query exceeded LIMIT ROWS EXAMINED 100. The query result may be incomplete +SELECT COUNT(*) FROM t1 JOIN t2 ON (b = a) UNION DISTINCT SELECT COUNT(*) FROM t1 JOIN t2 ON (b = a) LIMIT ROWS EXAMINED 100; +COUNT(*) +Warnings: +Warning 1931 Query execution was interrupted. The query exceeded LIMIT ROWS EXAMINED 100. The query result may be incomplete +DROP TABLE t1, t2; +# End of 10.5 tests diff --git a/mysql-test/main/limit_rows_examined.test b/mysql-test/main/limit_rows_examined.test index 94bbf8e819a..12c75121dfb 100644 --- a/mysql-test/main/limit_rows_examined.test +++ b/mysql-test/main/limit_rows_examined.test @@ -617,3 +617,44 @@ select * from t1, t2 where c1 = c2 LIMIT ROWS EXAMINED 2; drop table t1,t2; --echo # End of 10.4 tests + +--echo # +--echo # MDEV-35571: Connection hangs after query on a partitioned table with UNION and LIMIT ROWS EXAMINED +--echo # + +--source include/have_partition.inc +--source include/have_sequence.inc + +# Simplified test +create table t1 (a int); +insert into t1 values (1), (2); +select * from t1 UNION ALL select * from t1 LIMIT ROWS EXAMINED 1; +# UNION DISTINCT produces the same result here. Note that this is not +# affected by the MDEV-35571 patch +select * from t1 UNION DISTINCT select * from t1 LIMIT ROWS EXAMINED 1; +DROP TABLE t1; + +# Simplified test with order by +create table t1 (a int); +insert into t1 values (1), (2); +(select a from t1 UNION ALL select a from t1) order by a desc LIMIT ROWS EXAMINED 2; +# UNION DISTINCT produces the same result with order by desc. Note +# that this is not affected by the MDEV-35571 patch +(select a from t1 UNION DISTINCT select a from t1) order by a desc LIMIT ROWS EXAMINED 2; +DROP TABLE t1; + +# Original test +CREATE TABLE t1 (a INT); +INSERT INTO t1 SELECT seq%25 FROM seq_1_to_100; + +CREATE TABLE t2 (b INT, c INT, KEY(b)) PARTITION BY HASH(c) PARTITIONS 12; +INSERT INTO t2 SELECT seq, seq FROM seq_1_to_10; + +SELECT COUNT(*) FROM t1 JOIN t2 ON (b = a) UNION ALL SELECT COUNT(*) FROM t1 JOIN t2 ON (b = a) LIMIT ROWS EXAMINED 100; +# UNION DISTINCT produces the same result here. Note that this is not +# affected by the MDEV-35571 patch +SELECT COUNT(*) FROM t1 JOIN t2 ON (b = a) UNION DISTINCT SELECT COUNT(*) FROM t1 JOIN t2 ON (b = a) LIMIT ROWS EXAMINED 100; + +DROP TABLE t1, t2; + +--echo # End of 10.5 tests diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 8cbb35fc9a4..53e604bfa92 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -1026,7 +1026,8 @@ bool select_union_direct::send_eof() // Reset for each SELECT_LEX, so accumulate here limit_found_rows+= thd->limit_found_rows; - if (unit->thd->lex->current_select == last_select_lex) + if (unit->thd->lex->current_select == last_select_lex || + thd->killed == ABORT_QUERY) { thd->limit_found_rows= limit_found_rows;