From f36ca142f7fa59598e34e842b60372b963067766 Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 27 Feb 2020 19:12:27 +0200 Subject: Added page_range to records_in_range() to improve range statistics Prototype change: - virtual ha_rows records_in_range(uint inx, key_range *min_key, - key_range *max_key) + virtual ha_rows records_in_range(uint inx, const key_range *min_key, + const key_range *max_key, + page_range *res) The handler can ignore the page_range parameter. In the case the handler updates the parameter, the optimizer can deduce the following: - If previous range's last key is on the same block as next range's first key - If the current key range is in one block - We can also assume that the first and last block read are cached! This can be used for a better calculation of IO seeks when we estimate the cost of a range index scan. The parameter is fully implemented for MyISAM, Aria and InnoDB. A separate patch will update handler::multi_range_read_info_const() to take the benefits of this change and also remove the double records_in_range() calls that are not anymore needed. --- storage/myisammrg/ha_myisammrg.cc | 9 ++++++--- storage/myisammrg/ha_myisammrg.h | 3 ++- storage/myisammrg/myrg_range.c | 11 +++++++++-- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'storage/myisammrg') diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 4fd63020c6a..2a7ca8d51f8 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -1216,11 +1216,14 @@ void ha_myisammrg::position(const uchar *record) } -ha_rows ha_myisammrg::records_in_range(uint inx, key_range *min_key, - key_range *max_key) +ha_rows ha_myisammrg::records_in_range(uint inx, + const key_range *min_key, + const key_range *max_key, + page_range *pages) { DBUG_ASSERT(this->file->children_attached); - return (ha_rows) myrg_records_in_range(file, (int) inx, min_key, max_key); + return (ha_rows) myrg_records_in_range(file, (int) inx, min_key, max_key, + pages); } diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index b7cbd6c7d12..d5d62a002aa 100644 --- a/storage/myisammrg/ha_myisammrg.h +++ b/storage/myisammrg/ha_myisammrg.h @@ -129,7 +129,8 @@ public: int rnd_next(uchar *buf); int rnd_pos(uchar * buf, uchar *pos); void position(const uchar *record); - ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); + ha_rows records_in_range(uint inx, const key_range *start_key, + const key_range *end_key, page_range *pages); int delete_all_rows(); int info(uint); int reset(void); diff --git a/storage/myisammrg/myrg_range.c b/storage/myisammrg/myrg_range.c index 893bda20833..da5e2c38d68 100644 --- a/storage/myisammrg/myrg_range.c +++ b/storage/myisammrg/myrg_range.c @@ -17,14 +17,21 @@ #include "myrg_def.h" ha_rows myrg_records_in_range(MYRG_INFO *info, int inx, - key_range *min_key, key_range *max_key) + const key_range *min_key, + const key_range *max_key, + page_range *pages) { ha_rows records=0, res; MYRG_TABLE *table; + page_range ignore_pages; + + /* Don't calculate pages of more than one active partition */ + if (info->open_tables +1 != info->end_table) + pages= &ignore_pages; for (table=info->open_tables ; table != info->end_table ; table++) { - res= mi_records_in_range(table->table, inx, min_key, max_key); + res= mi_records_in_range(table->table, inx, min_key, max_key, pages); if (res == HA_POS_ERROR) return HA_POS_ERROR; if (records > HA_POS_ERROR - res) -- cgit v1.2.1