From d903396c18f1660be3b55f57758c7d8362a3b13b Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 2 Dec 2016 21:08:08 +0000 Subject: [PATCH] MDEV-11321: MariaRocks: type_binary_indexes, type_blob_indexes fail ... due to different index statistics Make statistics calculations in MariaRocks produce the same values that MyRocks produces. Added a comment in rdb_datadic.cc --- storage/rocksdb/ha_rocksdb.cc | 16 +++++++++++++++- storage/rocksdb/rdb_datadic.cc | 7 ++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/storage/rocksdb/ha_rocksdb.cc b/storage/rocksdb/ha_rocksdb.cc index ecfc6a2f3d8..b55daff426c 100644 --- a/storage/rocksdb/ha_rocksdb.cc +++ b/storage/rocksdb/ha_rocksdb.cc @@ -8464,11 +8464,25 @@ int ha_rocksdb::info(uint flag) if ((x == 0 && rocksdb_debug_optimizer_no_zero_cardinality) || rocksdb_debug_optimizer_n_rows > 0) { + /* + Make MariaRocks behave the same way as MyRocks does: + 1. SQL layer thinks that unique secondary indexes are not extended + with PK columns (both in MySQL and MariaDB) + 2. MariaDB also thinks that indexes with partially-covered columns + are not extended with PK columns. Use the same number of + keyparts that MyRocks would use. + */ + uint ext_key_parts2; + if (k->flags & HA_NOSAME) + ext_key_parts2= k->ext_key_parts; // This is #1 + else + ext_key_parts2= m_key_descr_arr[i]->get_key_parts(); // This is #2. + // Fake cardinality implementation. For example, (idx1, idx2, idx3) index // will have rec_per_key for (idx1)=4, (idx1,2)=2, and (idx1,2,3)=1. // rec_per_key for the whole index is 1, and multiplied by 2^n if // n suffix columns of the index are not used. - x = 1 << (k->ext_key_parts-j-1); + x = 1 << (ext_key_parts2-j-1); } k->rec_per_key[j]= x; } diff --git a/storage/rocksdb/rdb_datadic.cc b/storage/rocksdb/rdb_datadic.cc index 472af8141a7..3523397bae2 100644 --- a/storage/rocksdb/rdb_datadic.cc +++ b/storage/rocksdb/rdb_datadic.cc @@ -283,7 +283,12 @@ void Rdb_key_def::setup(const TABLE *tbl, const Rdb_tbl_def *tbl_def) key_part++; /* For "unique" secondary indexes, pretend they have - "index extensions" + "index extensions". + + MariaDB also has this property: if an index has a partially-covered + column like KEY(varchar_col(N)), then the SQL layer will think it is + not "extended" with PK columns. The code below handles this case, + also. */ if (secondary_key && src_i+1 == key_info->ext_key_parts) {