Commit cd081734 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-15562: Add dict_index_t::first_user_field()

dict_index_t::first_user_field(): Return the first data field in
a clustered index, that is, the field after the PRIMARY KEY and
the two system columns DB_TRX_ID, DB_ROLL_PTR.

dtuple_convert_big_rec(): Remove some local variables.
parent 2a955c7a
......@@ -598,7 +598,6 @@ dtuple_convert_big_rec(
mem_heap_t* heap;
big_rec_t* vector;
dfield_t* dfield;
dict_field_t* ifield;
ulint size;
ulint n_fields;
ulint local_len;
......@@ -608,14 +607,7 @@ dtuple_convert_big_rec(
return(NULL);
}
if (!dict_table_has_atomic_blobs(index->table)) {
/* up to MySQL 5.1: store a 768-byte prefix locally */
local_len = BTR_EXTERN_FIELD_REF_SIZE
+ DICT_ANTELOPE_MAX_INDEX_COL_LEN;
} else {
/* new-format table: do not store any BLOB prefix locally */
local_len = BTR_EXTERN_FIELD_REF_SIZE;
}
ut_ad(index->n_uniq > 0);
ut_a(dtuple_check_typed_no_assert(entry));
......@@ -638,24 +630,33 @@ dtuple_convert_big_rec(
stored externally */
n_fields = 0;
ulint longest_i;
if (!dict_table_has_atomic_blobs(index->table)) {
/* ROW_FORMAT=REDUNDANT or ROW_FORMAT=COMPACT:
store a 768-byte prefix locally */
local_len = BTR_EXTERN_FIELD_REF_SIZE
+ DICT_ANTELOPE_MAX_INDEX_COL_LEN;
} else {
/* ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED:
do not store any BLOB prefix locally */
local_len = BTR_EXTERN_FIELD_REF_SIZE;
}
while (page_zip_rec_needs_ext(rec_get_converted_size(index, entry,
*n_ext),
dict_table_is_comp(index->table),
dict_index_get_n_fields(index),
dict_table_page_size(index->table))) {
longest_i = 0;
ulint i;
ulint longest = 0;
ulint longest_i = ULINT_MAX;
byte* data;
for (i = dict_index_get_n_unique_in_tree(index);
i < dtuple_get_n_fields(entry); i++) {
for (ulint i = index->first_user_field(), longest = 0;
i < entry->n_fields; i++) {
ulint savings;
dfield = dtuple_get_nth_field(entry, i);
ifield = dict_index_get_nth_field(index, i);
const dict_field_t* ifield = dict_index_get_nth_field(
index, i);
/* Skip fixed-length, NULL, externally stored,
or short columns */
......@@ -697,7 +698,7 @@ dtuple_convert_big_rec(
continue;
}
if (!longest) {
if (!longest_i) {
/* Cannot shorten more */
mem_heap_free(heap);
......@@ -712,7 +713,6 @@ dtuple_convert_big_rec(
from locally stored data. */
dfield = dtuple_get_nth_field(entry, longest_i);
ifield = dict_index_get_nth_field(index, longest_i);
local_prefix_len = local_len - BTR_EXTERN_FIELD_REF_SIZE;
vector->append(
......@@ -723,7 +723,8 @@ dtuple_convert_big_rec(
+ local_prefix_len));
/* Allocate the locally stored part of the column. */
data = static_cast<byte*>(mem_heap_alloc(heap, local_len));
byte* data = static_cast<byte*>(
mem_heap_alloc(heap, local_len));
/* Copy the local prefix. */
memcpy(data, dfield_get_data(dfield), local_prefix_len);
......@@ -737,7 +738,6 @@ dtuple_convert_big_rec(
UNIV_MEM_ALLOC(data + local_prefix_len,
BTR_EXTERN_FIELD_REF_SIZE);
#endif
dfield_set_data(dfield, data, local_len);
dfield_set_ext(dfield);
......
......@@ -1055,6 +1055,13 @@ struct dict_index_t{
/** @return whether the index includes virtual columns */
bool has_virtual() const { return type & DICT_VIRTUAL; }
/** @return the offset of the metadata BLOB field,
or the first user field after the PRIMARY KEY,DB_TRX_ID,DB_ROLL_PTR */
unsigned first_user_field() const {
ut_ad(is_primary());
return n_uniq + 2;
}
/** @return whether the index is corrupted */
inline bool is_corrupted() const;
......
......@@ -1906,6 +1906,7 @@ rec_copy_prefix_to_buf(
/* We would have !index->is_instant() when rolling back
an instant ADD COLUMN operation. */
ut_ad(index->is_instant() || page_rec_is_metadata(rec));
ut_ad(n_fields <= index->first_user_field());
nulls++;
const ulint n_rec = ulint(index->n_core_fields) + 1
+ rec_get_n_add_field(nulls);
......
......@@ -684,9 +684,9 @@ row_log_table_delete(
fields of the record. */
heap = mem_heap_create(
DATA_TRX_ID_LEN
+ DTUPLE_EST_ALLOC(unsigned(new_index->n_uniq) + 2));
old_pk = tuple = dtuple_create(
heap, unsigned(new_index->n_uniq) + 2);
+ DTUPLE_EST_ALLOC(new_index->first_user_field()));
old_pk = tuple = dtuple_create(heap,
new_index->first_user_field());
dict_index_copy_types(tuple, new_index, tuple->n_fields);
dtuple_set_n_fields_cmp(tuple, new_index->n_uniq);
......@@ -1919,8 +1919,7 @@ row_log_table_apply_delete(
btr_pcur_t pcur;
ulint* offsets;
ut_ad(rec_offs_n_fields(moffsets)
== dict_index_get_n_unique(index) + 2);
ut_ad(rec_offs_n_fields(moffsets) == index->first_user_field());
ut_ad(!rec_offs_any_extern(moffsets));
/* Convert the row to a search tuple. */
......@@ -2483,8 +2482,7 @@ row_log_table_apply_op(
/* The ROW_T_DELETE record was converted by
rec_convert_dtuple_to_temp() using new_index. */
ut_ad(!new_index->is_instant());
rec_offs_set_n_fields(offsets,
unsigned(new_index->n_uniq) + 2);
rec_offs_set_n_fields(offsets, new_index->first_user_field());
rec_init_offsets_temp(mrec, new_index, offsets);
next_mrec = mrec + rec_offs_data_size(offsets);
if (next_mrec > mrec_end) {
......@@ -2576,7 +2574,7 @@ row_log_table_apply_op(
rec_convert_dtuple_to_temp() using new_index. */
ut_ad(!new_index->is_instant());
rec_offs_set_n_fields(offsets,
unsigned(new_index->n_uniq) + 2);
new_index->first_user_field());
rec_init_offsets_temp(mrec, new_index, offsets);
next_mrec = mrec + rec_offs_data_size(offsets);
......@@ -2586,13 +2584,12 @@ row_log_table_apply_op(
/* Copy the PRIMARY KEY fields and
DB_TRX_ID, DB_ROLL_PTR from mrec to old_pk. */
old_pk = dtuple_create(
heap, unsigned(new_index->n_uniq) + 2);
old_pk = dtuple_create(heap,
new_index->first_user_field());
dict_index_copy_types(old_pk, new_index,
old_pk->n_fields);
for (ulint i = 0;
i < dict_index_get_n_unique(new_index) + 2;
for (ulint i = 0; i < new_index->first_user_field();
i++) {
const void* field;
ulint len;
......@@ -2743,8 +2740,8 @@ row_log_table_apply_ops(
dict_index_t* new_index = dict_table_get_first_index(
new_table);
const ulint i = 1 + REC_OFFS_HEADER_SIZE
+ ut_max(dict_index_get_n_fields(index),
dict_index_get_n_unique(new_index) + 2);
+ std::max<ulint>(index->n_fields,
new_index->first_user_field());
const ulint new_trx_id_col = dict_col_get_clust_pos(
dict_table_get_sys_col(new_table, DATA_TRX_ID), new_index);
trx_t* trx = thr_get_trx(thr);
......
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