Commit 6fa5b727 authored by marko's avatar marko

branches/zip: Minor optimization.

trx_undo_page_report_modify(), trx_undo_report_row_operation():
Add const qualifier to the parameter rec.  Remove some local variables.

trx_undo_report_row_operation(): Invoke rec_get_offsets() only once.
parent 9a948882
...@@ -194,7 +194,7 @@ trx_undo_report_row_operation( ...@@ -194,7 +194,7 @@ trx_undo_report_row_operation(
the update vector, otherwise NULL */ the update vector, otherwise NULL */
ulint cmpl_info, /* in: compiler info on secondary ulint cmpl_info, /* in: compiler info on secondary
index updates */ index updates */
rec_t* rec, /* in: case of an update or delete const rec_t* rec, /* in: case of an update or delete
marking, the record in the clustered marking, the record in the clustered
index, otherwise NULL */ index, otherwise NULL */
dulint* roll_ptr); /* out: rollback pointer to the dulint* roll_ptr); /* out: rollback pointer to the
......
...@@ -402,7 +402,7 @@ trx_undo_page_report_modify( ...@@ -402,7 +402,7 @@ trx_undo_page_report_modify(
trx_t* trx, /* in: transaction */ trx_t* trx, /* in: transaction */
dict_index_t* index, /* in: clustered index where update or dict_index_t* index, /* in: clustered index where update or
delete marking is done */ delete marking is done */
rec_t* rec, /* in: clustered index record which const rec_t* rec, /* in: clustered index record which
has NOT yet been modified */ has NOT yet been modified */
const ulint* offsets, /* in: rec_get_offsets(rec, index) */ const ulint* offsets, /* in: rec_get_offsets(rec, index) */
upd_t* update, /* in: update vector which tells the upd_t* update, /* in: update vector which tells the
...@@ -413,18 +413,12 @@ trx_undo_page_report_modify( ...@@ -413,18 +413,12 @@ trx_undo_page_report_modify(
mtr_t* mtr) /* in: mtr */ mtr_t* mtr) /* in: mtr */
{ {
dict_table_t* table; dict_table_t* table;
upd_field_t* upd_field;
ulint first_free; ulint first_free;
byte* ptr; byte* ptr;
ulint len; ulint len;
byte* field; const byte* field;
ulint flen; ulint flen;
ulint pos;
dulint roll_ptr;
dulint trx_id;
ulint bits;
ulint col_no; ulint col_no;
byte* old_ptr;
ulint type_cmpl; ulint type_cmpl;
byte* type_cmpl_ptr; byte* type_cmpl_ptr;
ulint i; ulint i;
...@@ -454,17 +448,15 @@ trx_undo_page_report_modify( ...@@ -454,17 +448,15 @@ trx_undo_page_report_modify(
/* Store first some general parameters to the undo log */ /* Store first some general parameters to the undo log */
if (update) { if (!update) {
if (rec_get_deleted_flag(rec, dict_table_is_comp(table))) { type_cmpl = TRX_UNDO_DEL_MARK_REC;
} else if (rec_get_deleted_flag(rec, dict_table_is_comp(table))) {
type_cmpl = TRX_UNDO_UPD_DEL_REC; type_cmpl = TRX_UNDO_UPD_DEL_REC;
} else { } else {
type_cmpl = TRX_UNDO_UPD_EXIST_REC; type_cmpl = TRX_UNDO_UPD_EXIST_REC;
} }
} else {
type_cmpl = TRX_UNDO_DEL_MARK_REC;
}
type_cmpl = type_cmpl | (cmpl_info * TRX_UNDO_CMPL_INFO_MULT); type_cmpl |= cmpl_info * TRX_UNDO_CMPL_INFO_MULT;
mach_write_to_1(ptr, type_cmpl); mach_write_to_1(ptr, type_cmpl);
...@@ -480,26 +472,23 @@ trx_undo_page_report_modify( ...@@ -480,26 +472,23 @@ trx_undo_page_report_modify(
/*----------------------------------------*/ /*----------------------------------------*/
/* Store the state of the info bits */ /* Store the state of the info bits */
bits = rec_get_info_bits(rec, dict_table_is_comp(table)); *ptr++ = rec_get_info_bits(rec, dict_table_is_comp(table));
mach_write_to_1(ptr, bits);
ptr += 1;
/* Store the values of the system columns */ /* Store the values of the system columns */
field = rec_get_nth_field(rec, offsets, field = rec_get_nth_field(rec, offsets,
dict_index_get_sys_col_pos( dict_index_get_sys_col_pos(
index, DATA_TRX_ID), &len); index, DATA_TRX_ID), &len);
ut_ad(len == DATA_TRX_ID_LEN); ut_ad(len == DATA_TRX_ID_LEN);
trx_id = trx_read_trx_id(field);
len = mach_dulint_write_compressed(ptr, trx_read_trx_id(field));
ptr += len;
field = rec_get_nth_field(rec, offsets, field = rec_get_nth_field(rec, offsets,
dict_index_get_sys_col_pos( dict_index_get_sys_col_pos(
index, DATA_ROLL_PTR), &len); index, DATA_ROLL_PTR), &len);
ut_ad(len == DATA_ROLL_PTR_LEN); ut_ad(len == DATA_ROLL_PTR_LEN);
roll_ptr = trx_read_roll_ptr(field);
len = mach_dulint_write_compressed(ptr, trx_id);
ptr += len;
len = mach_dulint_write_compressed(ptr, roll_ptr); len = mach_dulint_write_compressed(ptr, trx_read_roll_ptr(field));
ptr += len; ptr += len;
/*----------------------------------------*/ /*----------------------------------------*/
...@@ -543,8 +532,7 @@ trx_undo_page_report_modify( ...@@ -543,8 +532,7 @@ trx_undo_page_report_modify(
for (i = 0; i < upd_get_n_fields(update); i++) { for (i = 0; i < upd_get_n_fields(update); i++) {
upd_field = upd_get_nth_field(update, i); ulint pos = upd_get_nth_field(update, i)->field_no;
pos = upd_field->field_no;
/* Write field number to undo log */ /* Write field number to undo log */
if (trx_undo_left(undo_page, ptr) < 5) { if (trx_undo_left(undo_page, ptr) < 5) {
...@@ -576,8 +564,7 @@ trx_undo_page_report_modify( ...@@ -576,8 +564,7 @@ trx_undo_page_report_modify(
trx->update_undo->del_marks = TRUE; trx->update_undo->del_marks = TRUE;
*type_cmpl_ptr = *type_cmpl_ptr *type_cmpl_ptr |= TRX_UNDO_UPD_EXTERN;
| TRX_UNDO_UPD_EXTERN;
} else { } else {
len = mach_write_compressed(ptr, flen); len = mach_write_compressed(ptr, flen);
} }
...@@ -609,6 +596,7 @@ trx_undo_page_report_modify( ...@@ -609,6 +596,7 @@ trx_undo_page_report_modify(
stored data. */ stored data. */
if (!update || !(cmpl_info & UPD_NODE_NO_ORD_CHANGE)) { if (!update || !(cmpl_info & UPD_NODE_NO_ORD_CHANGE)) {
byte* old_ptr = ptr;
trx->update_undo->del_marks = TRUE; trx->update_undo->del_marks = TRUE;
...@@ -617,8 +605,6 @@ trx_undo_page_report_modify( ...@@ -617,8 +605,6 @@ trx_undo_page_report_modify(
return(0); return(0);
} }
old_ptr = ptr;
/* Reserve 2 bytes to write the number of bytes the stored /* Reserve 2 bytes to write the number of bytes the stored
fields take in this undo record */ fields take in this undo record */
...@@ -632,8 +618,8 @@ trx_undo_page_report_modify( ...@@ -632,8 +618,8 @@ trx_undo_page_report_modify(
if (col->ord_part > 0) { if (col->ord_part > 0) {
pos = dict_index_get_nth_col_pos(index, ulint pos = dict_index_get_nth_col_pos(
col_no); index, col_no);
/* Write field number to undo log */ /* Write field number to undo log */
if (trx_undo_left(undo_page, ptr) < 5) { if (trx_undo_left(undo_page, ptr) < 5) {
...@@ -1018,7 +1004,7 @@ trx_undo_report_row_operation( ...@@ -1018,7 +1004,7 @@ trx_undo_report_row_operation(
the update vector, otherwise NULL */ the update vector, otherwise NULL */
ulint cmpl_info, /* in: compiler info on secondary ulint cmpl_info, /* in: compiler info on secondary
index updates */ index updates */
rec_t* rec, /* in: in case of an update or delete const rec_t* rec, /* in: in case of an update or delete
marking, the record in the clustered marking, the record in the clustered
index, otherwise NULL */ index, otherwise NULL */
dulint* roll_ptr) /* out: rollback pointer to the dulint* roll_ptr) /* out: rollback pointer to the
...@@ -1028,11 +1014,8 @@ trx_undo_report_row_operation( ...@@ -1028,11 +1014,8 @@ trx_undo_report_row_operation(
{ {
trx_t* trx; trx_t* trx;
trx_undo_t* undo; trx_undo_t* undo;
buf_block_t* undo_block;
page_t* undo_page;
ulint offset; ulint offset;
ulint page_no; ulint page_no;
ibool is_insert;
trx_rseg_t* rseg; trx_rseg_t* rseg;
mtr_t mtr; mtr_t mtr;
mem_heap_t* heap = NULL; mem_heap_t* heap = NULL;
...@@ -1068,7 +1051,13 @@ trx_undo_report_row_operation( ...@@ -1068,7 +1051,13 @@ trx_undo_report_row_operation(
} }
undo = trx->insert_undo; undo = trx->insert_undo;
is_insert = TRUE;
if (UNIV_UNLIKELY(!undo)) {
/* Did not succeed: out of space */
mutex_exit(&(trx->undo_mutex));
return(DB_OUT_OF_FILE_SPACE);
}
} else { } else {
ut_ad(op_type == TRX_UNDO_MODIFY_OP); ut_ad(op_type == TRX_UNDO_MODIFY_OP);
...@@ -1079,21 +1068,26 @@ trx_undo_report_row_operation( ...@@ -1079,21 +1068,26 @@ trx_undo_report_row_operation(
} }
undo = trx->update_undo; undo = trx->update_undo;
is_insert = FALSE;
}
if (undo == NULL) { if (UNIV_UNLIKELY(!undo)) {
/* Did not succeed: out of space */ /* Did not succeed: out of space */
mutex_exit(&(trx->undo_mutex)); mutex_exit(&(trx->undo_mutex));
return(DB_OUT_OF_FILE_SPACE); return(DB_OUT_OF_FILE_SPACE);
} }
offsets = rec_get_offsets(rec, index, offsets,
ULINT_UNDEFINED, &heap);
}
page_no = undo->last_page_no; page_no = undo->last_page_no;
mtr_start(&mtr); mtr_start(&mtr);
for (;;) { for (;;) {
buf_block_t* undo_block;
page_t* undo_page;
undo_block = buf_page_get_gen(undo->space, undo->zip_size, undo_block = buf_page_get_gen(undo->space, undo->zip_size,
page_no, RW_X_LATCH, page_no, RW_X_LATCH,
undo->guess_block, BUF_GET, undo->guess_block, BUF_GET,
...@@ -1107,8 +1101,6 @@ trx_undo_report_row_operation( ...@@ -1107,8 +1101,6 @@ trx_undo_report_row_operation(
offset = trx_undo_page_report_insert( offset = trx_undo_page_report_insert(
undo_page, trx, index, clust_entry, &mtr); undo_page, trx, index, clust_entry, &mtr);
} else { } else {
offsets = rec_get_offsets(rec, index, offsets,
ULINT_UNDEFINED, &heap);
offset = trx_undo_page_report_modify( offset = trx_undo_page_report_modify(
undo_page, trx, index, rec, offsets, update, undo_page, trx, index, rec, offsets, update,
cmpl_info, &mtr); cmpl_info, &mtr);
...@@ -1120,13 +1112,21 @@ trx_undo_report_row_operation( ...@@ -1120,13 +1112,21 @@ trx_undo_report_row_operation(
record of it to to ensure deterministic contents. */ record of it to to ensure deterministic contents. */
trx_undo_erase_page_end(undo_page, &mtr); trx_undo_erase_page_end(undo_page, &mtr);
} mtr_commit(&mtr);
} else {
/* Success */
mtr_commit(&mtr); mtr_commit(&mtr);
if (offset != 0) { undo->empty = FALSE;
/* Success */ undo->top_page_no = page_no;
undo->top_offset = offset;
undo->top_undo_no = trx->undo_no;
undo->guess_block = undo_block;
UT_DULINT_INC(trx->undo_no);
mutex_exit(&trx->undo_mutex);
break; break;
} }
...@@ -1146,7 +1146,7 @@ trx_undo_report_row_operation( ...@@ -1146,7 +1146,7 @@ trx_undo_report_row_operation(
mutex_exit(&(rseg->mutex)); mutex_exit(&(rseg->mutex));
if (page_no == FIL_NULL) { if (UNIV_UNLIKELY(page_no == FIL_NULL)) {
/* Did not succeed: out of space */ /* Did not succeed: out of space */
mutex_exit(&(trx->undo_mutex)); mutex_exit(&(trx->undo_mutex));
...@@ -1158,18 +1158,8 @@ trx_undo_report_row_operation( ...@@ -1158,18 +1158,8 @@ trx_undo_report_row_operation(
} }
} }
undo->empty = FALSE; *roll_ptr = trx_undo_build_roll_ptr(op_type == TRX_UNDO_INSERT_OP,
undo->top_page_no = page_no; rseg->id, page_no, offset);
undo->top_offset = offset;
undo->top_undo_no = trx->undo_no;
undo->guess_block = undo_block;
UT_DULINT_INC(trx->undo_no);
mutex_exit(&(trx->undo_mutex));
*roll_ptr = trx_undo_build_roll_ptr(is_insert, rseg->id, page_no,
offset);
if (UNIV_LIKELY_NULL(heap)) { if (UNIV_LIKELY_NULL(heap)) {
mem_heap_free(heap); mem_heap_free(heap);
} }
......
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