Browse Source

MDEV-35571 Check for LIMIT ROWS EXAMINED exceeded in UNION ALL

When UNION ALL is used with LIMIT ROWS EXAMINED, and when the limit is
exceeded for a SELECT that is not the last in the UNION, interrupt the
execution and call end_eof on the result. This makes sure that the
results are sent, and the query result status is conclusive rather
than empty, which would cause an assertion failure.
pull/3597/head
Yuchen Pei 11 months ago
parent
commit
432856c473
No known key found for this signature in database GPG Key ID: 3DD1B35105743563
  1. 43
      mysql-test/main/limit_rows_examined.result
  2. 41
      mysql-test/main/limit_rows_examined.test
  3. 3
      sql/sql_union.cc

43
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

41
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

3
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;

Loading…
Cancel
Save