Skip to content

Commit

Permalink
IB: misc fixes [#305]
Browse files Browse the repository at this point in the history
* System fields renamed
* Removed row0ins.ic
* Removed row_update_for_mysql() wrapper
  • Loading branch information
midenok committed Nov 10, 2017
1 parent ea6addd commit fe18ff1
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 139 deletions.
12 changes: 6 additions & 6 deletions storage/innobase/dict/dict0mem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,12 @@ dict_mem_table_add_col(

dict_mem_fill_column_struct(col, i, mtype, prtype, len);

if (prtype & DATA_VERS_ROW_START) {
ut_ad(!(prtype & DATA_VERS_ROW_END));
table->vers_row_start = i;
} else if (prtype & DATA_VERS_ROW_END) {
ut_ad(!(prtype & DATA_VERS_ROW_START));
table->vers_row_end = i;
if (prtype & DATA_VERS_START) {
ut_ad(!(prtype & DATA_VERS_END));
table->vers_start = i;
} else if (prtype & DATA_VERS_END) {
ut_ad(!(prtype & DATA_VERS_START));
table->vers_end = i;
}
}

Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/handler/ha_innodb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11400,9 +11400,9 @@ create_table_info_t::create_table_def()

if (m_form->versioned()) {
if (i == m_form->s->row_start_field) {
vers_row_start = DATA_VERS_ROW_START;
vers_row_start = DATA_VERS_START;
} else if (i == m_form->s->row_end_field) {
vers_row_end = DATA_VERS_ROW_END;
vers_row_end = DATA_VERS_END;
}
}

Expand Down
4 changes: 2 additions & 2 deletions storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4901,10 +4901,10 @@ prepare_inplace_alter_table_dict(

if (altered_table->versioned()) {
if (i == altered_table->s->row_start_field) {
field_type |= DATA_VERS_ROW_START;
field_type |= DATA_VERS_START;
} else if (i ==
altered_table->s->row_end_field) {
field_type |= DATA_VERS_ROW_END;
field_type |= DATA_VERS_END;
}
}

Expand Down
5 changes: 3 additions & 2 deletions storage/innobase/include/data0type.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ be less than 256 */
/** Check whether locking is disabled (never). */
#define dict_table_is_locking_disabled(table) false

#define DATA_VERS_ROW_START 0x4000 /* System Versioning row start */
#define DATA_VERS_ROW_END 0x8000 /* System Versioning row end */
/** System Versioning */
#define DATA_VERS_START 0x4000 /* start system field */
#define DATA_VERS_END 0x8000 /* end system field */
/*-------------------------------------------*/

/* This many bytes we need to store the type information affecting the
Expand Down
6 changes: 3 additions & 3 deletions storage/innobase/include/dict0mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ struct dict_table_t {
/** Add the table definition to the data dictionary cache */
void add_to_cache();

bool with_versioning() const { return vers_row_start || vers_row_end; }
bool with_versioning() const { return vers_start || vers_end; }

/** Id of the table. */
table_id_t id;
Expand Down Expand Up @@ -1604,9 +1604,9 @@ struct dict_table_t {

/** Virtual column names */
const char* v_col_names;
unsigned vers_row_start:10;
unsigned vers_start:10;
/*!< System Versioning: row start col index */
unsigned vers_row_end:10;
unsigned vers_end:10;
/*!< System Versioning: row end col index */
bool is_system_db;
/*!< True if the table belongs to a system
Expand Down
55 changes: 52 additions & 3 deletions storage/innobase/include/row0ins.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,57 @@ struct ins_node_t{
#define INS_NODE_INSERT_ENTRIES 3 /* index entries should be built and
inserted */

#ifndef UNIV_NONINL
#include "row0ins.ic"
#endif
UNIV_INLINE
void row_ins_set_tuple_col_8(
dtuple_t* tuple,
int col,
ib_uint64_t data,
mem_heap_t* heap)
{
static const ulint fsize = sizeof(data);
dfield_t* dfield = dtuple_get_nth_field(tuple, col);
ut_ad(dfield->type.len == fsize);
if (dfield->len == UNIV_SQL_NULL) {
byte* buf = reinterpret_cast<byte*>(mem_heap_alloc(heap, fsize));
dfield_set_data(dfield, buf, fsize);
}
ut_ad(dfield->len == dfield->type.len && dfield->data);
mach_write_to_8(dfield->data, data);
}

UNIV_INLINE
void row_ins_set_tuple_col_8(
dtuple_t* tuple,
int col,
timeval& data,
mem_heap_t* heap)
{
dfield_t* dfield = dtuple_get_nth_field(tuple, col);
ut_ad(dfield->type.len == 8);
if (dfield->len == UNIV_SQL_NULL) {
byte* buf = reinterpret_cast<byte*>(mem_heap_alloc(heap, 8));
dfield_set_data(dfield, buf, 8);
}
ut_ad(dfield->len == dfield->type.len && dfield->data);
mach_write_to_4(reinterpret_cast<byte*>(dfield->data), (ulint) data.tv_sec);
mach_write_to_4(reinterpret_cast<byte*>(dfield->data) + 4, (ulint) data.tv_usec);
}

UNIV_INLINE
void row_ins_set_tuple_col_1(
dtuple_t* tuple,
int col,
byte data,
mem_heap_t* heap)
{
dfield_t* dfield = dtuple_get_nth_field(tuple, col);
ut_ad(dfield->type.len == 1);
if (dfield->len == UNIV_SQL_NULL) {
byte* buf = reinterpret_cast<byte*>(mem_heap_alloc(heap, 1));
dfield_set_data(dfield, buf, 1);
}
ut_ad(dfield->len == dfield->type.len && dfield->data);
*(byte*)(dfield->data) = data;
}

#endif
78 changes: 0 additions & 78 deletions storage/innobase/include/row0ins.ic

This file was deleted.

19 changes: 7 additions & 12 deletions storage/innobase/row/row0ins.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ Created 4/20/1996 Heikki Tuuri
#include "ha_prototypes.h"

#include "row0ins.h"

#ifdef UNIV_NONINL
#include "row0ins.ic"
#endif

#include "dict0dict.h"
#include "dict0boot.h"
#include "trx0rec.h"
Expand Down Expand Up @@ -1593,7 +1588,7 @@ row_ins_get_sys_trx_end(

ulint len;
ulint nfield = dict_col_get_clust_pos(
&index->table->cols[index->table->vers_row_end], index);
&index->table->cols[index->table->vers_end], index);
const byte *field = rec_get_nth_field(rec, offsets, nfield, &len);
ut_a(len == 8);
return(mach_read_from_8(field));
Expand Down Expand Up @@ -1706,7 +1701,7 @@ row_ins_check_foreign_constraint(
/* System Versioning: if sys_trx_end != Inf, we
suppress the foreign key check */
if (table->with_versioning() &&
dfield_get_type(field)->prtype & DATA_VERS_ROW_END) {
dfield_get_type(field)->prtype & DATA_VERS_END) {
byte* data = static_cast<byte*>(dfield_get_data(field));
ut_ad(data);
trx_id_t end_trx_id = mach_read_from_8(data);
Expand Down Expand Up @@ -4065,12 +4060,12 @@ void vers_notify_vtq(trx_t* trx)
mutex_exit(&trx_sys->mutex);

dict_table_copy_types(tuple, dict_sys->sys_vtq);
set_tuple_col_8(tuple, DICT_COL__SYS_VTQ__TRX_ID, trx->id, heap);
set_tuple_col_8(tuple, DICT_COL__SYS_VTQ__COMMIT_ID, commit_id, heap);
set_tuple_col_8(tuple, DICT_COL__SYS_VTQ__BEGIN_TS, begin_ts, heap);
set_tuple_col_8(tuple, DICT_COL__SYS_VTQ__COMMIT_TS, commit_ts, heap);
row_ins_set_tuple_col_8(tuple, DICT_COL__SYS_VTQ__TRX_ID, trx->id, heap);
row_ins_set_tuple_col_8(tuple, DICT_COL__SYS_VTQ__COMMIT_ID, commit_id, heap);
row_ins_set_tuple_col_8(tuple, DICT_COL__SYS_VTQ__BEGIN_TS, begin_ts, heap);
row_ins_set_tuple_col_8(tuple, DICT_COL__SYS_VTQ__COMMIT_TS, commit_ts, heap);
ut_ad(trx->isolation_level < 256);
set_tuple_col_1(tuple, DICT_COL__SYS_VTQ__ISOLATION_LEVEL, trx->isolation_level, heap);
row_ins_set_tuple_col_1(tuple, DICT_COL__SYS_VTQ__ISOLATION_LEVEL, trx->isolation_level, heap);

err = vers_row_ins_vtq_low(trx, heap, tuple);
if (DB_SUCCESS != err)
Expand Down
12 changes: 6 additions & 6 deletions storage/innobase/row/row0merge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@ row_merge_read_clustered_index(
bool historical_row = false;
if (new_table->with_versioning()) {
const dfield_t *dfield = dtuple_get_nth_field(
row, new_table->vers_row_end);
row, new_table->vers_end);
const byte *data = static_cast<const byte *>(
dfield_get_data(dfield));
ut_ad(dfield_get_len(dfield) == 8);
Expand Down Expand Up @@ -2306,21 +2306,21 @@ row_merge_read_clustered_index(
if (old_table->with_versioning()) {
if (new_table->with_versioning() && !drop_historical) {
dfield_t *end = dtuple_get_nth_field(
row, new_table->vers_row_end);
row, new_table->vers_end);
byte *data = static_cast<byte *>(
dfield_get_data(end));
ut_ad(data);
if (mach_read_from_8(data) == TRX_ID_MAX) {
dfield_t *start = dtuple_get_nth_field(
row, new_table->vers_row_start);
row, new_table->vers_start);
void *data = dfield_get_data(start);
ut_ad(data);
mach_write_to_8(data, trx->id);
}
} else {
const dict_col_t *col =
&old_table->cols
[old_table->vers_row_end];
[old_table->vers_end];
const ulint nfield = dict_col_get_clust_pos(
col, clust_index);
ulint len = 0;
Expand All @@ -2336,9 +2336,9 @@ row_merge_read_clustered_index(
mach_write_to_8(sys_trx_start, trx->id);
mach_write_to_8(sys_trx_end, TRX_ID_MAX);
dfield_t *start = dtuple_get_nth_field(
row, new_table->vers_row_start);
row, new_table->vers_start);
dfield_t *end = dtuple_get_nth_field(
row, new_table->vers_row_end);
row, new_table->vers_end);
dfield_set_data(start, sys_trx_start, 8);
dfield_set_data(end, sys_trx_end, 8);
}
Expand Down
33 changes: 10 additions & 23 deletions storage/innobase/row/row0mysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1497,21 +1497,21 @@ row_insert_for_mysql(

if (ins_mode != ROW_INS_NORMAL)
{
ut_ad(table->vers_row_start != table->vers_row_end);
ut_ad(table->vers_start != table->vers_end);
/* Return back modified fields into mysql_rec, so that
upper logic may benefit from it (f.ex. 'on duplicate key'). */
const mysql_row_templ_t* t = &prebuilt->mysql_template[table->vers_row_end];
const mysql_row_templ_t* t = &prebuilt->mysql_template[table->vers_end];
ut_ad(t->mysql_col_len == 8);

if (ins_mode == ROW_INS_HISTORICAL) {
set_tuple_col_8(node->row, table->vers_row_end, trx->id, node->entry_sys_heap);
row_ins_set_tuple_col_8(node->row, table->vers_end, trx->id, node->entry_sys_heap);
}
else /* ROW_INS_VERSIONED */ {
set_tuple_col_8(node->row, table->vers_row_end, IB_UINT64_MAX, node->entry_sys_heap);
row_ins_set_tuple_col_8(node->row, table->vers_end, IB_UINT64_MAX, node->entry_sys_heap);
int8store(&mysql_rec[t->mysql_col_offset], IB_UINT64_MAX);
t = &prebuilt->mysql_template[table->vers_row_start];
t = &prebuilt->mysql_template[table->vers_start];
ut_ad(t->mysql_col_len == 8);
set_tuple_col_8(node->row, table->vers_row_start, trx->id, node->entry_sys_heap);
row_ins_set_tuple_col_8(node->row, table->vers_start, trx->id, node->entry_sys_heap);
int8store(&mysql_rec[t->mysql_col_offset], trx->id);
}
}
Expand Down Expand Up @@ -1865,7 +1865,7 @@ class ib_dec_counter {
@param[in,out] prebuilt prebuilt struct in MySQL handle
@return error code or DB_SUCCESS */
dberr_t
row_update_for_mysql_using_upd_graph(
row_update_for_mysql(
row_prebuilt_t* prebuilt,
bool vers_set_fields)
{
Expand Down Expand Up @@ -2008,11 +2008,11 @@ row_update_for_mysql_using_upd_graph(
uvect->n_fields = 0;
node->is_delete = false;
node->vers_delete = true;
col_idx = table->vers_row_end;
col_idx = table->vers_end;
} else {
ut_ad(uvect->n_fields < table->n_cols);
ufield = &uvect->fields[uvect->n_fields];
col_idx = table->vers_row_start;
col_idx = table->vers_start;
}
col = &table->cols[col_idx];
UNIV_MEM_INVALID(ufield, sizeof *ufield);
Expand Down Expand Up @@ -2050,6 +2050,7 @@ row_update_for_mysql_using_upd_graph(
err = trx->error_state;

if (err != DB_SUCCESS) {

que_thr_stop_for_mysql(thr);

if (err == DB_RECORD_NOT_FOUND) {
Expand Down Expand Up @@ -2260,20 +2261,6 @@ row_update_for_mysql_using_upd_graph(
DBUG_RETURN(err);
}

/** Does an update or delete of a row for MySQL.
@param[in] mysql_rec row in the MySQL format
@param[in,out] prebuilt prebuilt struct in MySQL handle
@return error code or DB_SUCCESS */
dberr_t
row_update_for_mysql(
row_prebuilt_t* prebuilt,
bool vers_set_fields)
{
ut_a(prebuilt->template_type == ROW_MYSQL_WHOLE_ROW);
return (row_update_for_mysql_using_upd_graph(
prebuilt, vers_set_fields));
}

/** This can only be used when srv_locks_unsafe_for_binlog is TRUE or this
session is using a READ COMMITTED or READ UNCOMMITTED isolation level.
Before calling this function row_search_for_mysql() must have
Expand Down

0 comments on commit fe18ff1

Please sign in to comment.