Commit 8a1caecc authored by marko's avatar marko

On data tuples being updated or inserted (but not searched for),

set type->len to the prefix_len of the index column, if it is a prefix index.
This should prevent bugs similar to Bug #21638 from occurring.

dict_index_copy_types(): Set type->len to prefix_len if prefix_len != 0.

row_build_index_entry(): Set type->len to prefix_len if prefix_len != 0,
also when the column in the tuple is SQL NULL, because the type information
may be used for interpreting other records during btr_page_reorganize().
parent 11a7abc0
...@@ -1723,8 +1723,6 @@ dict_index_copy_types( ...@@ -1723,8 +1723,6 @@ dict_index_copy_types(
dict_index_t* index, /* in: index */ dict_index_t* index, /* in: index */
ulint n_fields) /* in: number of field types to copy */ ulint n_fields) /* in: number of field types to copy */
{ {
dtype_t* dfield_type;
dtype_t* type;
ulint i; ulint i;
if (UNIV_UNLIKELY(index->type & DICT_UNIVERSAL)) { if (UNIV_UNLIKELY(index->type & DICT_UNIVERSAL)) {
...@@ -1734,10 +1732,17 @@ dict_index_copy_types( ...@@ -1734,10 +1732,17 @@ dict_index_copy_types(
} }
for (i = 0; i < n_fields; i++) { for (i = 0; i < n_fields; i++) {
dict_field_t* ifield;
dtype_t* dfield_type;
dtype_t* type;
ifield = dict_index_get_nth_field(index, i);
dfield_type = dfield_get_type(dtuple_get_nth_field(tuple, i)); dfield_type = dfield_get_type(dtuple_get_nth_field(tuple, i));
type = dict_col_get_type(dict_field_get_col type = dict_col_get_type(dict_field_get_col(ifield));
(dict_index_get_nth_field(index, i)));
*dfield_type = *type; *dfield_type = *type;
if (UNIV_UNLIKELY(ifield->prefix_len)) {
dfield_type->len = ifield->prefix_len;
}
} }
} }
......
...@@ -143,17 +143,22 @@ row_build_index_entry( ...@@ -143,17 +143,22 @@ row_build_index_entry(
dfield_copy(dfield, dfield2); dfield_copy(dfield, dfield2);
/* If a column prefix index, take only the prefix */ /* If a column prefix index, take only the prefix */
if (ind_field->prefix_len > 0 if (ind_field->prefix_len) {
&& dfield_get_len(dfield2) != UNIV_SQL_NULL) { if (dfield_get_len(dfield2) != UNIV_SQL_NULL) {
cur_type = dict_col_get_type cur_type = dict_col_get_type
(dict_field_get_col(ind_field)); (dict_field_get_col(ind_field));
storage_len = dtype_get_at_most_n_mbchars
(cur_type,
ind_field->prefix_len,
dfield_get_len(dfield2),
dfield2->data);
storage_len = dtype_get_at_most_n_mbchars dfield_set_len(dfield, storage_len);
(cur_type, ind_field->prefix_len, }
dfield_get_len(dfield2), dfield2->data);
dfield_set_len(dfield, storage_len); dfield_get_type(dfield)->len = ind_field->prefix_len;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment