diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2018-04-30 10:33:03 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2018-04-30 10:33:03 +0300 |
commit | 38bc4bcc964794f3cfc3d117079679c33f72f11a (patch) | |
tree | 3b007baf31a9c7917752e12772117764e9f18992 | |
parent | d73241c0a93a4d1ae198b3c59a0f8da84adb295f (diff) | |
download | mariadb-git-38bc4bcc964794f3cfc3d117079679c33f72f11a.tar.gz |
MDEV-16058 Unnecessary computations for SPATIAL INDEX
dict_index_copy_rec_order_prefix(): Avoid invoking
dict_index_get_n_unique_in_tree_nonleaf().
create_index(): Simplify code for creating SPATIAL or FULLTEXT index.
rec_copy_prefix_to_buf(): Skip the loop for SPATIAL INDEX.
-rw-r--r-- | storage/innobase/dict/dict0dict.cc | 16 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 19 | ||||
-rw-r--r-- | storage/innobase/rem/rem0rec.cc | 46 |
3 files changed, 38 insertions, 43 deletions
diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index dbad7a8fa31..6c975fdf05b 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -5596,19 +5596,19 @@ dict_index_copy_rec_order_prefix( UNIV_PREFETCH_R(rec); if (dict_index_is_ibuf(index)) { - ut_a(!dict_table_is_comp(index->table)); + ut_ad(!dict_table_is_comp(index->table)); n = rec_get_n_fields_old(rec); } else { if (page_rec_is_leaf(rec)) { n = dict_index_get_n_unique_in_tree(index); + } else if (dict_index_is_spatial(index)) { + ut_ad(dict_index_get_n_unique_in_tree_nonleaf(index) + == DICT_INDEX_SPATIAL_NODEPTR_SIZE); + /* For R-tree, we have to compare + the child page numbers as well. */ + n = DICT_INDEX_SPATIAL_NODEPTR_SIZE + 1; } else { - n = dict_index_get_n_unique_in_tree_nonleaf(index); - /* For internal node of R-tree, since we need to - compare the page no field, so, we need to copy this - field as well. */ - if (dict_index_is_spatial(index)) { - n++; - } + n = dict_index_get_n_unique_in_tree(index); } } diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 644cf64abc8..cd4768c3a4a 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -11262,7 +11262,6 @@ create_index( dict_index_t* index; int error; const KEY* key; - ulint ind_type; ulint* field_lengths; DBUG_ENTER("create_index"); @@ -11272,17 +11271,13 @@ create_index( /* Assert that "GEN_CLUST_INDEX" cannot be used as non-primary index */ ut_a(innobase_strcasecmp(key->name.str, innobase_index_reserve_name) != 0); - ind_type = 0; - if (key->flags & HA_SPATIAL) { - ind_type = DICT_SPATIAL; - } else if (key->flags & HA_FULLTEXT) { - ind_type = DICT_FTS; - } - - if (ind_type != 0) - { + if (key->flags & (HA_SPATIAL | HA_FULLTEXT)) { + /* Only one of these can be specified at a time. */ + ut_ad(~key->flags & (HA_SPATIAL | HA_FULLTEXT)); + ut_ad(!(key->flags & HA_NOSAME)); index = dict_mem_index_create(table, key->name.str, - ind_type, + (key->flags & HA_SPATIAL) + ? DICT_SPATIAL : DICT_FTS, key->user_defined_key_parts); for (ulint i = 0; i < key->user_defined_key_parts; i++) { @@ -11305,7 +11300,7 @@ create_index( table->flags, NULL)); } - ind_type = 0; + ulint ind_type = 0; if (key_num == form->s->primary_key) { ind_type |= DICT_CLUSTERED; diff --git a/storage/innobase/rem/rem0rec.cc b/storage/innobase/rem/rem0rec.cc index 917aaf25cf7..77b3fcb7906 100644 --- a/storage/innobase/rem/rem0rec.cc +++ b/storage/innobase/rem/rem0rec.cc @@ -1836,11 +1836,8 @@ rec_copy_prefix_to_buf( ulint* buf_size) /*!< in/out: buffer size */ { const byte* nulls; - const byte* UNINIT_VAR(lens); - ulint i; - ulint prefix_len; - ulint null_mask; - bool is_rtr_node_ptr = false; + const byte* lens; + ulint prefix_len = 0; ut_ad(n_fields <= index->n_fields || dict_index_is_ibuf(index)); ut_ad(index->n_core_null_bytes <= UT_BITS_IN_BYTES(index->n_nullable)); @@ -1855,8 +1852,7 @@ rec_copy_prefix_to_buf( } switch (rec_get_status(rec)) { - case REC_STATUS_INFIMUM: - case REC_STATUS_SUPREMUM: + default: /* infimum or supremum record: no sense to copy anything */ ut_error; return(NULL); @@ -1866,18 +1862,28 @@ rec_copy_prefix_to_buf( lens = nulls - index->n_core_null_bytes; break; case REC_STATUS_NODE_PTR: + nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1); + lens = nulls - index->n_core_null_bytes; /* For R-tree, we need to copy the child page number field. */ + compile_time_assert(DICT_INDEX_SPATIAL_NODEPTR_SIZE == 1); if (dict_index_is_spatial(index)) { + ut_ad(index->n_core_null_bytes == 0); ut_ad(n_fields == DICT_INDEX_SPATIAL_NODEPTR_SIZE + 1); - is_rtr_node_ptr = true; - } else { - /* it doesn't make sense to copy the child page number - field */ - ut_ad(n_fields <= - dict_index_get_n_unique_in_tree_nonleaf(index)); + ut_ad(index->fields[0].col->prtype & DATA_NOT_NULL); + ut_ad(DATA_BIG_COL(index->fields[0].col)); + /* This is a deficiency of the format introduced + in MySQL 5.7. The length in the R-tree index should + always be DATA_MBR_LEN. */ + ut_ad(!index->fields[0].fixed_len); + ut_ad(*lens == DATA_MBR_LEN); + lens--; + prefix_len = DATA_MBR_LEN + REC_NODE_PTR_SIZE; + n_fields = 0; /* skip the "for" loop below */ + break; } - nulls = rec - (REC_N_NEW_EXTRA_BYTES + 1); - lens = nulls - index->n_core_null_bytes; + /* it doesn't make sense to copy the child page number field */ + ut_ad(n_fields + <= dict_index_get_n_unique_in_tree_nonleaf(index)); break; case REC_STATUS_COLUMNS_ADDED: /* We would have !index->is_instant() when rolling back @@ -1891,11 +1897,9 @@ rec_copy_prefix_to_buf( } UNIV_PREFETCH_R(lens); - prefix_len = 0; - null_mask = 1; /* read the lengths of fields 0..n */ - for (i = 0; i < n_fields; i++) { + for (ulint i = 0, null_mask = 1; i < n_fields; i++) { const dict_field_t* field; const dict_col_t* col; @@ -1917,11 +1921,7 @@ rec_copy_prefix_to_buf( null_mask <<= 1; } - if (is_rtr_node_ptr && i == 1) { - /* For rtree node ptr rec, we need to - copy the page no field with 4 bytes len. */ - prefix_len += 4; - } else if (field->fixed_len) { + if (field->fixed_len) { prefix_len += field->fixed_len; } else { ulint len = *lens--; |