Commit 8972291a authored by Aleksey Midenkov's avatar Aleksey Midenkov

IB: misc fixes [#305]

* System fields renamed
* Removed row0ins.ic
* Removed row_update_for_mysql() wrapper
parent e6748062
......@@ -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;
}
}
......
......@@ -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;
}
}
......
......@@ -4971,10 +4971,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;
}
}
......
......@@ -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
......
......@@ -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;
......@@ -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
......
......@@ -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
/*****************************************************************************
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;
}
......@@ -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"
......@@ -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));
......@@ -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);
......@@ -4064,12 +4059,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)
......
......@@ -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);
......@@ -2306,13 +2306,13 @@ 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);
......@@ -2320,7 +2320,7 @@ row_merge_read_clustered_index(
} 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;
......@@ -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);
}
......
......@@ -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);
}
}
......@@ -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)
{
......@@ -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);
......@@ -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) {
......@@ -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
......
......@@ -19,7 +19,7 @@
#include "btr0pcur.h"
#include "dict0load.h"
#include "ha_innodb.h"
#include "row0ins.ic"
#include "row0ins.h"
#include "row0row.h"
#include "trx0trx.h"
#include "trx0types.h"
......@@ -347,7 +347,7 @@ vtq_query_commit_ts(
tuple = dtuple_create(heap, 1);
dict_index_copy_types(tuple, index, 1);
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);
btr_pcur_open_on_user_rec(index, tuple, mode,
......
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