Skip to content

Commit

Permalink
SQL: versioning info in INFORMATION_SCHEMA
Browse files Browse the repository at this point in the history
* show SYSTEM VERSIONED in INFORMATION_SCHEMA.TABLES
* show ROW START/ROW END columns in INFORMATION_SCHEMA.COLUMNS
  • Loading branch information
vuvova authored and midenok committed Jan 10, 2018
1 parent 6470a93 commit 26971c9
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
64 changes: 64 additions & 0 deletions mysql-test/suite/versioning/r/create.result
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,70 @@ t1 CREATE TABLE `t1` (
`Sys_end` SYS_DATATYPE GENERATED ALWAYS AS ROW END INVISIBLE COMMENT 'end',
PERIOD FOR SYSTEM_TIME (`Sys_start`, `Sys_end`)
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=latin1 WITH SYSTEM VERSIONING
select table_catalog,table_schema,table_name,table_type,version,table_rows,avg_row_length,data_free,auto_increment,check_time,table_collation,checksum,create_options,table_comment from information_schema.tables where table_name='t1';
table_catalog def
table_schema test
table_name t1
table_type SYSTEM VERSIONED
version 10
table_rows 0
avg_row_length 0
data_free 0
auto_increment NULL
check_time NULL
table_collation latin1_swedish_ci
checksum NULL
create_options
table_comment
select table_catalog,table_schema,table_name,column_name,ordinal_position,column_default,character_maximum_length,character_octet_length,character_set_name,collation_name,column_key,extra,privileges,column_comment,is_generated,generation_expression from information_schema.columns where table_name='t1';
table_catalog def
table_schema test
table_name t1
column_name x1
ordinal_position 1
column_default NULL
character_maximum_length NULL
character_octet_length NULL
character_set_name NULL
collation_name NULL
column_key
extra
privileges select,insert,update,references
column_comment
is_generated NEVER
generation_expression NULL
table_catalog def
table_schema test
table_name t1
column_name Sys_start
ordinal_position 2
column_default NULL
character_maximum_length NULL
character_octet_length NULL
character_set_name NULL
collation_name NULL
column_key
extra INVISIBLE
privileges select,insert,update,references
column_comment start
is_generated ALWAYS
generation_expression ROW START
table_catalog def
table_schema test
table_name t1
column_name Sys_end
ordinal_position 3
column_default NULL
character_maximum_length NULL
character_octet_length NULL
character_set_name NULL
collation_name NULL
column_key
extra INVISIBLE
privileges select,insert,update,references
column_comment end
is_generated ALWAYS
generation_expression ROW END
# Implicit fields test
create or replace table t1 (
x2 int unsigned
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/suite/versioning/t/create.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ eval create table t1 (
--replace_result $default_engine DEFAULT_ENGINE $sys_datatype_expl SYS_DATATYPE
show create table t1;

--query_vertical select table_catalog,table_schema,table_name,table_type,version,table_rows,avg_row_length,data_free,auto_increment,check_time,table_collation,checksum,create_options,table_comment from information_schema.tables where table_name='t1'
--query_vertical select table_catalog,table_schema,table_name,column_name,ordinal_position,column_default,character_maximum_length,character_octet_length,character_set_name,collation_name,column_key,extra,privileges,column_comment,is_generated,generation_expression from information_schema.columns where table_name='t1'

--echo # Implicit fields test
create or replace table t1 (
x2 int unsigned
Expand Down
14 changes: 13 additions & 1 deletion sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5459,7 +5459,10 @@ static int get_schema_tables_record(THD *thd, TABLE_LIST *tables,
else
{
DBUG_ASSERT(share->tmp_table == NO_TMP_TABLE);
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
if (share->versioned)
table->field[3]->store(STRING_WITH_LEN("SYSTEM VERSIONED"), cs);
else
table->field[3]->store(STRING_WITH_LEN("BASE TABLE"), cs);
}

for (int i= 4; i < 20; i++)
Expand Down Expand Up @@ -5948,6 +5951,15 @@ static int get_schema_column_record(THD *thd, TABLE_LIST *tables,
else
buf.set(STRING_WITH_LEN("VIRTUAL GENERATED"), cs);
}
else if (field->flags & VERS_SYSTEM_FIELD)
{
if (field->flags & VERS_SYS_START_FLAG)
table->field[21]->store(STRING_WITH_LEN("ROW START"), cs);
else
table->field[21]->store(STRING_WITH_LEN("ROW END"), cs);
table->field[21]->set_notnull();
table->field[20]->store(STRING_WITH_LEN("ALWAYS"), cs);
}
else
table->field[20]->store(STRING_WITH_LEN("NEVER"), cs);
/*Invisible can coexist with auto_increment and virtual */
Expand Down

0 comments on commit 26971c9

Please sign in to comment.