Commit 5faf2ac0 authored by Sergei Petrunia's avatar Sergei Petrunia Committed by Monty

MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST handler::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.
parent 00704aff
......@@ -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
#
......@@ -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 #
......@@ -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)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment