Skip to content

Commit 5d506ac

Browse files
committed
MDEV-25004 vers_force_trx option to force transactional System Versioning
Works like vers_force but forces trx_id-based system-versioned tables if the storage supports it (currently InnoDB-only). Otherwise creates timestamp-based system-versioned table.
1 parent 7c5609f commit 5d506ac

File tree

4 files changed

+41
-23
lines changed

4 files changed

+41
-23
lines changed

sql/handler.cc

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6976,7 +6976,6 @@ static Create_field *vers_init_sys_field(THD *thd, const char *field_name, int f
69766976
f->flags= flags | NOT_NULL_FLAG;
69776977
if (integer)
69786978
{
6979-
DBUG_ASSERT(0); // Not implemented yet
69806979
f->set_handler(&type_handler_vers_trx_id);
69816980
f->length= MY_INT64_NUM_DECIMAL_DIGITS - 1;
69826981
f->flags|= UNSIGNED_FLAG;
@@ -6994,10 +6993,13 @@ static Create_field *vers_init_sys_field(THD *thd, const char *field_name, int f
69946993
return f;
69956994
}
69966995

6997-
static bool vers_create_sys_field(THD *thd, const char *field_name,
6998-
Alter_info *alter_info, int flags)
6996+
bool Vers_parse_info::create_sys_field(THD *thd, const char *field_name,
6997+
Alter_info *alter_info, int flags)
69996998
{
7000-
Create_field *f= vers_init_sys_field(thd, field_name, flags, false);
6999+
DBUG_ASSERT(can_native >= 0); /* Requires vers_check_native() called */
7000+
Create_field *f= vers_init_sys_field(thd, field_name, flags,
7001+
DBUG_EVALUATE_IF("sysvers_force_trx",
7002+
(bool) can_native, false));
70017003
if (!f)
70027004
return true;
70037005

@@ -7021,23 +7023,34 @@ bool Vers_parse_info::fix_implicit(THD *thd, Alter_info *alter_info)
70217023
system_time= start_end_t(default_start, default_end);
70227024
as_row= system_time;
70237025

7024-
if (vers_create_sys_field(thd, default_start, alter_info, VERS_ROW_START) ||
7025-
vers_create_sys_field(thd, default_end, alter_info, VERS_ROW_END))
7026+
if (create_sys_field(thd, default_start, alter_info, VERS_ROW_START) ||
7027+
create_sys_field(thd, default_end, alter_info, VERS_ROW_END))
70267028
{
70277029
return true;
70287030
}
70297031
return false;
70307032
}
70317033

70327034

7035+
void Table_scope_and_contents_source_st::vers_check_native()
7036+
{
7037+
vers_info.can_native= (db_type->db_type == DB_TYPE_PARTITION_DB ||
7038+
ha_check_storage_engine_flag(db_type,
7039+
HTON_NATIVE_SYS_VERSIONING));
7040+
}
7041+
7042+
70337043
bool Table_scope_and_contents_source_st::vers_fix_system_fields(
70347044
THD *thd, Alter_info *alter_info, const TABLE_LIST &create_table)
70357045
{
70367046
DBUG_ASSERT(!(alter_info->flags & ALTER_DROP_SYSTEM_VERSIONING));
70377047

7038-
DBUG_EXECUTE_IF("sysvers_force", if (!tmp_table()) {
7039-
alter_info->flags|= ALTER_ADD_SYSTEM_VERSIONING;
7040-
options|= HA_VERSIONED_TABLE; });
7048+
if (DBUG_EVALUATE_IF("sysvers_force", true, false) ||
7049+
DBUG_EVALUATE_IF("sysvers_force_trx", true, false))
7050+
{
7051+
alter_info->flags|= ALTER_ADD_SYSTEM_VERSIONING;
7052+
options|= HA_VERSIONED_TABLE;
7053+
}
70417054

70427055
if (!vers_info.need_check(alter_info))
70437056
return false;
@@ -7068,7 +7081,9 @@ bool Table_scope_and_contents_source_st::vers_fix_system_fields(
70687081
{
70697082
f->flags|= VERS_UPDATE_UNVERSIONED_FLAG;
70707083
}
7071-
} // while (Create_field *f= it++)
7084+
} // while
7085+
7086+
vers_check_native();
70727087

70737088
if (vers_info.fix_implicit(thd, alter_info))
70747089
return true;
@@ -7121,11 +7136,7 @@ bool Table_scope_and_contents_source_st::vers_check_system_fields(
71217136
if (!(alter_info->flags & ALTER_ADD_SYSTEM_VERSIONING) && !versioned_fields)
71227137
return false;
71237138

7124-
bool can_native= ha_check_storage_engine_flag(db_type,
7125-
HTON_NATIVE_SYS_VERSIONING)
7126-
|| db_type->db_type == DB_TYPE_PARTITION_DB;
7127-
7128-
return vers_info.check_sys_fields(table_name, db, alter_info, can_native);
7139+
return vers_info.check_sys_fields(table_name, db, alter_info);
71297140
}
71307141

71317142

@@ -7138,7 +7149,8 @@ bool Vers_parse_info::fix_alter_info(THD *thd, Alter_info *alter_info,
71387149
if (!need_check(alter_info) && !share->versioned)
71397150
return false;
71407151

7141-
if (DBUG_EVALUATE_IF("sysvers_force", 0, share->tmp_table))
7152+
if (DBUG_EVALUATE_IF("sysvers_force", 0, share->tmp_table) ||
7153+
DBUG_EVALUATE_IF("sysvers_force_trx", 0, share->tmp_table))
71427154
{
71437155
my_error(ER_VERS_TEMPORARY, MYF(0));
71447156
return true;
@@ -7383,8 +7395,7 @@ bool Create_field::vers_check_bigint(const Lex_table_name &table_name) const
73837395

73847396
bool Vers_parse_info::check_sys_fields(const Lex_table_name &table_name,
73857397
const Lex_table_name &db,
7386-
Alter_info *alter_info,
7387-
bool can_native) const
7398+
Alter_info *alter_info) const
73887399
{
73897400
if (check_conditions(table_name, db))
73907401
return true;

sql/handler.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,8 @@ struct Vers_parse_info
18811881
{
18821882
Vers_parse_info() :
18831883
versioned_fields(false),
1884-
unversioned_fields(false)
1884+
unversioned_fields(false),
1885+
can_native(-1)
18851886
{}
18861887

18871888
void init() // Deep initialization
@@ -1890,6 +1891,7 @@ struct Vers_parse_info
18901891
as_row= start_end_t(null_clex_str, null_clex_str);
18911892
versioned_fields= false;
18921893
unversioned_fields= false;
1894+
can_native= -1;
18931895
}
18941896

18951897
struct start_end_t
@@ -1936,6 +1938,9 @@ struct Vers_parse_info
19361938
bool need_check(const Alter_info *alter_info) const;
19371939
bool check_conditions(const Lex_table_name &table_name,
19381940
const Lex_table_name &db) const;
1941+
bool create_sys_field(THD *thd, const char *field_name,
1942+
Alter_info *alter_info, int flags);
1943+
19391944
public:
19401945
static const Lex_ident default_start;
19411946
static const Lex_ident default_end;
@@ -1945,15 +1950,15 @@ struct Vers_parse_info
19451950
bool fix_create_like(Alter_info &alter_info, HA_CREATE_INFO &create_info,
19461951
TABLE_LIST &src_table, TABLE_LIST &table);
19471952
bool check_sys_fields(const Lex_table_name &table_name,
1948-
const Lex_table_name &db, Alter_info *alter_info,
1949-
bool can_native) const;
1953+
const Lex_table_name &db, Alter_info *alter_info) const;
19501954

19511955
/**
19521956
At least one field was specified 'WITH/WITHOUT SYSTEM VERSIONING'.
19531957
Useful for error handling.
19541958
*/
19551959
bool versioned_fields : 1;
19561960
bool unversioned_fields : 1;
1961+
int can_native;
19571962
};
19581963

19591964
/**
@@ -2059,14 +2064,15 @@ struct Table_scope_and_contents_source_st:
20592064
vers_info.init();
20602065
}
20612066

2067+
void vers_check_native();
2068+
20622069
bool vers_fix_system_fields(THD *thd, Alter_info *alter_info,
20632070
const TABLE_LIST &create_table);
20642071

20652072
bool vers_check_system_fields(THD *thd, Alter_info *alter_info,
20662073
const Lex_table_name &table_name,
20672074
const Lex_table_name &db,
20682075
int select_count= 0);
2069-
20702076
};
20712077

20722078

sql/sql_table.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9637,6 +9637,7 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
96379637
if (check_engine(thd, alter_ctx.new_db.str, alter_ctx.new_name.str, create_info))
96389638
DBUG_RETURN(true);
96399639

9640+
create_info->vers_check_native();
96409641
if (create_info->vers_info.fix_alter_info(thd, alter_info, create_info, table))
96419642
{
96429643
DBUG_RETURN(true);

storage/innobase/row/row0mysql.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ row_fts_update_or_delete(
16721672

16731673
if (new_doc_id == 0) {
16741674
ib::error() << "InnoDB FTS: Doc ID cannot be 0";
1675-
return(DB_FTS_INVALID_DOCID);
1675+
DBUG_RETURN(DB_FTS_INVALID_DOCID);
16761676
}
16771677
row_fts_do_update(trx, table, old_doc_id, new_doc_id);
16781678
}

0 commit comments

Comments
 (0)