42
42
/* on merge conflict, bump to a higher version again */
43
43
#define DUMP_VERSION "10.19"
44
44
45
+ /**
46
+ First mysql version supporting sequences.
47
+ */
48
+ #define FIRST_SEQUENCE_VERSION 100300
49
+
45
50
#include <my_global.h>
46
51
#include <my_sys.h>
47
52
#include <my_user.h>
92
97
/* Max length GTID position that we will output. */
93
98
#define MAX_GTID_LENGTH 1024
94
99
100
+ /* Dump sequence/tables control */
101
+ #define DUMP_TABLE_ALL -1
102
+ #define DUMP_TABLE_TABLE 0
103
+ #define DUMP_TABLE_SEQUENCE 1
104
+
95
105
static my_bool ignore_table_data (const uchar * hash_key , size_t len );
96
106
static void add_load_option (DYNAMIC_STRING * str , const char * option ,
97
107
const char * option_value );
@@ -3876,14 +3886,6 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
3876
3886
MYSQL_ROW row ;
3877
3887
DBUG_ENTER ("dump_table" );
3878
3888
3879
- /*
3880
- Check does table has a sequence structure and if has apply different sql queries
3881
- */
3882
- if (check_if_ignore_table (table , table_type ) & IGNORE_SEQUENCE_TABLE )
3883
- {
3884
- get_sequence_structure (table , db );
3885
- DBUG_VOID_RETURN ;
3886
- }
3887
3889
/*
3888
3890
Make sure you get the create table info before the following check for
3889
3891
--no-data flag below. Otherwise, the create table info won't be printed.
@@ -4368,18 +4370,36 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
4368
4370
} /* dump_table */
4369
4371
4370
4372
4371
- static char * getTableName (int reset )
4373
+ static char * getTableName (int reset , int want_sequences )
4372
4374
{
4373
4375
MYSQL_ROW row ;
4374
4376
4375
4377
if (!get_table_name_result )
4376
4378
{
4377
- if (!(get_table_name_result = mysql_list_tables (mysql ,NullS )))
4378
- return (NULL );
4379
+ if (mysql_get_server_version (mysql ) >= FIRST_SEQUENCE_VERSION )
4380
+ {
4381
+ const char * query = "SHOW FULL TABLES" ;
4382
+ if (mysql_query_with_error_report (mysql , 0 , query ))
4383
+ return (NULL );
4384
+
4385
+ if (!(get_table_name_result = mysql_store_result (mysql )))
4386
+ return (NULL );
4387
+ }
4388
+ else
4389
+ {
4390
+ if (!(get_table_name_result = mysql_list_tables (mysql ,NullS )))
4391
+ return (NULL );
4392
+ }
4379
4393
}
4380
4394
if ((row = mysql_fetch_row (get_table_name_result )))
4381
- return ((char * ) row [0 ]);
4395
+ {
4396
+ if (want_sequences != DUMP_TABLE_ALL )
4397
+ while (row && MY_TEST (strcmp (row [1 ], "SEQUENCE" )) == want_sequences )
4398
+ row = mysql_fetch_row (get_table_name_result );
4382
4399
4400
+ if (row )
4401
+ return ((char * ) row [0 ]);
4402
+ }
4383
4403
if (reset )
4384
4404
mysql_data_seek (get_table_name_result ,0 ); /* We want to read again */
4385
4405
else
@@ -5312,7 +5332,7 @@ static int dump_all_tables_in_db(char *database)
5312
5332
{
5313
5333
DYNAMIC_STRING query ;
5314
5334
init_dynamic_string_checked (& query , "LOCK TABLES " , 256 , 1024 );
5315
- for (numrows = 0 ; (table = getTableName (1 )) ; )
5335
+ for (numrows = 0 ; (table = getTableName (1 , DUMP_TABLE_ALL )) ; )
5316
5336
{
5317
5337
char * end = strmov (afterdot , table );
5318
5338
if (include_table ((uchar * ) hash_key ,end - hash_key ))
@@ -5346,7 +5366,19 @@ static int dump_all_tables_in_db(char *database)
5346
5366
DBUG_RETURN (1 );
5347
5367
}
5348
5368
}
5349
- while ((table = getTableName (0 )))
5369
+
5370
+ if (mysql_get_server_version (mysql ) >= FIRST_SEQUENCE_VERSION &&
5371
+ !opt_no_create_info )
5372
+ {
5373
+ // First process sequences
5374
+ while ((table = getTableName (1 , DUMP_TABLE_SEQUENCE )))
5375
+ {
5376
+ char * end = strmov (afterdot , table );
5377
+ if (include_table ((uchar * ) hash_key , end - hash_key ))
5378
+ get_sequence_structure (table , database );
5379
+ }
5380
+ }
5381
+ while ((table = getTableName (0 , DUMP_TABLE_TABLE )))
5350
5382
{
5351
5383
char * end = strmov (afterdot , table );
5352
5384
if (include_table ((uchar * ) hash_key , end - hash_key ))
@@ -5495,7 +5527,7 @@ static my_bool dump_all_views_in_db(char *database)
5495
5527
{
5496
5528
DYNAMIC_STRING query ;
5497
5529
init_dynamic_string_checked (& query , "LOCK TABLES " , 256 , 1024 );
5498
- for (numrows = 0 ; (table = getTableName (1 )); )
5530
+ for (numrows = 0 ; (table = getTableName (1 , DUMP_TABLE_TABLE )); )
5499
5531
{
5500
5532
char * end = strmov (afterdot , table );
5501
5533
if (include_table ((uchar * ) hash_key ,end - hash_key ))
@@ -5518,7 +5550,7 @@ static my_bool dump_all_views_in_db(char *database)
5518
5550
else
5519
5551
verbose_msg ("-- dump_all_views_in_db : logs flushed successfully!\n" );
5520
5552
}
5521
- while ((table = getTableName (0 )))
5553
+ while ((table = getTableName (0 , DUMP_TABLE_TABLE )))
5522
5554
{
5523
5555
char * end = strmov (afterdot , table );
5524
5556
if (include_table ((uchar * ) hash_key , end - hash_key ))
@@ -5648,7 +5680,7 @@ static int get_sys_var_lower_case_table_names()
5648
5680
5649
5681
static int dump_selected_tables (char * db , char * * table_names , int tables )
5650
5682
{
5651
- char table_buff [NAME_LEN * 2 + 3 ];
5683
+ char table_buff [NAME_LEN * 2 + 3 ], table_type [ NAME_LEN ] ;
5652
5684
DYNAMIC_STRING lock_tables_query ;
5653
5685
char * * dump_tables , * * pos , * * end ;
5654
5686
int lower_case_table_names ;
@@ -5745,9 +5777,22 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
5745
5777
DBUG_RETURN (1 );
5746
5778
}
5747
5779
}
5780
+
5781
+ if (mysql_get_server_version (mysql ) >= FIRST_SEQUENCE_VERSION )
5782
+ {
5783
+ /* Dump Sequence first */
5784
+ for (pos = dump_tables ; pos < end ; pos ++ )
5785
+ {
5786
+ DBUG_PRINT ("info" ,("Dumping sequence(?) %s" , * pos ));
5787
+ if (check_if_ignore_table (* pos , table_type ) & IGNORE_SEQUENCE_TABLE )
5788
+ get_sequence_structure (* pos , db );
5789
+ }
5790
+ }
5748
5791
/* Dump each selected table */
5749
5792
for (pos = dump_tables ; pos < end ; pos ++ )
5750
5793
{
5794
+ if (check_if_ignore_table (* pos , table_type ) & IGNORE_SEQUENCE_TABLE )
5795
+ continue ;
5751
5796
DBUG_PRINT ("info" ,("Dumping table %s" , * pos ));
5752
5797
dump_table (* pos , db , NULL , 0 );
5753
5798
if (opt_dump_triggers &&
0 commit comments