Skip to content

Commit

Permalink
MDEV-16058 Unnecessary computations for SPATIAL INDEX
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dr-m committed Apr 30, 2018
1 parent d73241c commit 38bc4bc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 43 deletions.
16 changes: 8 additions & 8 deletions storage/innobase/dict/dict0dict.cc
Expand Up @@ -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);
}
}

Expand Down
19 changes: 7 additions & 12 deletions storage/innobase/handler/ha_innodb.cc
Expand Up @@ -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");
Expand All @@ -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++) {
Expand All @@ -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;
Expand Down
46 changes: 23 additions & 23 deletions storage/innobase/rem/rem0rec.cc
Expand Up @@ -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));
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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;

Expand All @@ -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--;
Expand Down

0 comments on commit 38bc4bc

Please sign in to comment.