summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 0fad2d6e201..611917ab1a6 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -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");