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.
This commit is contained in:
Monty 2020-02-27 19:12:27 +02:00
commit f36ca142f7
63 changed files with 333 additions and 188 deletions

View file

@ -579,8 +579,8 @@ int ha_heap::rename_table(const char * from, const char * to)
}
ha_rows ha_heap::records_in_range(uint inx, key_range *min_key,
key_range *max_key)
ha_rows ha_heap::records_in_range(uint inx, const key_range *min_key,
const key_range *max_key, page_range *pages)
{
KEY *key=table->key_info+inx;
if (key->algorithm == HA_KEY_ALG_BTREE)

View file

@ -102,7 +102,8 @@ public:
int disable_indexes(uint mode);
int enable_indexes(uint mode);
int indexes_are_disabled(void);
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_table(const char *from);
void drop_table(const char *name);
int rename_table(const char * from, const char * to);

View file

@ -55,8 +55,9 @@ static ulong hp_hashnr(HP_KEYDEF *keydef, const uchar *key);
the range.
*/
ha_rows hp_rb_records_in_range(HP_INFO *info, int inx, key_range *min_key,
key_range *max_key)
ha_rows hp_rb_records_in_range(HP_INFO *info, int inx,
const key_range *min_key,
const key_range *max_key)
{
ha_rows start_pos, end_pos;
HP_KEYDEF *keyinfo= info->s->keydef + inx;