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

Remove unnecessary use of rec_get_nth_cfield() and unnecessary copying

rec_get_nth_cfield(): Remove the heap parameter.
Copying the default value of a field into a heap is only
needed in row_build_low(type=ROW_COPY_DATA).

rec_get_nth_field(): Use the original definition.
There are very few rec_get_nth_cfield() calls compared to
rec_get_nth_field().
parent 5af53464
......@@ -1958,8 +1958,7 @@ innobase_rec_to_mysql(
continue;
}
/* ifield is read only, the heap can be NULL */
ifield = rec_get_nth_cfield(rec, offsets, ipos, index, NULL, &ilen);
ifield = rec_get_nth_cfield(rec, index, offsets, ipos, &ilen);
/* Assign the NULL flag */
if (ilen == UNIV_SQL_NULL) {
......
......@@ -586,26 +586,23 @@ rec_get_nth_field_offs(
ulint* len) /*!< out: length of the field; UNIV_SQL_NULL
if SQL null */
MY_ATTRIBUTE((nonnull));
#define rec_get_nth_field(rec, offsets, n, len) \
((rec) + rec_get_nth_field_offs(offsets, n, len))
/************************************************************//**
Get the nth field from cluster index
@return pointer of field(Maybe get the pointer of default value of dictionary) */
/** Get the nth field from an index.
@param[in] rec index record
@param[in] index index
@param[in] offsets rec_get_offsets(rec, index)
@param[in] n field number
@param[out] len length of the field in bytes, or UNIV_SQL_NULL
@return a read-only copy of the index field */
const byte*
rec_get_nth_cfield(
const rec_t* rec, /*!< in: rec */
const ulint* offsets,/*!< in: array returned by rec_get_offsets() */
ulint n, /*!< in: index of the field */
const dict_index_t* index, /*!< in: dict_index of rec */
mem_heap_t* heap, /*!< in: mem_heap for default
value of instant added columns */
ulint* len); /*!< out: length of the field; UNIV_SQL_NULL
if SQL null */
/* Never return DEFAULT value(UNIV_SQL_DEFAULT)
It always return pointer inside the record
*/
#define rec_get_nth_field(rec, offsets, n, len) \
(byte*)rec_get_nth_cfield(rec, offsets, n, NULL, NULL, len)
const rec_t* rec,
const dict_index_t* index,
const ulint* offsets,
ulint n,
ulint* len);
/******************************************************//**
Determine if the offsets are for a record containing null BLOB pointers.
......
......@@ -272,7 +272,7 @@ page_cur_rec_field_extends(
type = dfield_get_type(dfield);
rec_f = rec_get_nth_cfield(rec, offsets, n, index, NULL, &rec_f_len);
rec_f = rec_get_nth_field(rec, offsets, n, &rec_f_len);
if (type->mtype == DATA_VARCHAR
|| type->mtype == DATA_CHAR
......
......@@ -1018,8 +1018,8 @@ cmp_rec_rec_simple_field(
ut_ad(!rec_offs_nth_extern(offsets1, n));
ut_ad(!rec_offs_nth_extern(offsets2, n));
rec1_b_ptr = rec_get_nth_cfield(rec1, offsets1, n, index, NULL, &rec1_f_len);
rec2_b_ptr = rec_get_nth_cfield(rec2, offsets2, n, index, NULL, &rec2_f_len);
rec1_b_ptr = rec_get_nth_field(rec1, offsets1, n, &rec1_f_len);
rec2_b_ptr = rec_get_nth_field(rec2, offsets2, n, &rec2_f_len);
return(cmp_data(col->mtype, col->prtype,
rec1_b_ptr, rec1_f_len, rec2_b_ptr, rec2_f_len));
......@@ -1205,11 +1205,13 @@ cmp_rec_rec_with_match(
DB_ROLL_PTR, and any externally stored columns. */
ut_ad(!rec_offs_nth_extern(offsets1, cur_field));
ut_ad(!rec_offs_nth_extern(offsets2, cur_field));
ut_ad(!rec_offs_nth_default(offsets1, cur_field));
ut_ad(!rec_offs_nth_default(offsets2, cur_field));
rec1_b_ptr = rec_get_nth_cfield(rec1, offsets1,
cur_field, index, NULL, &rec1_f_len);
rec2_b_ptr = rec_get_nth_cfield(rec2, offsets2,
cur_field, index, NULL, &rec2_f_len);
rec1_b_ptr = rec_get_nth_field(rec1, offsets1,
cur_field, &rec1_f_len);
rec2_b_ptr = rec_get_nth_field(rec2, offsets2,
cur_field, &rec2_f_len);
if (nulls_unequal
&& rec1_f_len == UNIV_SQL_NULL
......
......@@ -946,36 +946,28 @@ rec_get_offsets_reverse(
| REC_OFFS_COMPACT | any_ext;
}
/************************************************************//**
Get the nth field from cluster index
@return pointer of field(Maybe get the pointer of default value of dictionary) */
/** Get the nth field from an index.
@param[in] rec index record
@param[in] index index
@param[in] offsets rec_get_offsets(rec, index)
@param[in] n field number
@param[out] len length of the field in bytes, or UNIV_SQL_NULL
@return a read-only copy of the index field */
const byte*
rec_get_nth_cfield(
const rec_t* rec, /*!< in: rec */
const ulint* offsets, /*!< in: array returned by rec_get_offsets() */
ulint n, /*!< in: index of the field */
const dict_index_t* index, /*!< in: dict_index of rec.
If NULL, *len maybe UNIV_SQL_DEFAULT */
mem_heap_t* heap, /*!< in: mem_heap for default value of instant added columns
IF NULL, return the dictionary memory directly.
It must be read only when heap = NULL. */
ulint* len) /*!< out: length of the field; UNIV_SQL_NULL if SQL null */
const rec_t* rec,
const dict_index_t* index,
const ulint* offsets,
ulint n,
ulint* len)
{
const byte* field;
ulint off = rec_get_nth_field_offs(offsets, n, len);
ut_ad(index || !rec_offs_nth_default(offsets, n));
ut_ad(rec_offs_validate(rec, index, offsets));
if (*len != UNIV_SQL_DEFAULT || !index) {
return rec + off;
if (!rec_offs_nth_default(offsets, n)) {
return rec_get_nth_field(rec, offsets, n, len);
}
field = dict_index_get_nth_field_def(index, n, len);
ut_ad(*len != UNIV_SQL_DEFAULT);
if (heap) {
field = static_cast<byte*>(mem_heap_dup(heap, field, *len));
}
return field;
return dict_index_get_nth_field_def(index, n, len);
}
/************************************************************//**
......@@ -1847,7 +1839,7 @@ rec_copy_prefix_to_dtuple(
ulint len;
field = dtuple_get_nth_field(tuple, i);
data = rec_get_nth_cfield(rec, offsets, i, index, NULL, &len);
data = rec_get_nth_field(rec, offsets, i, &len);
if (len != UNIV_SQL_NULL) {
dfield_set_data(field,
......
......@@ -1619,7 +1619,7 @@ row_log_table_apply_convert_mrec(
blob_done:
rw_lock_x_unlock(dict_index_get_lock(index));
} else {
data = rec_get_nth_cfield(mrec, offsets, i, index, heap, &len);
data = rec_get_nth_field(mrec, offsets, i, &len);
dfield_set_data(dfield, data, len);
}
......
......@@ -506,10 +506,15 @@ row_build_low(
}
dfield_t* dfield = dtuple_get_nth_field(row, col_no);
const byte* field = rec_get_nth_cfield(
copy, offsets, i, index, heap, &len);
const void* field = rec_get_nth_field(
copy, offsets, i, &len);
if (len == UNIV_SQL_DEFAULT) {
field = dict_index_get_nth_field_def(index, i, &len);
if (field && type != ROW_COPY_POINTERS) {
ut_ad(univ_is_stored(len));
field = mem_heap_dup(heap, field, len);
}
}
dfield_set_data(dfield, field, len);
if (rec_offs_nth_extern(offsets, i)) {
......@@ -644,20 +649,23 @@ row_build_w_add_vcol(
add_cols, add_v, col_map, ext, heap));
}
/*******************************************************************//**
Converts an index record to a typed data tuple.
/** Convert an index record to a data tuple.
@tparam def whether the dict_col_t::def_val needs to be accessed
@param[in] rec index record
@param[in] index index
@param[in] offsets rec_get_offsets(rec, index)
@param[out] n_ext number of externally stored columns
@param[in,out] heap memory heap for allocations
@return index entry built; does not set info_bits, and the data fields
in the entry will point directly to rec */
template<bool def>
dtuple_t*
row_rec_to_index_entry_low(
/*=======================*/
const rec_t* rec, /*!< in: record in the index */
const dict_index_t* index, /*!< in: index */
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
ulint* n_ext, /*!< out: number of externally
stored columns */
mem_heap_t* heap) /*!< in: memory heap from which
the memory needed is allocated */
row_rec_to_index_entry_impl(
const rec_t* rec,
const dict_index_t* index,
const ulint* offsets,
ulint* n_ext,
mem_heap_t* heap)
{
dtuple_t* entry;
dfield_t* dfield;
......@@ -669,6 +677,7 @@ row_rec_to_index_entry_low(
ut_ad(rec != NULL);
ut_ad(heap != NULL);
ut_ad(index != NULL);
ut_ad(def || !rec_offs_any_default(offsets));
/* Because this function may be invoked by row0merge.cc
on a record whose header is in different format, the check
......@@ -693,7 +702,9 @@ row_rec_to_index_entry_low(
for (i = 0; i < rec_len; i++) {
dfield = dtuple_get_nth_field(entry, i);
field = rec_get_nth_cfield(rec, offsets, i, index, heap, &len);
field = def
? rec_get_nth_cfield(rec, index, offsets, i, &len)
: rec_get_nth_field(rec, offsets, i, &len);
dfield_set_data(dfield, field, len);
......@@ -704,10 +715,27 @@ row_rec_to_index_entry_low(
}
ut_ad(dtuple_check_typed(entry));
return(entry);
}
/** Convert an index record to a data tuple.
@param[in] rec index record
@param[in] index index
@param[in] offsets rec_get_offsets(rec, index)
@param[out] n_ext number of externally stored columns
@param[in,out] heap memory heap for allocations */
dtuple_t*
row_rec_to_index_entry_low(
const rec_t* rec,
const dict_index_t* index,
const ulint* offsets,
ulint* n_ext,
mem_heap_t* heap)
{
return row_rec_to_index_entry_impl<false>(
rec, index, offsets, n_ext, heap);
}
/*******************************************************************//**
Converts an index record to a typed data tuple. NOTE that externally
stored (often big) fields are NOT copied to heap.
......@@ -740,7 +768,7 @@ row_rec_to_index_entry(
rec_offs_make_valid(copy_rec, index, true,
const_cast<ulint*>(offsets));
entry = row_rec_to_index_entry_low(
entry = row_rec_to_index_entry_impl<true>(
copy_rec, index, offsets, n_ext, heap);
rec_offs_make_valid(rec, index, true,
const_cast<ulint*>(offsets));
......
......@@ -242,9 +242,9 @@ row_sel_sec_rec_is_for_clust_rec(
clust_field = static_cast<byte*>(vfield->data);
} else {
clust_pos = dict_col_get_clust_pos(col, clust_index);
clust_field = rec_get_nth_cfield(
clust_rec, clust_offs, clust_pos, clust_index, heap, &clust_len);
ut_ad(!rec_offs_nth_default(clust_offs, clust_pos));
clust_field = rec_get_nth_field(
clust_rec, clust_offs, clust_pos, &clust_len);
}
sec_field = rec_get_nth_field(sec_rec, sec_offs, i, &sec_len);
......@@ -517,7 +517,6 @@ row_sel_fetch_columns(
rec, offsets,
dict_table_page_size(index->table),
field_no, &len, heap);
//field_no, &len, heap, NULL);
/* data == NULL means that the
externally stored field was not
......@@ -534,14 +533,9 @@ row_sel_fetch_columns(
needs_copy = TRUE;
} else {
data = rec_get_nth_cfield(rec, offsets,
field_no, index, heap, &len);
if (rec_offs_nth_default(offsets, field_no)) {
needs_copy = TRUE;
} else {
needs_copy = column->copy_val;
}
data = rec_get_nth_cfield(rec, index, offsets,
field_no, &len);
needs_copy = column->copy_val;
}
if (needs_copy) {
......@@ -3056,22 +3050,17 @@ row_sel_store_mysql_field_func(
mem_heap_free(heap);
}
} else {
/* Field is stored in the row. */
/* The field is stored in the index record, or
in the 'default row' for instant ADD COLUMN. */
if (rec_offs_nth_default(offsets, field_no)) {
/* There is default value of added column only in
cluster index */
const dict_index_t* clust_index =
dict_table_get_first_index(prebuilt->index->table);
/* Reuse the blob_heap for instant added columns */
if (prebuilt->blob_heap == NULL) {
prebuilt->blob_heap = mem_heap_create(
UNIV_PAGE_SIZE);
}
data = rec_get_nth_cfield(rec, offsets, field_no, clust_index,
prebuilt->blob_heap, &len);
ut_ad(dict_index_is_clust(index));
ut_ad(index->is_instant());
const dict_index_t* clust_index
= dict_table_get_first_index(prebuilt->table);
ut_ad(index == clust_index);
data = dict_index_get_nth_field_def(
clust_index, field_no, &len);
} else {
data = rec_get_nth_field(rec, offsets, field_no, &len);
}
......@@ -4042,6 +4031,8 @@ row_sel_fill_vrow(
ut_ad(!(*vrow));
ut_ad(heap);
ut_ad(!dict_index_is_clust(index));
ut_ad(!index->is_instant());
ut_ad(page_rec_is_leaf(rec));
offsets = rec_get_offsets(rec, index, offsets, true,
......@@ -4064,7 +4055,7 @@ row_sel_fill_vrow(
const byte* data;
ulint len;
data = rec_get_nth_cfield(rec, offsets, i, index, heap, &len);
data = rec_get_nth_field(rec, offsets, i, &len);
const dict_v_col_t* vcol = reinterpret_cast<
const dict_v_col_t*>(col);
......
......@@ -1098,9 +1098,7 @@ row_upd_build_difference_binary(
}
for (i = 0; i < n_fld; i++) {
/* data is read only, heap can be NULL */
data = rec_get_nth_cfield(rec, offsets, i, index, NULL, &len);
data = rec_get_nth_cfield(rec, index, offsets, i, &len);
dfield = dtuple_get_nth_field(entry, i);
......@@ -2072,14 +2070,15 @@ row_upd_copy_columns(
sym_node_t* column) /*!< in: first column in a column list, or
NULL */
{
ut_ad(dict_index_is_clust(index));
const byte* data;
ulint len;
while (column) {
data = rec_get_nth_cfield(rec, offsets,
column->field_nos[SYM_CLUST_FIELD_NO],
index, NULL,
&len);
data = rec_get_nth_cfield(
rec, index, offsets,
column->field_nos[SYM_CLUST_FIELD_NO], &len);
eval_node_copy_and_alloc_val(column, data, len);
column = UT_LIST_GET_NEXT(col_var_list, column);
......
......@@ -1091,8 +1091,8 @@ trx_undo_page_report_modify(
flen, max_v_log_len);
}
} else {
field = rec_get_nth_cfield(rec, offsets,
pos, index, NULL, &flen);
field = rec_get_nth_cfield(
rec, index, offsets, pos, &flen);
}
if (trx_undo_left(undo_page, ptr) < 15) {
......@@ -1232,8 +1232,8 @@ trx_undo_page_report_modify(
ptr += mach_write_compressed(ptr, pos);
/* Save the old value of field */
field = rec_get_nth_cfield(rec, offsets, pos,
index, NULL, &flen);
field = rec_get_nth_cfield(
rec, index, offsets, pos, &flen);
if (rec_offs_nth_extern(offsets, pos)) {
const dict_col_t* col =
......
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