summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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