@@ -129,7 +129,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_no_data_m
129
129
opt_include_master_host_port = 0 ,
130
130
opt_events = 0 , opt_comments_used = 0 ,
131
131
opt_alltspcs = 0 , opt_notspcs = 0 , opt_logging ,
132
- opt_drop_trigger = 0 ;
132
+ opt_drop_trigger = 0 ;
133
133
#define OPT_SYSTEM_ALL 1
134
134
#define OPT_SYSTEM_USERS 2
135
135
#define OPT_SYSTEM_PLUGINS 4
@@ -155,7 +155,7 @@ static char *opt_password=0,*current_user=0,
155
155
* lines_terminated = 0 , * enclosed = 0 , * opt_enclosed = 0 , * escaped = 0 ,
156
156
* where = 0 , * order_by = 0 ,
157
157
* err_ptr = 0 ,
158
- * log_error_file = NULL ;
158
+ * log_error_file = NULL , * opt_asof_timestamp = NULL ;
159
159
static const char * opt_compatible_mode_str = 0 ;
160
160
static char * * defaults_argv = 0 ;
161
161
static char compatible_mode_normal_str [255 ];
@@ -278,6 +278,9 @@ static struct my_option my_long_options[] =
278
278
"Adds 'STOP SLAVE' prior to 'CHANGE MASTER' and 'START SLAVE' to bottom of dump." ,
279
279
& opt_slave_apply , & opt_slave_apply , 0 , GET_BOOL , NO_ARG ,
280
280
0 , 0 , 0 , 0 , 0 , 0 },
281
+ {"as-of" , OPT_ASOF_TIMESTAMP ,
282
+ "Dump system versioned table as of specified timestamp." ,
283
+ & opt_asof_timestamp , & opt_asof_timestamp , 0 , GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 },
281
284
{"character-sets-dir" , OPT_CHARSETS_DIR ,
282
285
"Directory for character set files." , (char * * )& charsets_dir ,
283
286
(char * * )& charsets_dir , 0 , GET_STR , REQUIRED_ARG , 0 , 0 , 0 , 0 , 0 , 0 },
@@ -1325,6 +1328,12 @@ static int get_options(int *argc, char ***argv)
1325
1328
my_progname_short );
1326
1329
return (EX_USAGE );
1327
1330
}
1331
+ if (opt_asof_timestamp && strchr (opt_asof_timestamp , '\'' ))
1332
+ {
1333
+ fprintf (stderr , "%s: Incorrect DATETIME value: '%s'\n" ,
1334
+ my_progname_short , opt_asof_timestamp );
1335
+ return (EX_USAGE );
1336
+ }
1328
1337
if (strcmp (default_charset , MYSQL_AUTODETECT_CHARSET_NAME ) &&
1329
1338
!(charset_info = get_charset_by_csname (default_charset ,
1330
1339
MY_CS_PRIMARY ,
@@ -3039,7 +3048,7 @@ static void get_sequence_structure(const char *seq, const char *db)
3039
3048
*/
3040
3049
3041
3050
static uint get_table_structure (const char * table , const char * db , char * table_type ,
3042
- char * ignore_flag )
3051
+ char * ignore_flag , my_bool * versioned )
3043
3052
{
3044
3053
my_bool init = 0 , delayed , write_data , complete_insert ;
3045
3054
my_ulonglong num_fields ;
@@ -3106,6 +3115,26 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
3106
3115
3107
3116
verbose_msg ("-- Retrieving table structure for table %s...\n" , table );
3108
3117
3118
+ if (versioned )
3119
+ {
3120
+ if (!opt_asof_timestamp )
3121
+ versioned = NULL ;
3122
+ else
3123
+ {
3124
+ my_snprintf (query_buff , sizeof (query_buff ), "select 1 from"
3125
+ " information_schema.tables where table_schema=database()"
3126
+ " and table_name=%s and table_type='SYSTEM VERSIONED'" ,
3127
+ quote_for_equal (table , table_buff ));
3128
+ if (!mysql_query_with_error_report (mysql , & result , query_buff ))
3129
+ {
3130
+ * versioned = result -> row_count > 0 ;
3131
+ mysql_free_result (result );
3132
+ }
3133
+ else
3134
+ * versioned = 0 ;
3135
+ }
3136
+ }
3137
+
3109
3138
len = my_snprintf (query_buff , sizeof (query_buff ),
3110
3139
"SET SQL_QUOTE_SHOW_CREATE=%d" ,
3111
3140
(opt_quoted || opt_keywords ));
@@ -3991,6 +4020,15 @@ static char *alloc_query_str(size_t size)
3991
4020
}
3992
4021
3993
4022
4023
+ static void vers_append_system_time (DYNAMIC_STRING * query_string )
4024
+ {
4025
+ DBUG_ASSERT (opt_asof_timestamp );
4026
+ dynstr_append_checked (query_string , " FOR SYSTEM_TIME AS OF TIMESTAMP '" );
4027
+ dynstr_append_checked (query_string , opt_asof_timestamp );
4028
+ dynstr_append_checked (query_string , "'" );
4029
+ }
4030
+
4031
+
3994
4032
/*
3995
4033
3996
4034
SYNOPSIS
@@ -4018,6 +4056,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
4018
4056
ulong rownr , row_break ;
4019
4057
uint num_fields ;
4020
4058
size_t total_length , init_length ;
4059
+ my_bool versioned = 0 ;
4021
4060
4022
4061
MYSQL_RES * res ;
4023
4062
MYSQL_FIELD * field ;
@@ -4028,7 +4067,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
4028
4067
Make sure you get the create table info before the following check for
4029
4068
--no-data flag below. Otherwise, the create table info won't be printed.
4030
4069
*/
4031
- num_fields = get_table_structure (table , db , table_type , & ignore_flag );
4070
+ num_fields = get_table_structure (table , db , table_type , & ignore_flag , & versioned );
4032
4071
4033
4072
/*
4034
4073
The "table" could be a view. If so, we don't do anything here.
@@ -4135,6 +4174,8 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
4135
4174
4136
4175
dynstr_append_checked (& query_string , " FROM " );
4137
4176
dynstr_append_checked (& query_string , result_table );
4177
+ if (versioned )
4178
+ vers_append_system_time (& query_string );
4138
4179
4139
4180
if (where )
4140
4181
{
@@ -4167,6 +4208,8 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
4167
4208
dynstr_append_checked (& query_string , select_field_names .str );
4168
4209
dynstr_append_checked (& query_string , " FROM " );
4169
4210
dynstr_append_checked (& query_string , result_table );
4211
+ if (versioned )
4212
+ vers_append_system_time (& query_string );
4170
4213
4171
4214
if (where )
4172
4215
{
@@ -5637,21 +5680,21 @@ static int dump_all_tables_in_db(char *database)
5637
5680
if (general_log_table_exists )
5638
5681
{
5639
5682
if (!get_table_structure ((char * ) "general_log" ,
5640
- database , table_type , & ignore_flag ) )
5683
+ database , table_type , & ignore_flag , NULL ) )
5641
5684
verbose_msg ("-- Warning: get_table_structure() failed with some internal "
5642
5685
"error for 'general_log' table\n" );
5643
5686
}
5644
5687
if (slow_log_table_exists )
5645
5688
{
5646
5689
if (!get_table_structure ((char * ) "slow_log" ,
5647
- database , table_type , & ignore_flag ) )
5690
+ database , table_type , & ignore_flag , NULL ) )
5648
5691
verbose_msg ("-- Warning: get_table_structure() failed with some internal "
5649
5692
"error for 'slow_log' table\n" );
5650
5693
}
5651
5694
if (transaction_registry_table_exists )
5652
5695
{
5653
5696
if (!get_table_structure ((char * ) "transaction_registry" ,
5654
- database , table_type , & ignore_flag ) )
5697
+ database , table_type , & ignore_flag , NULL ) )
5655
5698
verbose_msg ("-- Warning: get_table_structure() failed with some internal "
5656
5699
"error for 'transaction_registry' table\n" );
5657
5700
}
0 commit comments