IB: misc fixes [#305]

* System fields renamed
* Removed row0ins.ic
* Removed row_update_for_mysql() wrapper
This commit is contained in:
Aleksey Midenkov 2017-11-01 22:13:05 +03:00
parent e674806282
commit 8972291ac1
11 changed files with 93 additions and 139 deletions

View File

@ -304,12 +304,12 @@ dict_mem_table_add_col(
dict_mem_fill_column_struct(col, i, mtype, prtype, len); dict_mem_fill_column_struct(col, i, mtype, prtype, len);
if (prtype & DATA_VERS_ROW_START) { if (prtype & DATA_VERS_START) {
ut_ad(!(prtype & DATA_VERS_ROW_END)); ut_ad(!(prtype & DATA_VERS_END));
table->vers_row_start = i; table->vers_start = i;
} else if (prtype & DATA_VERS_ROW_END) { } else if (prtype & DATA_VERS_END) {
ut_ad(!(prtype & DATA_VERS_ROW_START)); ut_ad(!(prtype & DATA_VERS_START));
table->vers_row_end = i; table->vers_end = i;
} }
} }

View File

@ -11400,9 +11400,9 @@ create_table_info_t::create_table_def()
if (m_form->versioned()) { if (m_form->versioned()) {
if (i == m_form->s->row_start_field) { 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) { } else if (i == m_form->s->row_end_field) {
vers_row_end = DATA_VERS_ROW_END; vers_row_end = DATA_VERS_END;
} }
} }

View File

@ -4971,10 +4971,10 @@ new_clustered_failed:
if (altered_table->versioned()) { if (altered_table->versioned()) {
if (i == altered_table->s->row_start_field) { if (i == altered_table->s->row_start_field) {
field_type |= DATA_VERS_ROW_START; field_type |= DATA_VERS_START;
} else if (i == } else if (i ==
altered_table->s->row_end_field) { altered_table->s->row_end_field) {
field_type |= DATA_VERS_ROW_END; field_type |= DATA_VERS_END;
} }
} }

View File

@ -192,8 +192,9 @@ be less than 256 */
/** Check whether locking is disabled (never). */ /** Check whether locking is disabled (never). */
#define dict_table_is_locking_disabled(table) false #define dict_table_is_locking_disabled(table) false
#define DATA_VERS_ROW_START 0x4000 /* System Versioning row start */ /** System Versioning */
#define DATA_VERS_ROW_END 0x8000 /* System Versioning row end */ #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 /* This many bytes we need to store the type information affecting the

View File

