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