4242/* on merge conflict, bump to a higher version again */
4343#define DUMP_VERSION "10.19"
4444
45+ /**
46+ First mysql version supporting sequences.
47+ */
48+ #define FIRST_SEQUENCE_VERSION 100300
49+
4550#include <my_global.h>
4651#include <my_sys.h>
4752#include <my_user.h>
9297/* Max length GTID position that we will output. */
9398#define MAX_GTID_LENGTH 1024
9499
100+ /* Dump sequence/tables control */
101+ #define DUMP_TABLE_ALL -1
102+ #define DUMP_TABLE_TABLE 0
103+ #define DUMP_TABLE_SEQUENCE 1
104+
95105static my_bool ignore_table_data (const uchar * hash_key , size_t len );
96106static void add_load_option (DYNAMIC_STRING * str , const char * option ,
97107 const char * option_value );
@@ -3876,14 +3886,6 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
38763886 MYSQL_ROW row ;
38773887 DBUG_ENTER ("dump_table" );
38783888
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- }
38873889 /*
38883890 Make sure you get the create table info before the following check for
38893891 --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,
43684370} /* dump_table */
43694371
43704372
4371- static char * getTableName (int reset )
4373+ static char * getTableName (int reset , int want_sequences )
43724374{
43734375 MYSQL_ROW row ;
43744376
43754377 if (!get_table_name_result )
43764378 {
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+ }
43794393 }
43804394 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 );
43824399
4400+ if (row )
4401+ return ((char * ) row [0 ]);
4402+ }
43834403 if (reset )
43844404 mysql_data_seek (get_table_name_result ,0 ); /* We want to read again */
43854405 else
@@ -5312,7 +5332,7 @@ static int dump_all_tables_in_db(char *database)
53125332 {
53135333 DYNAMIC_STRING query ;
53145334 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 )) ; )
53165336 {
53175337 char * end = strmov (afterdot , table );
53185338 if (include_table ((uchar * ) hash_key ,end - hash_key ))
@@ -5346,7 +5366,19 @@ static int dump_all_tables_in_db(char *database)
53465366 DBUG_RETURN (1 );
53475367 }
53485368 }
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 )))
53505382 {
53515383 char * end = strmov (afterdot , table );
53525384 if (include_table ((uchar * ) hash_key , end - hash_key ))
@@ -5495,7 +5527,7 @@ static my_bool dump_all_views_in_db(char *database)
54955527 {
54965528 DYNAMIC_STRING query ;
54975529 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 )); )
54995531 {
55005532 char * end = strmov (afterdot , table );
55015533 if (include_table ((uchar * ) hash_key ,end - hash_key ))
@@ -5518,7 +5550,7 @@ static my_bool dump_all_views_in_db(char *database)
55185550 else
55195551 verbose_msg ("-- dump_all_views_in_db : logs flushed successfully!\n" );
55205552 }
5521- while ((table = getTableName (0 )))
5553+ while ((table = getTableName (0 , DUMP_TABLE_TABLE )))
55225554 {
55235555 char * end = strmov (afterdot , table );
55245556 if (include_table ((uchar * ) hash_key , end - hash_key ))
@@ -5648,7 +5680,7 @@ static int get_sys_var_lower_case_table_names()
56485680
56495681static int dump_selected_tables (char * db , char * * table_names , int tables )
56505682{
5651- char table_buff [NAME_LEN * 2 + 3 ];
5683+ char table_buff [NAME_LEN * 2 + 3 ], table_type [ NAME_LEN ] ;
56525684 DYNAMIC_STRING lock_tables_query ;
56535685 char * * dump_tables , * * pos , * * end ;
56545686 int lower_case_table_names ;
@@ -5745,9 +5777,22 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
57455777 DBUG_RETURN (1 );
57465778 }
57475779 }
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+ }
57485791 /* Dump each selected table */
57495792 for (pos = dump_tables ; pos < end ; pos ++ )
57505793 {
5794+ if (check_if_ignore_table (* pos , table_type ) & IGNORE_SEQUENCE_TABLE )
5795+ continue ;
57515796 DBUG_PRINT ("info" ,("Dumping table %s" , * pos ));
57525797 dump_table (* pos , db , NULL , 0 );
57535798 if (opt_dump_triggers &&
0 commit comments