@ -1489,7 +1489,7 @@ struct dict_table_t {
/** Add the table definition to the data dictionary cache */ /** Add the table definition to the data dictionary cache */
void add_to_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. */ /** Id of the table. */
table_id_t id; table_id_t id;
@ -1604,9 +1604,9 @@ struct dict_table_t {
/** Virtual column names */ /** Virtual column names */
const char* v_col_names; const char* v_col_names;
unsigned vers_row_start:10; unsigned vers_start:10;
/*!< System Versioning: row start col index */ /*!< System Versioning: row start col index */
unsigned vers_row_end:10; unsigned vers_end:10;
/*!< System Versioning: row end col index */ /*!< System Versioning: row end col index */
bool is_system_db; bool is_system_db;
/*!< True if the table belongs to a system /*!< True if the table belongs to a system

View File

@ -235,8 +235,57 @@ struct ins_node_t{
#define INS_NODE_INSERT_ENTRIES 3 /* index entries should be built and #define INS_NODE_INSERT_ENTRIES 3 /* index entries should be built and
inserted */ inserted */
#ifndef UNIV_NONINL UNIV_INLINE
#include "row0ins.ic" void row_ins_set_tuple_col_8(
#endif 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 #endif

View File

@ -1,78 +0,0 @@
/*****************************************************************************
Copyright (c) 1996, 2009, Oracle and/or its affiliates. All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
*****************************************************************************/
/**************************************************//**
@file include/row0ins.ic
Insert into a table
Created 4/20/1996 Heikki Tuuri
*******************************************************/
UNIV_INLINE
void 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 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 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;
}

View File

@ -27,11 +27,6 @@ Created 4/20/1996 Heikki Tuuri
#include "ha_prototypes.h" #include "ha_prototypes.h"
#include "row0ins.h" #include "row0ins.h"
#ifdef UNIV_NONINL
#include "row0ins.ic"
#endif
#include "dict0dict.h" #include "dict0dict.h"
#include "dict0boot.h" #include "dict0boot.h"
#include "trx0rec.h" #include "trx0rec.h"
@ -1593,7 +1588,7 @@ row_ins_get_sys_trx_end(
ulint len; ulint len;
ulint nfield = dict_col_get_clust_pos( 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); const byte *field = rec_get_nth_field(rec, offsets, nfield, &len);
ut_a(len == 8); ut_a(len == 8);
return(mach_read_from_8(field)); return(mach_read_from_8(field));
@ -1706,7 +1701,7 @@ row_ins_check_foreign_constraint(
/* System Versioning: if sys_trx_end != Inf, we /* System Versioning: if sys_trx_end != Inf, we
suppress the foreign key check */ suppress the foreign key check */
if (table->with_versioning() && 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)); byte* data = static_cast<byte*>(dfield_get_data(field));
ut_ad(data); ut_ad(data);
trx_id_t end_trx_id = mach_read_from_8(data); trx_id_t end_trx_id = mach_read_from_8(data);
@ -4064,12 +4059,12 @@ void vers_notify_vtq(trx_t* trx)
mutex_exit(&trx_sys->mutex); mutex_exit(&trx_sys->mutex);
dict_table_copy_types(tuple, dict_sys->sys_vtq); dict_table_copy_types(tuple, dict_sys->sys_vtq);
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__TRX_ID, trx->id, heap);
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__COMMIT_ID, commit_id, heap);
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__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__COMMIT_TS, commit_ts, heap);
ut_ad(trx->isolation_level < 256); 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); err = vers_row_ins_vtq_low(trx, heap, tuple);
if (DB_SUCCESS != err) if (DB_SUCCESS != err)

View File

