Commit cbe93291 authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL,IB: add auto_inc copy mode fix [#347]

Related to #212.

Extra update of sys_trx_start removed [#87].
parent b612f3ba
......@@ -466,10 +466,18 @@ Table Create Table
t CREATE TABLE `t` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1
call verify_vtq;
No A B C D
create or replace table t (a int) with system versioning engine=innodb;
insert into t values (1), (2), (3);
delete from t where a<3;
call verify_vtq;
No A B C D
1 1 1 1 1
2 1 1 1 1
alter table t add b int auto_increment unique;
call verify_vtq;
No A B C D
select * from t for system_time all;
a b
1 -1
......@@ -482,6 +490,9 @@ a b
2 -2
3 1
4 2
call verify_vtq;
No A B C D
1 1 1 1 1
create or replace table t (a int) with system versioning;
insert into t values (1), (2), (3);
delete from t where a<3;
......@@ -501,7 +512,13 @@ a b
create or replace table t (a int) with system versioning engine=innodb;
insert into t values (1), (2), (3);
delete from t where a<3;
call verify_vtq;
No A B C D
1 1 1 1 1
2 1 1 1 1
alter table t add b tinyint auto_increment unique;
call verify_vtq;
No A B C D
select * from t for system_time all;
a b
1 -1
......@@ -514,6 +531,9 @@ a b
2 -2
3 1
4 2
call verify_vtq;
No A B C D
1 1 1 1 1
create or replace table t (a int) with system versioning;
insert into t values (1), (2), (3);
delete from t where a<3;
......@@ -610,15 +630,6 @@ call verify_vtq;
No A B C D
1 1 1 1 1
2 1 1 1 1
3 1 1 1 1
4 1 1 1 1
5 1 1 1 1
6 1 1 1 1
7 1 1 1 1
8 1 1 1 1
9 1 1 1 1
10 1 1 1 1
11 1 1 1 1
drop table t;
drop procedure verify_vtq;
drop procedure innodb_verify_vtq;
......
......@@ -194,14 +194,18 @@ select * from t for system_time all;
alter table t drop system versioning, algorithm=copy;
show create table t;
call verify_vtq;
create or replace table t (a int) with system versioning engine=innodb;
insert into t values (1), (2), (3);
delete from t where a<3;
call verify_vtq;
alter table t add b int auto_increment unique;
call verify_vtq;
select * from t for system_time all;
insert into t values (4, NULL);
select * from t for system_time all;
call verify_vtq;
create or replace table t (a int) with system versioning;
insert into t values (1), (2), (3);
......@@ -214,10 +218,13 @@ select * from t for system_time all;
create or replace table t (a int) with system versioning engine=innodb;
insert into t values (1), (2), (3);
delete from t where a<3;
call verify_vtq;
alter table t add b tinyint auto_increment unique;
call verify_vtq;
select * from t for system_time all;
insert into t values (4, NULL);
select * from t for system_time all;
call verify_vtq;
create or replace table t (a int) with system versioning;
insert into t values (1), (2), (3);
......
......@@ -3036,7 +3036,7 @@ int handler::update_auto_increment()
DBUG_ENTER("handler::update_auto_increment");
// System Versioning: handle ALTER ADD COLUMN AUTO_INCREMENT
if (thd->lex->sql_command == SQLCOM_ALTER_TABLE && table->versioned_by_sql())
if (thd->lex->sql_command == SQLCOM_ALTER_TABLE && table->versioned())
{
Field *end= table->vers_end_field();
DBUG_ASSERT(end);
......
......@@ -10180,14 +10180,9 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
if (keep_versioned && to->versioned_by_engine() &&
thd->variables.vers_alter_history != VERS_ALTER_HISTORY_SURVIVE)
{
to->s->versioned= false;
to->vers_write= false;
}
error= to->file->ha_write_row(to->record[0]);
if (keep_versioned && to->versioned_by_engine() &&
thd->variables.vers_alter_history != VERS_ALTER_HISTORY_SURVIVE)
{
to->s->versioned= true;
}
to->auto_increment_field_not_null= FALSE;
if (error)
{
......
......@@ -3216,9 +3216,13 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
*fptr++ = outparam->field[i];
}
(*fptr)= 0; // End marker
outparam->vers_write= true;
}
else
{
outparam->non_generated_field= NULL;
outparam->vers_write= false;
}
if (share->found_next_number_field)
outparam->found_next_number_field=
......
......@@ -1505,6 +1505,7 @@ struct TABLE
/**
System Versioning support
*/
bool vers_write;
bool versioned() const
{
......@@ -1512,6 +1513,12 @@ struct TABLE
return s->versioned;
}
bool versioned_write() const
{
DBUG_ASSERT(versioned() || !vers_write);
return vers_write;
}
/* Versioned by SQL layer */
bool versioned_by_sql() const
{
......
......@@ -186,9 +186,9 @@ VTMD_table::update(THD *thd, const char* archive_name)
vtmd.table->mark_columns_needed_for_update(); // not needed?
if (archive_name)
{
vtmd.table->s->versioned= false;
vtmd.table->vers_write= false;
error= vtmd.table->file->ha_update_row(vtmd.table->record[1], vtmd.table->record[0]);
vtmd.table->s->versioned= true;
vtmd.table->vers_write= true;
if (!error)
{
......@@ -220,9 +220,9 @@ VTMD_table::update(THD *thd, const char* archive_name)
store_record(vtmd.table, record[1]);
vtmd.table->field[FLD_ARCHIVE_NAME]->store(archive_name, an_len, table_alias_charset);
vtmd.table->field[FLD_ARCHIVE_NAME]->set_notnull();
vtmd.table->s->versioned= false;
vtmd.table->vers_write= false;
error= vtmd.table->file->ha_update_row(vtmd.table->record[1], vtmd.table->record[0]);
vtmd.table->s->versioned= true;
vtmd.table->vers_write= true;
if (error)
goto err;
sys_trx_end= (ulonglong) vtmd.table->vers_start_field()->val_int();
......
......@@ -8369,7 +8369,7 @@ ha_innobase::write_row(
innobase_srv_conc_enter_innodb(m_prebuilt);
vers_set_fields = (table->versioned() &&
vers_set_fields = (table->versioned_write() &&
(sql_command != SQLCOM_CREATE_TABLE || table->s->vtmd))
?
ROW_INS_VERSIONED :
......@@ -9179,7 +9179,7 @@ ha_innobase::update_row(
innobase_srv_conc_enter_innodb(m_prebuilt);
if (!table->versioned())
if (!table->versioned_write())
m_prebuilt->upd_node->versioned = false;
if (m_prebuilt->upd_node->versioned) {
......@@ -9317,7 +9317,7 @@ ha_innobase::delete_row(
innobase_srv_conc_enter_innodb(m_prebuilt);
bool vers_set_fields =
table->versioned() &&
table->versioned_write() &&
table->vers_end_field()->is_max();
error = row_update_for_mysql(m_prebuilt, vers_set_fields);
......
......@@ -2304,21 +2304,7 @@ row_merge_read_clustered_index(
}
if (old_table->versioned()) {
if (new_table->versioned() && !drop_historical) {
dfield_t *end = dtuple_get_nth_field(
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_start);
void *data = dfield_get_data(start);
ut_ad(data);
mach_write_to_8(data, trx->id);
trx->vers_update_trt= true;
}
} else {
if (!new_table->versioned() || drop_historical) {
const dict_col_t *col =
&old_table->cols
[old_table->vers_end];
......
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