From 9a80cab74d5ccef3d4a79e9b94830a9dd6f520b2 Mon Sep 17 00:00:00 2001 From: Nayuta Yanagisawa Date: Tue, 20 Sep 2022 21:28:19 +0900 Subject: MDEV-24283 Assertion `bitmap_is_set(&m_part_info->read_partitions, m_part_spec.start_part)' failed in ha_partition::handle_ordered_index_scan 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. --- mysql-test/suite/parts/r/partition_all_pruned_away.result | 5 +++++ mysql-test/suite/parts/t/partition_all_pruned_away.test | 11 +++++++++++ sql/opt_sum.cc | 5 +++++ 3 files changed, 21 insertions(+) create mode 100644 mysql-test/suite/parts/r/partition_all_pruned_away.result create mode 100644 mysql-test/suite/parts/t/partition_all_pruned_away.test 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 -- cgit v1.2.1