@ -2243,7 +2243,7 @@ end_of_index:
bool historical_row = false; bool historical_row = false;
if (new_table->with_versioning()) { if (new_table->with_versioning()) {
const dfield_t *dfield = dtuple_get_nth_field( 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 *>( const byte *data = static_cast<const byte *>(
dfield_get_data(dfield)); dfield_get_data(dfield));
ut_ad(dfield_get_len(dfield) == 8); ut_ad(dfield_get_len(dfield) == 8);
@ -2306,13 +2306,13 @@ end_of_index:
if (old_table->with_versioning()) { if (old_table->with_versioning()) {
if (new_table->with_versioning() && !drop_historical) { if (new_table->with_versioning() && !drop_historical) {
dfield_t *end = dtuple_get_nth_field( dfield_t *end = dtuple_get_nth_field(
row, new_table->vers_row_end); row, new_table->vers_end);
byte *data = static_cast<byte *>( byte *data = static_cast<byte *>(
dfield_get_data(end)); dfield_get_data(end));
ut_ad(data); ut_ad(data);
if (mach_read_from_8(data) == TRX_ID_MAX) { if (mach_read_from_8(data) == TRX_ID_MAX) {
dfield_t *start = dtuple_get_nth_field( dfield_t *start = dtuple_get_nth_field(
row, new_table->vers_row_start); row, new_table->vers_start);
void *data = dfield_get_data(start); void *data = dfield_get_data(start);
ut_ad(data); ut_ad(data);
mach_write_to_8(data, trx->id); mach_write_to_8(data, trx->id);
@ -2320,7 +2320,7 @@ end_of_index:
} else { } else {
const dict_col_t *col = const dict_col_t *col =
&old_table->cols &old_table->cols
[old_table->vers_row_end]; [old_table->vers_end];
const ulint nfield = dict_col_get_clust_pos( const ulint nfield = dict_col_get_clust_pos(
col, clust_index); col, clust_index);
ulint len = 0; ulint len = 0;
@ -2336,9 +2336,9 @@ end_of_index:
mach_write_to_8(sys_trx_start, trx->id); mach_write_to_8(sys_trx_start, trx->id);
mach_write_to_8(sys_trx_end, TRX_ID_MAX); mach_write_to_8(sys_trx_end, TRX_ID_MAX);
dfield_t *start = dtuple_get_nth_field( 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( 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(start, sys_trx_start, 8);
dfield_set_data(end, sys_trx_end, 8); dfield_set_data(end, sys_trx_end, 8);
} }

View File

@ -1497,21 +1497,21 @@ row_insert_for_mysql(
if (ins_mode != ROW_INS_NORMAL) 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 /* Return back modified fields into mysql_rec, so that
upper logic may benefit from it (f.ex. 'on duplicate key'). */ 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); ut_ad(t->mysql_col_len == 8);
if (ins_mode == ROW_INS_HISTORICAL) { 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 */ { 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); 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); 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); int8store(&mysql_rec[t->mysql_col_offset], trx->id);
} }
} }
@ -1865,7 +1865,7 @@ public:
@param[in,out] prebuilt prebuilt struct in MySQL handle @param[in,out] prebuilt prebuilt struct in MySQL handle
@return error code or DB_SUCCESS */ @return error code or DB_SUCCESS */
dberr_t dberr_t
row_update_for_mysql_using_upd_graph( row_update_for_mysql(
row_prebuilt_t* prebuilt, row_prebuilt_t* prebuilt,
bool vers_set_fields) bool vers_set_fields)
{ {
@ -2008,11 +2008,11 @@ run_again:
uvect->n_fields = 0; uvect->n_fields = 0;
node->is_delete = false; node->is_delete = false;
node->vers_delete = true; node->vers_delete = true;
col_idx = table->vers_row_end; col_idx = table->vers_end;
} else { } else {
ut_ad(uvect->n_fields < table->n_cols); ut_ad(uvect->n_fields < table->n_cols);
ufield = &uvect->fields[uvect->n_fields]; ufield = &uvect->fields[uvect->n_fields];
col_idx = table->vers_row_start; col_idx = table->vers_start;
} }
col = &table->cols[col_idx]; col = &table->cols[col_idx];
UNIV_MEM_INVALID(ufield, sizeof *ufield); UNIV_MEM_INVALID(ufield, sizeof *ufield);
@ -2050,6 +2050,7 @@ run_again:
err = trx->error_state; err = trx->error_state;
if (err != DB_SUCCESS) { if (err != DB_SUCCESS) {
que_thr_stop_for_mysql(thr); que_thr_stop_for_mysql(thr);
if (err == DB_RECORD_NOT_FOUND) { if (err == DB_RECORD_NOT_FOUND) {
@ -2260,20 +2261,6 @@ error:
DBUG_RETURN(err); 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 /** 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. session is using a READ COMMITTED or READ UNCOMMITTED isolation level.
Before calling this function row_search_for_mysql() must have Before calling this function row_search_for_mysql() must have

View File

@ -19,7 +19,7 @@
#include "btr0pcur.h" #include "btr0pcur.h"
#include "dict0load.h" #include "dict0load.h"
#include "ha_innodb.h" #include "ha_innodb.h"
#include "row0ins.ic" #include "row0ins.h"
#include "row0row.h" #include "row0row.h"
#include "trx0trx.h" #include "trx0trx.h"
#include "trx0types.h" #include "trx0types.h"
@ -347,7 +347,7 @@ vtq_query_commit_ts(
tuple = dtuple_create(heap, 1); tuple = dtuple_create(heap, 1);
dict_index_copy_types(tuple, index, 1); dict_index_copy_types(tuple, index, 1);
dtuple_get_nth_field(tuple, 0)->len = UNIV_SQL_NULL; dtuple_get_nth_field(tuple, 0)->len = UNIV_SQL_NULL;
set_tuple_col_8(tuple, 0, commit_ts, heap); row_ins_set_tuple_col_8(tuple, 0, commit_ts, heap);
mtr_start_trx(&mtr, trx); mtr_start_trx(&mtr, trx);
btr_pcur_open_on_user_rec(index, tuple, mode, btr_pcur_open_on_user_rec(index, tuple, mode,