Skip to content

Commit

Permalink
MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST handler::…
Browse files Browse the repository at this point in the history
…keyread_time

Make get_best_group_min_max() exit early if the table has
table->records()=0. Attempting to compute loose scan over 0
groups eventually causes an assert when trying to get the
cost of reading 0 ranges.
  • Loading branch information
spetrunia authored and montywi committed Feb 10, 2023
1 parent 00704af commit 5faf2ac
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions mysql-test/main/merge.result
Original file line number Diff line number Diff line change
Expand Up @@ -3936,5 +3936,14 @@ SELECT a, COUNT(*) FROM t1 WHERE a >= '2000-01-01 00:00:00' GROUP BY a;
a COUNT(*)
DROP TABLE t1;
#
# MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST handler::keyread_time
#
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
CREATE TABLE t2 (a INT, KEY(a)) ENGINE=MyISAM;
CREATE TABLE tm (a INT, KEY(a)) ENGINE=MRG_MyISAM UNION=(t1,t2);
SELECT DISTINCT a FROM tm WHERE a > 50;
a
DROP TABLE tm, t1, t2;
#
# End of 11.0 tests
#
9 changes: 9 additions & 0 deletions mysql-test/main/merge.test
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,15 @@ explain SELECT a, COUNT(*) FROM t1 WHERE a >= '2000-01-01 00:00:00' GROUP BY a;
SELECT a, COUNT(*) FROM t1 WHERE a >= '2000-01-01 00:00:00' GROUP BY a;
DROP TABLE t1;

--echo #
--echo # MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST handler::keyread_time
--echo #
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
CREATE TABLE t2 (a INT, KEY(a)) ENGINE=MyISAM;
CREATE TABLE tm (a INT, KEY(a)) ENGINE=MRG_MyISAM UNION=(t1,t2);
SELECT DISTINCT a FROM tm WHERE a > 50;
DROP TABLE tm, t1, t2;

--echo #
--echo # End of 11.0 tests
--echo #
2 changes: 2 additions & 0 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14049,6 +14049,8 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
else if (join->conds && join->conds->used_tables()
& OUTER_REF_TABLE_BIT) // Cannot execute with correlated conditions.
cause= "correlated conditions";
else if (table->stat_records() == 0)
cause= "Empty table"; // Exit now, records=0 messes up cost computations

if (cause)
{
Expand Down

0 comments on commit 5faf2ac

Please sign in to comment.