Skip to content

Commit

Permalink
MDEV-30525: Assertion `ranges > 0' fails in IO_AND_CPU_COST
Browse files Browse the repository at this point in the history
Part #2: fix the case where table->stat_records()=1 (due to EITS
statistics), but the range returns rows=0.
  • Loading branch information
spetrunia committed Feb 21, 2023
1 parent d61bc94 commit 9c401c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mysql-test/main/merge.result
Original file line number Diff line number Diff line change
Expand Up @@ -3944,6 +3944,17 @@ 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;
# Testcase 2:
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=MERGE UNION = (t1, t2) INSERT_METHOD=FIRST;
ANALYZE TABLE tm PERSISTENT FOR ALL;
Table Op Msg_type Msg_text
test.tm analyze status Engine-independent statistics collected
test.tm analyze note The storage engine for the table doesn't support analyze
SELECT DISTINCT a FROM (SELECT * FROM tm WHERE a iS NOT NULL) AS sq;
a
DROP TABLE tm, t1, t2;
#
# MDEV-30568 Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
#
Expand Down
8 changes: 8 additions & 0 deletions mysql-test/main/merge.test
Original file line number Diff line number Diff line change
Expand Up @@ -2905,6 +2905,14 @@ 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 # Testcase 2:
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=MERGE UNION = (t1, t2) INSERT_METHOD=FIRST;
ANALYZE TABLE tm PERSISTENT FOR ALL;
SELECT DISTINCT a FROM (SELECT * FROM tm WHERE a iS NOT NULL) AS sq;
DROP TABLE tm, t1, t2;

--echo #
--echo # MDEV-30568 Assertion `cond_selectivity <= 1.000000001' failed in get_range_limit_read_cost
--echo #
Expand Down
11 changes: 11 additions & 0 deletions sql/opt_range.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14527,6 +14527,17 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if ((cur_index_tree= tree->keys[cur_param_idx]))
{
cur_quick_prefix_records= param->quick_rows[cur_index];
if (!cur_quick_prefix_records)
{
/*
Non-constant table has a range with rows=0. Can happen e.g. for
Merge tables. Regular range access will be just as good as loose
scan.
*/
if (unlikely(trace_idx.trace_started()))
trace_idx.add("aborting_search", "range with rows=0");
DBUG_RETURN(NULL);
}
if (unlikely(cur_index_tree && thd->trace_started()))
{
Json_writer_array trace_range(thd, "ranges");
Expand Down

0 comments on commit 9c401c8

Please sign in to comment.