Skip to content

Commit d661696

Browse files
spetruniamontywi
authored andcommitted
MDEV-30568: Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
In get_range_limit_read_cost(), handle the case where range_rows=0.
1 parent cc81ea1 commit d661696

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

mysql-test/main/merge.result

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,5 +3945,14 @@ SELECT DISTINCT a FROM tm WHERE a > 50;
39453945
a
39463946
DROP TABLE tm, t1, t2;
39473947
#
3948+
# MDEV-30568 Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
3949+
#
3950+
CREATE TABLE t1 (f INT, KEY(f)) ENGINE=MyISAM;
3951+
CREATE TABLE t2 (f INT, KEY(f)) ENGINE=MyISAM;
3952+
CREATE TABLE tm (f INT, KEY(f)) ENGINE=MERGE UNION = (t1, t2);
3953+
SELECT DISTINCT f FROM tm WHERE f IN (47, 126, 97, 48, 73, 0);
3954+
f
3955+
DROP TABLE tm, t1, t2;
3956+
#
39483957
# End of 11.0 tests
39493958
#

mysql-test/main/merge.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,6 +2905,15 @@ CREATE TABLE tm (a INT, KEY(a)) ENGINE=MRG_MyISAM UNION=(t1,t2);
29052905
SELECT DISTINCT a FROM tm WHERE a > 50;
29062906
DROP TABLE tm, t1, t2;
29072907

2908+
--echo #
2909+
--echo # MDEV-30568 Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
2910+
--echo #
2911+
CREATE TABLE t1 (f INT, KEY(f)) ENGINE=MyISAM;
2912+
CREATE TABLE t2 (f INT, KEY(f)) ENGINE=MyISAM;
2913+
CREATE TABLE tm (f INT, KEY(f)) ENGINE=MERGE UNION = (t1, t2);
2914+
SELECT DISTINCT f FROM tm WHERE f IN (47, 126, 97, 48, 73, 0);
2915+
DROP TABLE tm, t1, t2;
2916+
29082917
--echo #
29092918
--echo # End of 11.0 tests
29102919
--echo #

sql/sql_select.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30475,7 +30475,15 @@ static bool get_range_limit_read_cost(const POSITION *pos,
3047530475
account that using key2 we have to examine much fewer rows.
3047630476
*/
3047730477
best_rows= pos->records_out; // Best rows with any key/keys
30478-
double cond_selectivity= best_rows / range_rows;
30478+
double cond_selectivity;
30479+
/*
30480+
We assign "double range_rows" from integer #rows a few lines above
30481+
so comparison with 0.0 makes sense
30482+
*/
30483+
if (range_rows > 0.0)
30484+
cond_selectivity= best_rows / range_rows;
30485+
else
30486+
cond_selectivity= 1.0;
3047930487
DBUG_ASSERT(cond_selectivity <= 1.000000001);
3048030488
set_if_smaller(cond_selectivity, 1.0);
3048130489

0 commit comments

Comments
 (0)