Skip to content

Commit 9c401c8

Browse files
committed
MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST
Part #2: fix the case where table->stat_records()=1 (due to EITS statistics), but the range returns rows=0.
1 parent d61bc94 commit 9c401c8

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

mysql-test/main/merge.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,6 +3944,17 @@ CREATE TABLE tm (a INT, KEY(a)) ENGINE=MRG_MyISAM UNION=(t1,t2);
39443944
SELECT DISTINCT a FROM tm WHERE a > 50;
39453945
a
39463946
DROP TABLE tm, t1, t2;
3947+
# Testcase 2:
3948+
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
3949+
CREATE TABLE t2 (a INT, KEY(a)) ENGINE=MyISAM;
3950+
CREATE TABLE tm (a INT, KEY(a)) ENGINE=MERGE UNION = (t1, t2) INSERT_METHOD=FIRST;
3951+
ANALYZE TABLE tm PERSISTENT FOR ALL;
3952+
Table Op Msg_type Msg_text
3953+
test.tm analyze status Engine-independent statistics collected
3954+
test.tm analyze note The storage engine for the table doesn't support analyze
3955+
SELECT DISTINCT a FROM (SELECT * FROM tm WHERE a iS NOT NULL) AS sq;
3956+
a
3957+
DROP TABLE tm, t1, t2;
39473958
#
39483959
# MDEV-30568 Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
39493960
#

mysql-test/main/merge.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,6 +2905,14 @@ 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 # Testcase 2:
2909+
CREATE TABLE t1 (a INT, KEY(a)) ENGINE=MyISAM;
2910+
CREATE TABLE t2 (a INT, KEY(a)) ENGINE=MyISAM;
2911+
CREATE TABLE tm (a INT, KEY(a)) ENGINE=MERGE UNION = (t1, t2) INSERT_METHOD=FIRST;
2912+
ANALYZE TABLE tm PERSISTENT FOR ALL;
2913+
SELECT DISTINCT a FROM (SELECT * FROM tm WHERE a iS NOT NULL) AS sq;
2914+
DROP TABLE tm, t1, t2;
2915+
29082916
--echo #
29092917
--echo # MDEV-30568 Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
29102918
--echo #

sql/opt_range.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14527,6 +14527,17 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
1452714527
if ((cur_index_tree= tree->keys[cur_param_idx]))
1452814528
{
1452914529
cur_quick_prefix_records= param->quick_rows[cur_index];
14530+
if (!cur_quick_prefix_records)
14531+
{
14532+
/*
14533+
Non-constant table has a range with rows=0. Can happen e.g. for
14534+
Merge tables. Regular range access will be just as good as loose
14535+
scan.
14536+
*/
14537+
if (unlikely(trace_idx.trace_started()))
14538+
trace_idx.add("aborting_search", "range with rows=0");
14539+
DBUG_RETURN(NULL);
14540+
}
1453014541
if (unlikely(cur_index_tree && thd->trace_started()))
1453114542
{
1453214543
Json_writer_array trace_range(thd, "ranges");

0 commit comments

Comments
 (0)