[Commits] 0ae0f6571c2: Issue #790, MyRocks/MRR: make ref(const) access switch to MRR
revision-id: 0ae0f6571c234ab00a16005da0db15fafc6fe98c (fb-prod201903-165-g0ae0f6571c2) parent(s): 803de702568dc7867075a434cbeca1e3c7e2782a author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2019-09-16 23:30:13 +0300 message: Issue #790, MyRocks/MRR: make ref(const) access switch to MRR Do the switch only if the storage engine requests it by setting the HA_MRR_CONVERT_REF_TO_RANGE flag. --- sql/handler.h | 13 +++++++++++++ sql/sql_optimizer.cc | 21 ++++++++++++++++----- storage/rocksdb/ha_rocksdb.cc | 4 ++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/sql/handler.h b/sql/handler.h index 3dd40c88881..4f68fcb6bcc 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1834,8 +1834,21 @@ void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted, */ #define HA_MRR_SUPPORT_SORTED 256 +/* + SQL layer passes this as an argument to multi_range_read_info() to indicate + that the lookup keys are full extended keys for the index +*/ #define HA_MRR_FULL_EXTENDED_KEYS 512 +/* + MRR implementation returns this flag to indicate that when the optimizer has + a choice between + - ref(const) access (which doesnt use the MRR interface) + - range access (which does use MRR interface) + the latter should be preferred. +*/ +#define HA_MRR_CONVERT_REF_TO_RANGE 1024 + class ha_statistics { public: diff --git a/sql/sql_optimizer.cc b/sql/sql_optimizer.cc index 219ddc5d50f..e170e674e08 100644 --- a/sql/sql_optimizer.cc +++ b/sql/sql_optimizer.cc @@ -8324,7 +8324,9 @@ only_eq_ref_tables(JOIN *join, ORDER *order, table_map tables, @param thd THD To re-run range optimizer. @param tab JOIN_TAB To check the above conditions. - @return Pointer Range is better than ref + @return Pointer Range is better than ref. The pointer points to a string + describing why (the string is intended to be used in the + optimizer trace) @return nullptr Ref is better or switch isn't possible @todo: This decision should rather be made in best_access_path() @@ -8334,13 +8336,22 @@ static const char* can_switch_from_ref_to_range(THD *thd, JOIN_TAB *tab) if (!tab->ref.depend_map && // 1) tab->quick) // 2) { - // MRR use: TODO: check if quick would have used MRR: + /* + If there was a quick select that + - was scanning the same range + - used MRR + - MRR implementation indicated that it's preferred to use MRR over + ref(const). + then switch to range access as it will read rows using the MRR interface + */ if ((uint) tab->ref.key == tab->quick->index && tab->ref.key_length == tab->quick->max_used_key_length && - tab->quick->get_type() == QUICK_SELECT_I::QS_TYPE_RANGE && - !(((QUICK_RANGE_SELECT*)tab->quick)->mrr_flags & - HA_MRR_USE_DEFAULT_IMPL)) + tab->quick->get_type() == QUICK_SELECT_I::QS_TYPE_RANGE) { + QUICK_RANGE_SELECT *qr = (QUICK_RANGE_SELECT*)tab->quick; + if (!(qr->mrr_flags & HA_MRR_USE_DEFAULT_IMPL) && + (qr->mrr_flags & HA_MRR_CONVERT_REF_TO_RANGE)) return "uses_mrr"; + } if ((uint) tab->ref.key == tab->quick->index && // 3a) tab->ref.key_length < tab->quick->max_used_key_length) // 3b) diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index 94b8c3741f3..993cfe1abce 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -15175,6 +15175,7 @@ ha_rows ha_rocksdb::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq, if (all_eq_ranges) { // Indicate that we will use Mutlit-Get MRR *flags &= ~HA_MRR_USE_DEFAULT_IMPL; + *flags |= HA_MRR_CONVERT_REF_TO_RANGE; *flags |= HA_MRR_SUPPORT_SORTED; *bufsz = mrr_get_length_per_rec() * res * 1.1 + 1; } @@ -15184,6 +15185,7 @@ ha_rows ha_rocksdb::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq, if (!(*flags & HA_MRR_INDEX_ONLY)) { *flags &= ~HA_MRR_SUPPORT_SORTED; // Non-sorted mode *flags &= ~HA_MRR_USE_DEFAULT_IMPL; + *flags |= HA_MRR_CONVERT_REF_TO_RANGE; *bufsz = mrr_get_length_per_rec() * res * 1.1 + 1; } } @@ -15207,11 +15209,13 @@ ha_rows ha_rocksdb::multi_range_read_info(uint keyno, uint n_ranges, uint keys, if (keyno == table->s->primary_key && (*flags & HA_MRR_FULL_EXTENDED_KEYS)) { *flags &= ~HA_MRR_USE_DEFAULT_IMPL; + *flags |= HA_MRR_CONVERT_REF_TO_RANGE; *flags |= HA_MRR_SUPPORT_SORTED; } if (keyno != table->s->primary_key && !(*flags & HA_MRR_INDEX_ONLY)) { *flags &= ~HA_MRR_USE_DEFAULT_IMPL; + *flags |= HA_MRR_CONVERT_REF_TO_RANGE; *flags &= ~HA_MRR_SUPPORT_SORTED; // Non-sorted mode }
participants (1)
-
Sergei Petrunia