summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNayuta Yanagisawa <nayuta.yanagisawa@hey.com>2022-09-20 21:28:19 +0900
committerNayuta Yanagisawa <nayuta.yanagisawa@hey.com>2022-09-21 14:21:28 +0900
commit9a80cab74d5ccef3d4a79e9b94830a9dd6f520b2 (patch)
treef01804486d41486119622fe508ae642e6ba30802
parent65b4a2afb8fc734352359edfbae32cb2b0ef4f7a (diff)
downloadmariadb-git-bb-10.3-MDEV-24283.tar.gz
MDEV-24283 Assertion `bitmap_is_set(&m_part_info->read_partitions, m_part_spec.start_part)' failed in ha_partition::handle_ordered_index_scanbb-10.3-MDEV-24283
On the optimization of MAX/MIN clauses by opt_sum_query(), the optimizer tries to access a partitioned table, even though all the partitions of the table have been pruned away in a earlier stage. This leads to the assertion error. We stop the optimization by opt_sum_query() if all the partitions were pruned way.
-rw-r--r--mysql-test/suite/parts/r/partition_all_pruned_away.result5
-rw-r--r--mysql-test/suite/parts/t/partition_all_pruned_away.test11
-rw-r--r--sql/opt_sum.cc5
3 files changed, 21 insertions, 0 deletions
diff --git a/mysql-test/suite/parts/r/partition_all_pruned_away.result b/mysql-test/suite/parts/r/partition_all_pruned_away.result
new file mode 100644
index 00000000000..76dec662fd3
--- /dev/null
+++ b/mysql-test/suite/parts/r/partition_all_pruned_away.result
@@ -0,0 +1,5 @@
+CREATE TABLE t (c INT KEY) PARTITION BY LIST (c) (PARTITION p VALUES IN (0));
+SELECT MAX(c) FROM t WHERE c>0;
+MAX(c)
+NULL
+DROP TABLE t;
diff --git a/mysql-test/suite/parts/t/partition_all_pruned_away.test b/mysql-test/suite/parts/t/partition_all_pruned_away.test
new file mode 100644
index 00000000000..e890d12f1ea
--- /dev/null
+++ b/mysql-test/suite/parts/t/partition_all_pruned_away.test
@@ -0,0 +1,11 @@
+#
+# MDEV-24283 Assertion `bitmap_is_set(&m_part_info->read_partitions, m_part_spec.start_part)' failed in ha_partition::handle_ordered_index_scan
+#
+--source include/have_partition.inc
+
+CREATE TABLE t (c INT KEY) PARTITION BY LIST (c) (PARTITION p VALUES IN (0));
+#SELECT MAX(c) FROM t WHERE c >= 0;
+SELECT MAX(c) FROM t WHERE c>0;
+
+# Cleanup
+DROP TABLE t;
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index a6c56bbea37..4d82ee70096 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -383,6 +383,11 @@ int opt_sum_query(THD *thd,
Item_field *item_field= (Item_field*) (expr->real_item());
TABLE *table= item_field->field->table;
+#ifdef WITH_PARTITION_STORAGE_ENGINE
+ if (table->all_partitions_pruned_away)
+ DBUG_RETURN(HA_ERR_KEY_NOT_FOUND); // No rows matching WHERE
+#endif
+
/*
Look for a partial key that can be used for optimization.
If we succeed, ref.key_length will contain the length of