summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Petrunia <sergey@mariadb.com>2023-02-09 12:52:20 +0300
committerSergei Petrunia <sergey@mariadb.com>2023-02-10 14:40:09 +0300
commit62531b0df82b98055d0c29b3a9bdb2154657c3b0 (patch)
tree35d212f97e30d1b483b0dd38541d24643dea882f
parentb3bdb41d492130b5b1f65523d97f47375db071e8 (diff)
downloadmariadb-git-62531b0df82b98055d0c29b3a9bdb2154657c3b0.tar.gz
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.
-rw-r--r--mysql-test/main/merge.result11
-rw-r--r--mysql-test/main/merge.test8
-rw-r--r--sql/opt_range.cc11
3 files changed, 30 insertions, 0 deletions
diff --git a/mysql-test/main/merge.result b/mysql-test/main/merge.result
index 820372efe85..1eecb3e34ca 100644
--- a/mysql-test/main/merge.result
+++ b/mysql-test/main/merge.result
@@ -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
#
diff --git a/mysql-test/main/merge.test b/mysql-test/main/merge.test
index 8da9e7b3a1c..6b88d427fb4 100644
--- a/mysql-test/main/merge.test
+++ b/mysql-test/main/merge.test
@@ -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 #
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index f2696683124..71f48a9601e 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -14528,6 +14528,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");