diff --git a/client/mysqldump.c b/client/mysqldump.c index c0a3c55746e..e89e8064c9a 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -21,7 +21,7 @@ ** AUTHOR: Igor Romanenko (igor@frog.kiev.ua) ** DATE: December 3, 1994 ** WARRANTY: None, expressed, impressed, implied -** or other +** or other ** STATUS: Public domain ** Adapted and optimized for MySQL by ** Michael Widenius, Sinisa Milivojevic, Jani Tolonen @@ -77,22 +77,22 @@ #define IGNORE_INSERT_DELAYED 0x02 /* table doesn't support INSERT DELAYED */ static char *add_load_option(char *ptr, const char *object, - const char *statement); + const char *statement); static ulong find_set(TYPELIB *lib, const char *x, uint length, - char **err_pos, uint *err_len); + char **err_pos, uint *err_len); static char *alloc_query_str(ulong size); static char *field_escape(char *to,const char *from,uint length); static my_bool verbose=0,tFlag=0,dFlag=0,quick= 1, extended_insert= 1, - lock_tables=1,ignore_errors=0,flush_logs=0, - opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0, + lock_tables=1,ignore_errors=0,flush_logs=0, + opt_drop=1,opt_keywords=0,opt_lock=1,opt_compress=0, opt_delayed=0,create_options=1,opt_quoted=0,opt_databases=0, opt_alldbs=0,opt_create_db=0,opt_lock_all_tables=0, opt_set_charset=0, - opt_autocommit=0,opt_disable_keys=1,opt_xml=0, - opt_delete_master_logs=0, tty_password=0, - opt_single_transaction=0, opt_comments= 0, opt_compact= 0, - opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0, + opt_autocommit=0,opt_disable_keys=1,opt_xml=0, + opt_delete_master_logs=0, tty_password=0, + opt_single_transaction=0, opt_comments= 0, opt_compact= 0, + opt_hex_blob=0, opt_order_by_primary=0, opt_ignore=0, opt_complete_insert= 0, opt_drop_database= 0, opt_dump_triggers= 0, opt_routines=0, opt_tz_utc=1; static ulong opt_max_allowed_packet, opt_net_buffer_length; @@ -129,8 +129,8 @@ static const char *mysql_universal_client_charset= static char *default_charset; static CHARSET_INFO *charset_info= &my_charset_latin1; const char *default_dbug_option="d:t:o,/tmp/mysqldump.trace"; -/* do we met VIEWs during tables scaning */ -my_bool was_views= 0; +/* have we seen any VIEWs during table scanning? */ +my_bool seen_views= 0; const char *compatible_mode_names[]= { @@ -149,7 +149,7 @@ const char *compatible_mode_names[]= (1<<10) /* ANSI */\ ) TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1, - "", compatible_mode_names, NULL}; + "", compatible_mode_names, NULL}; HASH ignore_table; @@ -276,7 +276,7 @@ static struct my_option my_long_options[] = {"lines-terminated-by", OPT_LTB, "Lines in the i.file are terminated by ...", (gptr*) &lines_terminated, (gptr*) &lines_terminated, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"lock-all-tables", 'x', "Locks all tables across all databases. This " + {"lock-all-tables", 'x', "Locks all tables across all databases. This " "is achieved by taking a global read lock for the duration of the whole " "dump. Automatically turns --single-transaction and --lock-tables off.", (gptr*) &opt_lock_all_tables, (gptr*) &opt_lock_all_tables, 0, GET_BOOL, NO_ARG, @@ -297,7 +297,7 @@ static struct my_option my_long_options[] = GET_UINT, OPT_ARG, 0, 0, MYSQL_OPT_MASTER_DATA_COMMENTED_SQL, 0, 0, 0}, {"max_allowed_packet", OPT_MAX_ALLOWED_PACKET, "", (gptr*) &opt_max_allowed_packet, (gptr*) &opt_max_allowed_packet, 0, - GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096, + GET_ULONG, REQUIRED_ARG, 24*1024*1024, 4096, (longlong) 2L*1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, {"net_buffer_length", OPT_NET_BUFFER_LENGTH, "", (gptr*) &opt_net_buffer_length, (gptr*) &opt_net_buffer_length, 0, @@ -411,8 +411,8 @@ static const char *load_default_groups[]= { "mysqldump","client",0 }; static void safe_exit(int error); static void write_header(FILE *sql_file, char *db_name); static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, - const char *prefix,const char *name, - int string_value); + const char *prefix,const char *name, + int string_value); static int dump_selected_tables(char *db, char **table_names, int tables); static int dump_all_tables_in_db(char *db); static int init_dumping(char *); @@ -428,10 +428,10 @@ static my_bool dump_all_views_in_db(char *database); /* exit with message if ferror(file) - + SYNOPSIS check_io() - file - checked file + file - checked file */ void check_io(FILE *file) @@ -456,7 +456,7 @@ static void short_usage_sub(void) { printf("Usage: %s [OPTIONS] database [tables]\n", my_progname); printf("OR %s [OPTIONS] --databases [OPTIONS] DB1 [DB2 DB3...]\n", - my_progname); + my_progname); printf("OR %s [OPTIONS] --all-databases [OPTIONS]\n", my_progname); NETWARE_SET_SCREEN_MODE(1); } @@ -501,12 +501,12 @@ static void write_header(FILE *sql_file, char *db_name) { fprintf(sql_file, "-- MySQL dump %s\n--\n", DUMP_VERSION); fprintf(sql_file, "-- Host: %s Database: %s\n", - current_host ? current_host : "localhost", db_name ? db_name : - ""); + current_host ? current_host : "localhost", db_name ? db_name : + ""); fputs("-- ------------------------------------------------------\n", - sql_file); + sql_file); fprintf(sql_file, "-- Server version\t%s\n", - mysql_get_server_info(&mysql_connection)); + mysql_get_server_info(&mysql_connection)); } if (opt_set_charset) fprintf(sql_file, @@ -529,10 +529,10 @@ static void write_header(FILE *sql_file, char *db_name) "); } fprintf(sql_file, - "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='%s%s%s' */;\n" - "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n", - path?"":"NO_AUTO_VALUE_ON_ZERO",compatible_mode_normal_str[0]==0?"":",", - compatible_mode_normal_str); + "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='%s%s%s' */;\n" + "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n", + path?"":"NO_AUTO_VALUE_ON_ZERO",compatible_mode_normal_str[0]==0?"":",", + compatible_mode_normal_str); check_io(sql_file); } } /* write_header */ @@ -563,7 +563,7 @@ static void write_footer(FILE *sql_file) "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n" "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n"); fprintf(sql_file, - "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n"); + "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n"); fputs("\n", sql_file); check_io(sql_file); } @@ -577,7 +577,7 @@ static void free_table_ent(char *key) byte* get_table_key(const char *entry, uint *length, - my_bool not_used __attribute__((unused))) + my_bool not_used __attribute__((unused))) { *length= strlen(entry); return (byte*) entry; @@ -594,7 +594,7 @@ void init_table_rule_hash(HASH* h) static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), - char *argument) + char *argument) { switch (optid) { #ifdef __NETWARE__ @@ -608,9 +608,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *start=argument; my_free(opt_password,MYF(MY_ALLOW_ZERO_PTR)); opt_password=my_strdup(argument,MYF(MY_FAE)); - while (*argument) *argument++= 'x'; /* Destroy argument */ + while (*argument) *argument++= 'x'; /* Destroy argument */ if (*start) - start[1]=0; /* Cut length of argument */ + start[1]=0; /* Cut length of argument */ tty_password= 0; } else @@ -618,7 +618,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), break; case 'r': if (!(md_result_file = my_fopen(argument, O_WRONLY | FILE_BINARY, - MYF(MY_WME)))) + MYF(MY_WME)))) exit(1); break; case 'W': @@ -639,7 +639,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'V': print_version(); exit(0); case 'X': opt_xml = 1; - extended_insert= opt_drop= opt_lock= + extended_insert= opt_drop= opt_lock= opt_disable_keys= opt_autocommit= opt_create_db= 0; break; case 'I': @@ -692,36 +692,36 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt_set_charset= 0; opt_compatible_mode_str= argument; opt_compatible_mode= find_set(&compatible_mode_typelib, - argument, strlen(argument), - &err_ptr, &err_len); + argument, strlen(argument), + &err_ptr, &err_len); if (err_len) { - strmake(buff, err_ptr, min(sizeof(buff), err_len)); - fprintf(stderr, "Invalid mode to --compatible: %s\n", buff); - exit(1); + strmake(buff, err_ptr, min(sizeof(buff), err_len)); + fprintf(stderr, "Invalid mode to --compatible: %s\n", buff); + exit(1); } #if !defined(DBUG_OFF) { - uint size_for_sql_mode= 0; - const char **ptr; - for (ptr= compatible_mode_names; *ptr; ptr++) - size_for_sql_mode+= strlen(*ptr); - size_for_sql_mode+= sizeof(compatible_mode_names)-1; - DBUG_ASSERT(sizeof(compatible_mode_normal_str)>=size_for_sql_mode); + uint size_for_sql_mode= 0; + const char **ptr; + for (ptr= compatible_mode_names; *ptr; ptr++) + size_for_sql_mode+= strlen(*ptr); + size_for_sql_mode+= sizeof(compatible_mode_names)-1; + DBUG_ASSERT(sizeof(compatible_mode_normal_str)>=size_for_sql_mode); } #endif mode= opt_compatible_mode; for (i= 0, mode= opt_compatible_mode; mode; mode>>= 1, i++) { - if (mode & 1) - { - end= strmov(end, compatible_mode_names[i]); - end= strmov(end, ","); - } + if (mode & 1) + { + end= strmov(end, compatible_mode_names[i]); + end= strmov(end, ","); + } } if (end!=compatible_mode_normal_str) - end[-1]= 0; - /* + end[-1]= 0; + /* Set charset to the default compiled value if it hasn't been reset yet by --default-character-set=xxx. */ @@ -733,8 +733,8 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), { if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0) { - fprintf(stderr, "Unknown option to protocol: %s\n", argument); - exit(1); + fprintf(stderr, "Unknown option to protocol: %s\n", argument); + exit(1); } break; } @@ -760,12 +760,12 @@ static int get_options(int *argc, char ***argv) *mysql_params->p_net_buffer_length= opt_net_buffer_length; if (opt_delayed) - opt_lock=0; /* Can't have lock with delayed */ + opt_lock=0; /* Can't have lock with delayed */ if (!path && (enclosed || opt_enclosed || escaped || lines_terminated || - fields_terminated)) + fields_terminated)) { fprintf(stderr, - "%s: You must use option --tab with --fields-...\n", my_progname); + "%s: You must use option --tab with --fields-...\n", my_progname); return(1); } @@ -777,7 +777,7 @@ static int get_options(int *argc, char ***argv) fprintf(stderr, "%s: You can't use --single-transaction and " "--lock-all-tables at the same time.\n", my_progname); return(1); - } + } if (opt_master_data) opt_lock_all_tables= !opt_single_transaction; if (opt_single_transaction || opt_lock_all_tables) @@ -790,13 +790,13 @@ static int get_options(int *argc, char ***argv) if ((opt_databases || opt_alldbs) && path) { fprintf(stderr, - "%s: --databases or --all-databases can't be used with --tab.\n", - my_progname); + "%s: --databases or --all-databases can't be used with --tab.\n", + my_progname); return(1); } if (strcmp(default_charset, charset_info->csname) && - !(charset_info= get_charset_by_csname(default_charset, - MY_CS_PRIMARY, MYF(MY_WME)))) + !(charset_info= get_charset_by_csname(default_charset, + MY_CS_PRIMARY, MYF(MY_WME)))) exit(1); if ((*argc < 1 && !opt_alldbs) || (*argc > 0 && opt_alldbs)) { @@ -816,7 +816,7 @@ static void DB_error(MYSQL *mysql, const char *when) { DBUG_ENTER("DB_error"); my_printf_error(0,"Got error: %d: %s %s", MYF(0), - mysql_errno(mysql), mysql_error(mysql), when); + mysql_errno(mysql), mysql_error(mysql), when); safe_exit(EX_MYSQLERR); DBUG_VOID_RETURN; } /* DB_error */ @@ -830,14 +830,14 @@ static void DB_error(MYSQL *mysql, const char *when) mysql_query_with_error_report() mysql_con connection to use res if non zero, result will be put there with - mysql_store_result() + mysql_store_result() query query to send to server RETURN VALUES 0 query sending and (if res!=0) result reading went ok 1 error */ - + static int mysql_query_with_error_report(MYSQL *mysql_con, MYSQL_RES **res, const char *query) { @@ -869,7 +869,7 @@ static FILE* open_sql_file_for_table(const char* table) char filename[FN_REFLEN], tmp_path[FN_REFLEN]; convert_dirname(tmp_path,path,NullS); res= my_fopen(fn_format(filename, table, tmp_path, ".sql", 4), - O_WRONLY, MYF(MY_WME)); + O_WRONLY, MYF(MY_WME)); return res; } @@ -904,7 +904,7 @@ static int dbConnect(char *host, char *user,char *passwd) #ifdef HAVE_OPENSSL if (opt_use_ssl) mysql_ssl_set(&mysql_connection, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, - opt_ssl_capath, opt_ssl_cipher); + opt_ssl_capath, opt_ssl_cipher); mysql_options(&mysql_connection,MYSQL_OPT_SSL_VERIFY_SERVER_CERT, (char*)&opt_ssl_verify_server_cert); #endif @@ -933,7 +933,7 @@ static int dbConnect(char *host, char *user,char *passwd) */ sock->reconnect= 0; my_snprintf(buff, sizeof(buff), "/*!40100 SET @@SQL_MODE='%s' */", - compatible_mode_normal_str); + compatible_mode_normal_str); if (mysql_query_with_error_report(sock, 0, buff)) { mysql_close(sock); @@ -941,7 +941,7 @@ static int dbConnect(char *host, char *user,char *passwd) return 1; } /* - set time_zone to UTC to allow dumping date types between servers with + set time_zone to UTC to allow dumping date types between servers with different time zone settings */ if (opt_tz_utc) @@ -975,8 +975,8 @@ static void unescape(FILE *file,char *pos,uint length) DBUG_ENTER("unescape"); if (!(tmp=(char*) my_malloc(length*2+1, MYF(MY_WME)))) { - ignore_errors=0; /* Fatal error */ - safe_exit(EX_MYSQLERR); /* Force exit */ + ignore_errors=0; /* Fatal error */ + safe_exit(EX_MYSQLERR); /* Force exit */ } mysql_real_escape_string(&mysql_connection, tmp, pos, length); fputc('\'', file); @@ -1003,13 +1003,13 @@ static my_bool test_if_special_chars(const char *str) /* quote_name(name, buff, force) - Quotes char string, taking into account compatible mode + Quotes char string, taking into account compatible mode Args name Unquoted string containing that which will be quoted buff The buffer that contains the quoted value, also returned - force Flag to make it ignore 'test_if_special_chars' + force Flag to make it ignore 'test_if_special_chars' Returns @@ -1082,13 +1082,13 @@ static char *quote_for_like(const char *name, char *buff) /* Quote and print a string. - + SYNOPSIS print_quoted_xml() - output - output file - str - string to print - len - its length - + output - output file + str - string to print + len - its length + DESCRIPTION Quote '<' '>' '&' '\"' chars and print a string to the xml_file. */ @@ -1096,7 +1096,7 @@ static char *quote_for_like(const char *name, char *buff) static void print_quoted_xml(FILE *xml_file, const char *str, ulong len) { const char *end; - + for (end= str + len; str != end; str++) { switch (*str) { @@ -1123,15 +1123,15 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len) /* Print xml tag with one attribute. - + SYNOPSIS print_xml_tag1() - xml_file - output file - sbeg - line beginning - stag_atr - tag and attribute - sval - value of attribute - send - line ending - + xml_file - output file + sbeg - line beginning + stag_atr - tag and attribute + sval - value of attribute + send - line ending + DESCRIPTION Print tag with one attribute to the xml_file. Format is: sbegsend @@ -1141,8 +1141,8 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len) */ static void print_xml_tag1(FILE * xml_file, const char* sbeg, - const char* stag_atr, const char* sval, - const char* send) + const char* stag_atr, const char* sval, + const char* send) { fputs(sbeg, xml_file); fputs("<", xml_file); @@ -1160,11 +1160,11 @@ static void print_xml_tag1(FILE * xml_file, const char* sbeg, SYNOPSIS print_xml_null_tag() - xml_file - output file - sbeg - line beginning - stag_atr - tag and attribute - sval - value of attribute - send - line ending + xml_file - output file + sbeg - line beginning + stag_atr - tag and attribute + sval - value of attribute + send - line ending DESCRIPTION Print tag with one attribute to the xml_file. Format is: @@ -1194,11 +1194,11 @@ static void print_xml_null_tag(FILE * xml_file, const char* sbeg, SYNOPSIS print_xml_row() - xml_file - output file - row_name - xml tag name - tableRes - query result - row - result row - + xml_file - output file + row_name - xml tag name + tableRes - query result + row - result row + DESCRIPTION Print tag with many attribute to the xml_file. Format is: \t\t @@ -1207,7 +1207,7 @@ static void print_xml_null_tag(FILE * xml_file, const char* sbeg, */ static void print_xml_row(FILE *xml_file, const char *row_name, - MYSQL_RES *tableRes, MYSQL_ROW *row) + MYSQL_RES *tableRes, MYSQL_ROW *row) { uint i; MYSQL_FIELD *field; @@ -1324,7 +1324,7 @@ static uint dump_routines_for_db(char *db) */ definer_begin= strstr(row[2], " DEFINER"); - + if (definer_begin) { char *definer_end= strstr(definer_begin, " PROCEDURE"); @@ -1388,7 +1388,7 @@ static uint dump_routines_for_db(char *db) ARGS table - table name db - db name - table_type - table type ie "InnoDB" + table_type - table type, e.g. "MyISAM" or "InnoDB", but also "VIEW" ignore_flag - what we must particularly ignore - see IGNORE_ defines above RETURN @@ -1400,10 +1400,10 @@ static uint get_table_structure(char *table, char *db, char *table_type, { my_bool init=0, delayed, write_data, complete_insert; my_ulonglong num_fields; - char *result_table, *opt_quoted_table; + char *result_table, *opt_quoted_table; const char *insert_option; - char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3]; - char table_buff2[NAME_LEN*2+3], query_buff[512]; + char name_buff[NAME_LEN+3],table_buff[NAME_LEN*2+3]; + char table_buff2[NAME_LEN*2+3], query_buff[512]; FILE *sql_file = md_result_file; int len; MYSQL_RES *result; @@ -1473,21 +1473,30 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (!(sql_file= open_sql_file_for_table(table))) { - safe_exit(EX_MYSQLERR); - DBUG_RETURN(0); + safe_exit(EX_MYSQLERR); + DBUG_RETURN(0); } write_header(sql_file, db); } if (!opt_xml && opt_comments) { + if (strcmp (table_type, "VIEW") == 0) /* view */ + fprintf(sql_file, "\n--\n-- Temporary table structure for view %s\n--\n\n", + result_table); + else fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", - result_table); - check_io(sql_file); + result_table); + check_io(sql_file); } if (opt_drop) { - fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", opt_quoted_table); - check_io(sql_file); + /* + Even if the "table" is a view, we do a DROP TABLE here. The + view-specific code below fills in the DROP VIEW. + */ + fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", + opt_quoted_table); + check_io(sql_file); } result= mysql_store_result(sock); @@ -1500,7 +1509,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, mysql_free_result(result); /* - Create a table with the same name as the view and with columns of + Create a table with the same name as the view and with columns of the same name in order to satisfy views that depend on this view. The table will be removed when the actual view is created. @@ -1524,10 +1533,13 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (opt_drop) { + /* + We have already dropped any table of the same name + above, so here we just drop the view. + */ + fprintf(sql_file, "/*!50001 DROP VIEW IF EXISTS %s*/;\n", opt_quoted_table); - fprintf(sql_file, "/*!50001 DROP TABLE IF EXISTS %s*/;\n", - opt_quoted_table); check_io(sql_file); } @@ -1554,7 +1566,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, } mysql_free_result(result); - was_views= 1; + seen_views= 1; DBUG_RETURN(0); } @@ -1564,11 +1576,11 @@ static uint get_table_structure(char *table, char *db, char *table_type, mysql_free_result(result); } my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", - result_table); + result_table); if (mysql_query_with_error_report(sock, &result, query_buff)) { if (path) - my_fclose(sql_file, MYF(MY_WME)); + my_fclose(sql_file, MYF(MY_WME)); safe_exit(EX_MYSQLERR); DBUG_RETURN(0); } @@ -1621,7 +1633,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, my_progname, mysql_error(sock)); my_snprintf(query_buff, sizeof(query_buff), "show fields from %s", - result_table); + result_table); if (mysql_query_with_error_report(sock, &result, query_buff)) { safe_exit(EX_MYSQLERR); @@ -1635,18 +1647,18 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (!(sql_file= open_sql_file_for_table(table))) { - safe_exit(EX_MYSQLERR); - DBUG_RETURN(0); + safe_exit(EX_MYSQLERR); + DBUG_RETURN(0); } write_header(sql_file, db); } if (!opt_xml && opt_comments) - fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", - result_table); + fprintf(sql_file, "\n--\n-- Table structure for table %s\n--\n\n", + result_table); if (opt_drop) fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n", result_table); if (!opt_xml) - fprintf(sql_file, "CREATE TABLE %s (\n", result_table); + fprintf(sql_file, "CREATE TABLE %s (\n", result_table); else print_xml_tag1(sql_file, "\t", "table_structure name=", table, "\n"); check_io(sql_file); @@ -1674,10 +1686,10 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (init) { if (!opt_xml && !tFlag) - { - fputs(",\n",sql_file); - check_io(sql_file); - } + { + fputs(",\n",sql_file); + check_io(sql_file); + } if (complete_insert) dynstr_append_mem(&insert_pat, ", ", 2); } @@ -1687,30 +1699,30 @@ static uint get_table_structure(char *table, char *db, char *table_type, quote_name(row[SHOW_FIELDNAME], name_buff, 0)); if (!tFlag) { - if (opt_xml) - { - print_xml_row(sql_file, "field", result, &row); - continue; - } + if (opt_xml) + { + print_xml_row(sql_file, "field", result, &row); + continue; + } if (opt_keywords) - fprintf(sql_file, " %s.%s %s", result_table, - quote_name(row[SHOW_FIELDNAME],name_buff, 0), - row[SHOW_TYPE]); + fprintf(sql_file, " %s.%s %s", result_table, + quote_name(row[SHOW_FIELDNAME],name_buff, 0), + row[SHOW_TYPE]); else - fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME], - name_buff, 0), - row[SHOW_TYPE]); + fprintf(sql_file, " %s %s", quote_name(row[SHOW_FIELDNAME], + name_buff, 0), + row[SHOW_TYPE]); if (row[SHOW_DEFAULT]) { - fputs(" DEFAULT ", sql_file); - unescape(sql_file, row[SHOW_DEFAULT], lengths[SHOW_DEFAULT]); + fputs(" DEFAULT ", sql_file); + unescape(sql_file, row[SHOW_DEFAULT], lengths[SHOW_DEFAULT]); } if (!row[SHOW_NULL][0]) - fputs(" NOT NULL", sql_file); + fputs(" NOT NULL", sql_file); if (row[SHOW_EXTRA][0]) - fprintf(sql_file, " %s",row[SHOW_EXTRA]); - check_io(sql_file); + fprintf(sql_file, " %s",row[SHOW_EXTRA]); + check_io(sql_file); } } num_fields= mysql_num_rows(result); @@ -1730,9 +1742,9 @@ static uint get_table_structure(char *table, char *db, char *table_type, goto continue_xml; } fprintf(stderr, "%s: Can't get keys for table %s (%s)\n", - my_progname, result_table, mysql_error(sock)); + my_progname, result_table, mysql_error(sock)); if (path) - my_fclose(sql_file, MYF(MY_WME)); + my_fclose(sql_file, MYF(MY_WME)); safe_exit(EX_MYSQLERR); DBUG_RETURN(0); } @@ -1744,102 +1756,102 @@ static uint get_table_structure(char *table, char *db, char *table_type, { if (atoi(row[3]) == 1) { - keynr++; + keynr++; #ifdef FORCE_PRIMARY_KEY - if (atoi(row[1]) == 0 && primary_key == INT_MAX) - primary_key=keynr; + if (atoi(row[1]) == 0 && primary_key == INT_MAX) + primary_key=keynr; #endif - if (!strcmp(row[2],"PRIMARY")) - { - primary_key=keynr; - break; - } + if (!strcmp(row[2],"PRIMARY")) + { + primary_key=keynr; + break; + } } } mysql_data_seek(result,0); keynr=0; while ((row= mysql_fetch_row(result))) { - if (opt_xml) - { - print_xml_row(sql_file, "key", result, &row); - continue; - } + if (opt_xml) + { + print_xml_row(sql_file, "key", result, &row); + continue; + } if (atoi(row[3]) == 1) { - if (keynr++) - putc(')', sql_file); - if (atoi(row[1])) /* Test if duplicate key */ - /* Duplicate allowed */ - fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff,0)); - else if (keynr == primary_key) - fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */ - else - fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff, - 0)); + if (keynr++) + putc(')', sql_file); + if (atoi(row[1])) /* Test if duplicate key */ + /* Duplicate allowed */ + fprintf(sql_file, ",\n KEY %s (",quote_name(row[2],name_buff,0)); + else if (keynr == primary_key) + fputs(",\n PRIMARY KEY (",sql_file); /* First UNIQUE is primary */ + else + fprintf(sql_file, ",\n UNIQUE %s (",quote_name(row[2],name_buff, + 0)); } else - putc(',', sql_file); + putc(',', sql_file); fputs(quote_name(row[4], name_buff, 0), sql_file); if (row[7]) - fprintf(sql_file, " (%s)",row[7]); /* Sub key */ - check_io(sql_file); + fprintf(sql_file, " (%s)",row[7]); /* Sub key */ + check_io(sql_file); } if (!opt_xml) { - if (keynr) - putc(')', sql_file); - fputs("\n)",sql_file); - check_io(sql_file); + if (keynr) + putc(')', sql_file); + fputs("\n)",sql_file); + check_io(sql_file); } /* Get MySQL specific create options */ if (create_options) { - char show_name_buff[NAME_LEN*2+2+24]; + char show_name_buff[NAME_LEN*2+2+24]; - /* Check memory for quote_for_like() */ + /* Check memory for quote_for_like() */ my_snprintf(buff, sizeof(buff), "show table status like %s", - quote_for_like(table, show_name_buff)); + quote_for_like(table, show_name_buff)); if (mysql_query_with_error_report(sock, &result, buff)) { - if (mysql_errno(sock) != ER_PARSE_ERROR) - { /* If old MySQL version */ - if (verbose) - fprintf(stderr, - "-- Warning: Couldn't get status information for table %s (%s)\n", - result_table,mysql_error(sock)); - } + if (mysql_errno(sock) != ER_PARSE_ERROR) + { /* If old MySQL version */ + if (verbose) + fprintf(stderr, + "-- Warning: Couldn't get status information for table %s (%s)\n", + result_table,mysql_error(sock)); + } } else if (!(row= mysql_fetch_row(result))) { - fprintf(stderr, - "Error: Couldn't read status information for table %s (%s)\n", - result_table,mysql_error(sock)); + fprintf(stderr, + "Error: Couldn't read status information for table %s (%s)\n", + result_table,mysql_error(sock)); } else { - if (opt_xml) - print_xml_row(sql_file, "options", result, &row); - else - { - fputs("/*!",sql_file); - print_value(sql_file,result,row,"engine=","Engine",0); - print_value(sql_file,result,row,"","Create_options",0); - print_value(sql_file,result,row,"comment=","Comment",1); - fputs(" */",sql_file); - check_io(sql_file); - } + if (opt_xml) + print_xml_row(sql_file, "options", result, &row); + else + { + fputs("/*!",sql_file); + print_value(sql_file,result,row,"engine=","Engine",0); + print_value(sql_file,result,row,"","Create_options",0); + print_value(sql_file,result,row,"comment=","Comment",1); + fputs(" */",sql_file); + check_io(sql_file); + } } - mysql_free_result(result); /* Is always safe to free */ + mysql_free_result(result); /* Is always safe to free */ } continue_xml: if (!opt_xml) - fputs(";\n", sql_file); + fputs(";\n", sql_file); else - fputs("\t\n", sql_file); + fputs("\t\n", sql_file); check_io(sql_file); } } @@ -1871,8 +1883,8 @@ continue_xml: static void dump_triggers_for_table (char *table, char *db) { - char *result_table; - char name_buff[NAME_LEN*4+3], table_buff[NAME_LEN*2+3]; + char *result_table; + char name_buff[NAME_LEN*4+3], table_buff[NAME_LEN*2+3]; char query_buff[512]; uint old_opt_compatible_mode=opt_compatible_mode; FILE *sql_file = md_result_file; @@ -1921,7 +1933,7 @@ DELIMITER ;;\n"); uint host_name_len; char host_name_str[HOSTNAME_LENGTH + 1]; char quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3]; - + parse_user(row[7], strlen(row[7]), user_name_str, &user_name_len, host_name_str, &host_name_len); @@ -1937,7 +1949,7 @@ DELIMITER ;;\n"); row[4], /* Timing */ row[1], /* Event */ result_table, - (strchr(" \t\n\r", *(row[3]))) ? "" : " ", + (strchr(" \t\n\r", *(row[3]))) ? "" : " ", row[3] /* Statement */); } if (mysql_num_rows(result)) @@ -1946,7 +1958,7 @@ DELIMITER ;;\n"); "/*!50003 SET SESSION SQL_MODE=@OLD_SQL_MODE */;\n"); mysql_free_result(result); /* - make sure to set back opt_compatible mode to + make sure to set back opt_compatible mode to original value */ opt_compatible_mode=old_opt_compatible_mode; @@ -1954,7 +1966,7 @@ DELIMITER ;;\n"); } static char *add_load_option(char *ptr,const char *object, - const char *statement) + const char *statement) { if (object) { @@ -1993,7 +2005,7 @@ static char *field_escape(char *to,const char *from,uint length) else { if (*from == '\'' && !end_backslashes) - *to++= *from; /* We want a duplicate of "'" for MySQL */ + *to++= *from; /* We want a duplicate of "'" for MySQL */ end_backslashes=0; } } @@ -2010,8 +2022,8 @@ static char *alloc_query_str(ulong size) if (!(query= (char*) my_malloc(size, MYF(MY_WME)))) { - ignore_errors= 0; /* Fatal error */ - safe_exit(EX_MYSQLERR); /* Force exit */ + ignore_errors= 0; /* Fatal error */ + safe_exit(EX_MYSQLERR); /* Force exit */ } return query; } @@ -2040,11 +2052,11 @@ static void dump_table(char *table, char *db) char *result_table, table_buff2[NAME_LEN*2+3], *opt_quoted_table; char *query= query_buf; int error= 0; - ulong rownr, row_break, total_length, init_length; + ulong rownr, row_break, total_length, init_length; uint num_fields; - MYSQL_RES *res; - MYSQL_FIELD *field; - MYSQL_ROW row; + MYSQL_RES *res; + MYSQL_FIELD *field; + MYSQL_ROW row; DBUG_ENTER("dump_table"); /* @@ -2053,13 +2065,19 @@ static void dump_table(char *table, char *db) */ num_fields= get_table_structure(table, db, table_type, &ignore_flag); + /* + The "table" could be a view. If so, we don't do anything here. + */ + if (strcmp (table_type, "VIEW") == 0) + return; + /* Check --no-data flag */ if (dFlag) { if (verbose) fprintf(stderr, "-- Skipping dump data for table '%s', --no-data was used\n", - table); + table); DBUG_VOID_RETURN; } @@ -2074,8 +2092,8 @@ static void dump_table(char *table, char *db) { if (verbose) fprintf(stderr, - "-- Warning: Skipping data for table '%s' because it's of type %s\n", - table, table_type); + "-- Warning: Skipping data for table '%s' because it's of type %s\n", + table, table_type); DBUG_VOID_RETURN; } /* Check that there are any fields in the table */ @@ -2083,8 +2101,8 @@ static void dump_table(char *table, char *db) { if (verbose) fprintf(stderr, - "-- Skipping dump data for table '%s', it has no fields\n", - table); + "-- Skipping dump data for table '%s', it has no fields\n", + table); DBUG_VOID_RETURN; } @@ -2100,11 +2118,11 @@ static void dump_table(char *table, char *db) my_load_path(tmp_path, tmp_path, NULL); fn_format(filename, table, tmp_path, ".txt", 4); my_delete(filename, MYF(0)); /* 'INTO OUTFILE' doesn't work, if - filename wasn't deleted */ + filename wasn't deleted */ to_unix_path(filename); - my_snprintf(query, QUERY_LENGTH, - "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '%s'", - filename); + my_snprintf(query, QUERY_LENGTH, + "SELECT /*!40001 SQL_NO_CACHE */ * INTO OUTFILE '%s'", + filename); end= strend(query); if (fields_terminated || enclosed || opt_enclosed || escaped) @@ -2141,12 +2159,12 @@ static void dump_table(char *table, char *db) if (!opt_xml && opt_comments) { fprintf(md_result_file,"\n--\n-- Dumping data for table %s\n--\n", - result_table); + result_table); check_io(md_result_file); } my_snprintf(query, QUERY_LENGTH, - "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s", - result_table); + "SELECT /*!40001 SQL_NO_CACHE */ * FROM %s", + result_table); if (where || order_by) { query = alloc_query_str((ulong) (strlen(query) + 1 + @@ -2194,7 +2212,7 @@ static void dump_table(char *table, char *db) if (mysql_num_fields(res) != num_fields) { fprintf(stderr,"%s: Error in field count for table: %s ! Aborting.\n", - my_progname, result_table); + my_progname, result_table); error= EX_CONSCHECK; goto err; } @@ -2202,7 +2220,7 @@ static void dump_table(char *table, char *db) if (opt_disable_keys) { fprintf(md_result_file, "\n/*!40000 ALTER TABLE %s DISABLE KEYS */;\n", - opt_quoted_table); + opt_quoted_table); check_io(md_result_file); } if (opt_lock) @@ -2211,7 +2229,7 @@ static void dump_table(char *table, char *db) check_io(md_result_file); } - total_length= opt_net_buffer_length; /* Force row break */ + total_length= opt_net_buffer_length; /* Force row break */ row_break=0; rownr=0; init_length=(uint) insert_pat.length+4; @@ -2231,15 +2249,15 @@ static void dump_table(char *table, char *db) rownr++; if (!extended_insert && !opt_xml) { - fputs(insert_pat.str,md_result_file); - check_io(md_result_file); + fputs(insert_pat.str,md_result_file); + check_io(md_result_file); } mysql_field_seek(res,0); if (opt_xml) { fputs("\t\n", md_result_file); - check_io(md_result_file); + check_io(md_result_file); } for (i = 0; i < mysql_num_fields(res); i++) @@ -2247,21 +2265,21 @@ static void dump_table(char *table, char *db) int is_blob; ulong length= lengths[i]; - if (!(field = mysql_fetch_field(res))) - { - my_snprintf(query, QUERY_LENGTH, - "%s: Not enough fields from table %s! Aborting.\n", - my_progname, result_table); - fputs(query,stderr); - error= EX_CONSCHECK; - goto err; - } + if (!(field = mysql_fetch_field(res))) + { + my_snprintf(query, QUERY_LENGTH, + "%s: Not enough fields from table %s! Aborting.\n", + my_progname, result_table); + fputs(query,stderr); + error= EX_CONSCHECK; + goto err; + } - /* - 63 is my_charset_bin. If charsetnr is not 63, - we have not a BLOB but a TEXT column. - we'll dump in hex only BLOB columns. - */ + /* + 63 is my_charset_bin. If charsetnr is not 63, + we have not a BLOB but a TEXT column. + we'll dump in hex only BLOB columns. + */ is_blob= (opt_hex_blob && field->charsetnr == 63 && (field->type == MYSQL_TYPE_BIT || field->type == MYSQL_TYPE_STRING || @@ -2271,36 +2289,36 @@ static void dump_table(char *table, char *db) field->type == MYSQL_TYPE_LONG_BLOB || field->type == MYSQL_TYPE_MEDIUM_BLOB || field->type == MYSQL_TYPE_TINY_BLOB)) ? 1 : 0; - if (extended_insert) - { - if (i == 0) - dynstr_set(&extended_row,"("); - else - dynstr_append(&extended_row,","); + if (extended_insert) + { + if (i == 0) + dynstr_set(&extended_row,"("); + else + dynstr_append(&extended_row,","); - if (row[i]) - { - if (length) - { - if (!IS_NUM_FIELD(field)) - { - /* - "length * 2 + 2" is OK for both HEX and non-HEX modes: - - In HEX mode we need exactly 2 bytes per character - plus 2 bytes for '0x' prefix. - - In non-HEX mode we need up to 2 bytes per character, - plus 2 bytes for leading and trailing '\'' characters. - */ - if (dynstr_realloc(&extended_row,length * 2+2)) - { - fputs("Aborting dump (out of memory)",stderr); - error= EX_EOM; - goto err; - } + if (row[i]) + { + if (length) + { + if (!IS_NUM_FIELD(field)) + { + /* + "length * 2 + 2" is OK for both HEX and non-HEX modes: + - In HEX mode we need exactly 2 bytes per character + plus 2 bytes for '0x' prefix. + - In non-HEX mode we need up to 2 bytes per character, + plus 2 bytes for leading and trailing '\'' characters. + */ + if (dynstr_realloc(&extended_row,length * 2+2)) + { + fputs("Aborting dump (out of memory)",stderr); + error= EX_EOM; + goto err; + } if (opt_hex_blob && is_blob) { dynstr_append(&extended_row, "0x"); - extended_row.length+= mysql_hex_string(extended_row.str + + extended_row.length+= mysql_hex_string(extended_row.str + extended_row.length, row[i], length); extended_row.str[extended_row.length]= '\0'; @@ -2315,94 +2333,94 @@ static void dump_table(char *table, char *db) extended_row.str[extended_row.length]='\0'; dynstr_append(&extended_row,"'"); } - } - else - { - /* change any strings ("inf", "-inf", "nan") into NULL */ - char *ptr = row[i]; - if (my_isalpha(charset_info, *ptr) || (*ptr == '-' && - my_isalpha(charset_info, ptr[1]))) - dynstr_append(&extended_row, "NULL"); - else - { - if (field->type == FIELD_TYPE_DECIMAL) - { - /* add " signs around */ - dynstr_append(&extended_row, "'"); - dynstr_append(&extended_row, ptr); - dynstr_append(&extended_row, "'"); - } - else - dynstr_append(&extended_row, ptr); - } - } - } - else - dynstr_append(&extended_row,"''"); - } - else if (dynstr_append(&extended_row,"NULL")) - { - fputs("Aborting dump (out of memory)",stderr); - error= EX_EOM; - goto err; - } - } - else - { - if (i && !opt_xml) - { - fputc(',', md_result_file); - check_io(md_result_file); - } - if (row[i]) - { - if (!IS_NUM_FIELD(field)) - { - if (opt_xml) - { - print_xml_tag1(md_result_file, "\t\t", "field name=", - field->name, ""); - print_quoted_xml(md_result_file, row[i], length); - fputs("\n", md_result_file); - } - else if (opt_hex_blob && is_blob && length) + } + else + { + /* change any strings ("inf", "-inf", "nan") into NULL */ + char *ptr = row[i]; + if (my_isalpha(charset_info, *ptr) || (*ptr == '-' && + my_isalpha(charset_info, ptr[1]))) + dynstr_append(&extended_row, "NULL"); + else + { + if (field->type == FIELD_TYPE_DECIMAL) + { + /* add " signs around */ + dynstr_append(&extended_row, "'"); + dynstr_append(&extended_row, ptr); + dynstr_append(&extended_row, "'"); + } + else + dynstr_append(&extended_row, ptr); + } + } + } + else + dynstr_append(&extended_row,"''"); + } + else if (dynstr_append(&extended_row,"NULL")) + { + fputs("Aborting dump (out of memory)",stderr); + error= EX_EOM; + goto err; + } + } + else + { + if (i && !opt_xml) + { + fputc(',', md_result_file); + check_io(md_result_file); + } + if (row[i]) + { + if (!IS_NUM_FIELD(field)) + { + if (opt_xml) + { + print_xml_tag1(md_result_file, "\t\t", "field name=", + field->name, ""); + print_quoted_xml(md_result_file, row[i], length); + fputs("\n", md_result_file); + } + else if (opt_hex_blob && is_blob && length) { /* sakaik got the idea to to provide blob's in hex notation. */ char *ptr= row[i], *end= ptr + length; fputs("0x", md_result_file); for (; ptr < end ; ptr++) - fprintf(md_result_file, "%02X", *((uchar *)ptr)); + fprintf(md_result_file, "%02X", *((uchar *)ptr)); } else unescape(md_result_file, row[i], length); - } - else - { - /* change any strings ("inf", "-inf", "nan") into NULL */ - char *ptr = row[i]; - if (opt_xml) - { - print_xml_tag1(md_result_file, "\t\t", "field name=", - field->name, ""); - fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL", - md_result_file); - fputs("\n", md_result_file); - } - else if (my_isalpha(charset_info, *ptr) || - (*ptr == '-' && my_isalpha(charset_info, ptr[1]))) - fputs("NULL", md_result_file); - else if (field->type == FIELD_TYPE_DECIMAL) - { - /* add " signs around */ - fputc('\'', md_result_file); - fputs(ptr, md_result_file); - fputc('\'', md_result_file); - } - else - fputs(ptr, md_result_file); - } - } - else + } + else + { + /* change any strings ("inf", "-inf", "nan") into NULL */ + char *ptr = row[i]; + if (opt_xml) + { + print_xml_tag1(md_result_file, "\t\t", "field name=", + field->name, ""); + fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL", + md_result_file); + fputs("\n", md_result_file); + } + else if (my_isalpha(charset_info, *ptr) || + (*ptr == '-' && my_isalpha(charset_info, ptr[1]))) + fputs("NULL", md_result_file); + else if (field->type == FIELD_TYPE_DECIMAL) + { + /* add " signs around */ + fputc('\'', md_result_file); + fputs(ptr, md_result_file); + fputc('\'', md_result_file); + } + else + fputs(ptr, md_result_file); + } + } + else { /* The field value is NULL */ if (!opt_xml) @@ -2412,61 +2430,61 @@ static void dump_table(char *table, char *db) field->name, "\n"); } check_io(md_result_file); - } + } } if (opt_xml) { fputs("\t\n", md_result_file); - check_io(md_result_file); + check_io(md_result_file); } if (extended_insert) { - ulong row_length; - dynstr_append(&extended_row,")"); + ulong row_length; + dynstr_append(&extended_row,")"); row_length = 2 + extended_row.length; if (total_length + row_length < opt_net_buffer_length) { - total_length += row_length; - fputc(',',md_result_file); /* Always row break */ - fputs(extended_row.str,md_result_file); - } + total_length += row_length; + fputc(',',md_result_file); /* Always row break */ + fputs(extended_row.str,md_result_file); + } else { - if (row_break) - fputs(";\n", md_result_file); - row_break=1; /* This is first row */ + if (row_break) + fputs(";\n", md_result_file); + row_break=1; /* This is first row */ fputs(insert_pat.str,md_result_file); fputs(extended_row.str,md_result_file); - total_length = row_length+init_length; + total_length = row_length+init_length; } - check_io(md_result_file); + check_io(md_result_file); } else if (!opt_xml) { - fputs(");\n", md_result_file); - check_io(md_result_file); + fputs(");\n", md_result_file); + check_io(md_result_file); } } /* XML - close table tag and supress regular output */ if (opt_xml) - fputs("\t\n", md_result_file); + fputs("\t\n", md_result_file); else if (extended_insert && row_break) - fputs(";\n", md_result_file); /* If not empty table */ + fputs(";\n", md_result_file); /* If not empty table */ fflush(md_result_file); check_io(md_result_file); if (mysql_errno(sock)) { my_snprintf(query, QUERY_LENGTH, - "%s: Error %d: %s when dumping table %s at row: %ld\n", - my_progname, - mysql_errno(sock), - mysql_error(sock), - result_table, - rownr); + "%s: Error %d: %s when dumping table %s at row: %ld\n", + my_progname, + mysql_errno(sock), + mysql_error(sock), + result_table, + rownr); fputs(query,stderr); error= EX_CONSCHECK; goto err; @@ -2479,7 +2497,7 @@ static void dump_table(char *table, char *db) if (opt_disable_keys) { fprintf(md_result_file,"/*!40000 ALTER TABLE %s ENABLE KEYS */;\n", - opt_quoted_table); + opt_quoted_table); check_io(md_result_file); } if (opt_autocommit) @@ -2538,7 +2556,7 @@ static int dump_all_databases() if (dump_all_tables_in_db(row[0])) result=1; } - if (was_views) + if (seen_views) { if (mysql_query(sock, "SHOW DATABASES") || !(tableres = mysql_store_result(sock))) @@ -2567,7 +2585,7 @@ static int dump_databases(char **db_names) if (dump_all_tables_in_db(*db)) result=1; } - if (!result && was_views) + if (!result && seen_views) { for (db= db_names ; *db ; db++) { @@ -2583,26 +2601,26 @@ static int init_dumping(char *database) { if (mysql_get_server_version(sock) >= 50003 && !my_strcasecmp(&my_charset_latin1, database, "information_schema")) - return 1; + return 1; if (mysql_select_db(sock, database)) { DB_error(sock, "when selecting the database"); - return 1; /* If --force */ + return 1; /* If --force */ } if (!path && !opt_xml) { if (opt_databases || opt_alldbs) { /* - length of table name * 2 (if name contains quotes), 2 quotes and 0 + length of table name * 2 (if name contains quotes), 2 quotes and 0 */ char quoted_database_buf[64*2+3]; char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted); if (opt_comments) { - fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase); - check_io(md_result_file); + fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase); + check_io(md_result_file); } if (!opt_create_db) { @@ -2610,9 +2628,9 @@ static int init_dumping(char *database) MYSQL_ROW row; MYSQL_RES *dbinfo; - my_snprintf(qbuf, sizeof(qbuf), - "SHOW CREATE DATABASE IF NOT EXISTS %s", - qdatabase); + my_snprintf(qbuf, sizeof(qbuf), + "SHOW CREATE DATABASE IF NOT EXISTS %s", + qdatabase); if (mysql_query(sock, qbuf) || !(dbinfo = mysql_store_result(sock))) { @@ -2621,22 +2639,22 @@ static int init_dumping(char *database) fprintf(md_result_file, "\n/*!40000 DROP DATABASE IF EXISTS %s;*/\n", qdatabase); - fprintf(md_result_file, - "\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n", - qdatabase); - } - else + fprintf(md_result_file, + "\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n", + qdatabase); + } + else { if (opt_drop_database) fprintf(md_result_file, "\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n", qdatabase); - row = mysql_fetch_row(dbinfo); - if (row[1]) - { - fprintf(md_result_file,"\n%s;\n",row[1]); + row = mysql_fetch_row(dbinfo); + if (row[1]) + { + fprintf(md_result_file,"\n%s;\n",row[1]); } - } + } } fprintf(md_result_file,"\nUSE %s;\n", qdatabase); check_io(md_result_file); @@ -2741,8 +2759,6 @@ static my_bool dump_all_views_in_db(char *database) uint numrows; char table_buff[NAME_LEN*2+3]; - if (init_dumping(database)) - return 1; if (opt_xml) print_xml_tag1(md_result_file, "", "database name=", database, "\n"); if (lock_tables) @@ -2801,7 +2817,7 @@ static char *get_actual_table_name(const char *old_table_name, MEM_ROOT *root) /* Check memory for quote_for_like() */ DBUG_ASSERT(2*sizeof(old_table_name) < sizeof(show_name_buff)); my_snprintf(query, sizeof(query), "SHOW TABLES LIKE %s", - quote_for_like(old_table_name, show_name_buff)); + quote_for_like(old_table_name, show_name_buff)); if (mysql_query_with_error_report(sock, 0, query)) { @@ -2896,7 +2912,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) } /* Dump each selected view */ - if (was_views) + if (seen_views) { for (pos= dump_tables; pos < end; pos++) get_view_structure(*pos, db); @@ -2946,14 +2962,14 @@ static int do_show_master_status(MYSQL *mysql_con) "recovery from\n--\n\n"); fprintf(md_result_file, "%sCHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", - comment_prefix, row[0], row[1]); + comment_prefix, row[0], row[1]); check_io(md_result_file); } else if (!ignore_errors) { /* SHOW MASTER STATUS reports nothing and --force is not enabled */ - my_printf_error(0, "Error: Binlogging on server not active", - MYF(0)); + my_printf_error(0, "Error: Binlogging on server not active", + MYF(0)); mysql_free_result(master); return 1; } @@ -2973,7 +2989,7 @@ static int do_flush_tables_read_lock(MYSQL *mysql_con) and most client connections are stalled. Of course, if a second long update starts between the two FLUSHes, we have that bad stall. */ - return + return ( mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES") || mysql_query_with_error_report(mysql_con, 0, "FLUSH TABLES WITH READ LOCK") ); @@ -3015,7 +3031,7 @@ static int start_transaction(MYSQL *mysql_con, my_bool consistent_read_now) static ulong find_set(TYPELIB *lib, const char *x, uint length, - char **err_pos, uint *err_len) + char **err_pos, uint *err_len) { const char *end= x + length; ulong found= 0; @@ -3057,10 +3073,10 @@ static ulong find_set(TYPELIB *lib, const char *x, uint length, /* Print a value with a prefix on file */ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, - const char *prefix, const char *name, - int string_value) + const char *prefix, const char *name, + int string_value) { - MYSQL_FIELD *field; + MYSQL_FIELD *field; mysql_field_seek(result, 0); for ( ; (field = mysql_fetch_field(result)) ; row++) @@ -3069,18 +3085,18 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, { if (row[0] && row[0][0] && strcmp(row[0],"0")) /* Skip default */ { - fputc(' ',file); - fputs(prefix, file); - if (string_value) - unescape(file,row[0],(uint) strlen(row[0])); - else - fputs(row[0], file); - check_io(file); - return; + fputc(' ',file); + fputs(prefix, file); + if (string_value) + unescape(file,row[0],(uint) strlen(row[0])); + else + fputs(row[0], file); + check_io(file); + return; } } } - return; /* This shouldn't happen */ + return; /* This shouldn't happen */ } /* print_value */ @@ -3091,19 +3107,19 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, Check if we the table is one of the table types that should be ignored: MRG_ISAM, MRG_MYISAM, if opt_delayed, if that table supports delayed inserts. If the table should be altogether ignored, it returns a TRUE, FALSE if it - should not be ignored. If the user has selected to use INSERT DELAYED, it - sets the value of the bool pointer supports_delayed_inserts to 0 if not + should not be ignored. If the user has selected to use INSERT DELAYED, it + sets the value of the bool pointer supports_delayed_inserts to 0 if not supported, 1 if it is supported. ARGS check_if_ignore_table() - table_name Table name to check + table_name Table name to check table_type Type of table GLOBAL VARIABLES - sock MySQL socket - verbose Write warning messages + sock MySQL socket + verbose Write warning messages RETURN char (bit value) See IGNORE_ values at top @@ -3120,23 +3136,23 @@ char check_if_ignore_table(const char *table_name, char *table_type) /* Check memory for quote_for_like() */ DBUG_ASSERT(2*sizeof(table_name) < sizeof(show_name_buff)); my_snprintf(buff, sizeof(buff), "show table status like %s", - quote_for_like(table_name, show_name_buff)); + quote_for_like(table_name, show_name_buff)); if (mysql_query_with_error_report(sock, &res, buff)) { if (mysql_errno(sock) != ER_PARSE_ERROR) - { /* If old MySQL version */ + { /* If old MySQL version */ if (verbose) - fprintf(stderr, - "-- Warning: Couldn't get status information for table %s (%s)\n", - table_name,mysql_error(sock)); + fprintf(stderr, + "-- Warning: Couldn't get status information for table %s (%s)\n", + table_name,mysql_error(sock)); DBUG_RETURN(result); /* assume table is ok */ } } if (!(row= mysql_fetch_row(res))) { fprintf(stderr, - "Error: Couldn't read status information for table %s (%s)\n", - table_name, mysql_error(sock)); + "Error: Couldn't read status information for table %s (%s)\n", + table_name, mysql_error(sock)); mysql_free_result(res); DBUG_RETURN(result); /* assume table is ok */ } @@ -3199,8 +3215,8 @@ static char *primary_key_fields(const char *table_name) uint result_length = 0; char *result = 0; - my_snprintf(show_keys_buff, sizeof(show_keys_buff), - "SHOW KEYS FROM %s", table_name); + my_snprintf(show_keys_buff, sizeof(show_keys_buff), + "SHOW KEYS FROM %s", table_name); if (mysql_query(sock, show_keys_buff) || !(res = mysql_store_result(sock))) { @@ -3276,7 +3292,7 @@ static int replace(DYNAMIC_STRING *ds_str, if (!start) return 1; init_dynamic_string(&ds_tmp, "", - ds_str->length + replace_len, 256); + ds_str->length + replace_len, 256); dynstr_append_mem(&ds_tmp, ds_str->str, start - ds_str->str); dynstr_append_mem(&ds_tmp, replace_str, replace_len); dynstr_append(&ds_tmp, start + search_len); @@ -3304,9 +3320,9 @@ static my_bool get_view_structure(char *table, char* db) MYSQL_RES *table_res; MYSQL_ROW row; MYSQL_FIELD *field; - char *result_table, *opt_quoted_table; - char table_buff[NAME_LEN*2+3]; - char table_buff2[NAME_LEN*2+3]; + char *result_table, *opt_quoted_table; + char table_buff[NAME_LEN*2+3]; + char table_buff2[NAME_LEN*2+3]; char query[QUERY_LENGTH]; FILE *sql_file = md_result_file; DBUG_ENTER("get_view_structure"); @@ -3319,7 +3335,7 @@ static my_bool get_view_structure(char *table, char* db) #ifdef NOT_REALLY_USED_YET sprintf(insert_pat,"SET OPTION SQL_QUOTE_SHOW_CREATE=%d", - (opt_quoted || opt_keywords)); + (opt_quoted || opt_keywords)); #endif result_table= quote_name(table, table_buff, 1); @@ -3354,7 +3370,7 @@ static my_bool get_view_structure(char *table, char* db) if (!opt_xml && opt_comments) { - fprintf(sql_file, "\n--\n-- View structure for view %s\n--\n\n", + fprintf(sql_file, "\n--\n-- Final view structure for view %s\n--\n\n", result_table); check_io(sql_file); } @@ -3435,7 +3451,7 @@ static my_bool get_view_structure(char *table, char* db) char quoted_host_name_str[HOSTNAME_LENGTH * 2 + 3]; parse_user(row[1], lengths[1], user_name_str, &user_name_len, - host_name_str, &host_name_len); + host_name_str, &host_name_len); ptr= search_buf; search_len= diff --git a/include/my_global.h b/include/my_global.h index e7205c94c18..c9f27e0031e 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -735,6 +735,9 @@ typedef SOCKET_SIZE_TYPE size_socket; #define DBL_MAX 1.79769313486231470e+308 #define FLT_MAX ((float)3.40282346638528860e+38) #endif +#ifndef SSIZE_MAX +#define SSIZE_MAX ((~((size_t) 0)) / 2) +#endif #if !defined(HAVE_ISINF) && !defined(isinf) #define isinf(X) 0 diff --git a/innobase/row/row0mysql.c b/innobase/row/row0mysql.c index 89b82882d93..9e922a3e04a 100644 --- a/innobase/row/row0mysql.c +++ b/innobase/row/row0mysql.c @@ -2570,14 +2570,14 @@ do not allow the discard. We also reserve the data dictionary latch. */ } } funct_exit: + trx_commit_for_mysql(trx); + row_mysql_unlock_data_dictionary(trx); if (graph) { que_graph_free(graph); } - trx_commit_for_mysql(trx); - trx->op_info = ""; return((int) err); @@ -2707,10 +2707,10 @@ row_import_tablespace_for_mysql( } funct_exit: - row_mysql_unlock_data_dictionary(trx); - trx_commit_for_mysql(trx); + row_mysql_unlock_data_dictionary(trx); + trx->op_info = ""; return((int) err); @@ -3398,6 +3398,8 @@ fputs(" InnoDB: You are trying to drop table ", stderr); } funct_exit: + trx_commit_for_mysql(trx); + if (locked_dictionary) { row_mysql_unlock_data_dictionary(trx); } @@ -3408,8 +3410,6 @@ funct_exit: que_graph_free(graph); - trx_commit_for_mysql(trx); - trx->op_info = ""; #ifndef UNIV_HOTBACKUP @@ -3488,10 +3488,10 @@ loop: } } - row_mysql_unlock_data_dictionary(trx); - trx_commit_for_mysql(trx); + row_mysql_unlock_data_dictionary(trx); + trx->op_info = ""; return(err); @@ -3905,6 +3905,8 @@ row_rename_table_for_mysql( } } funct_exit: + trx_commit_for_mysql(trx); + if (!recovering_temp_table) { row_mysql_unlock_data_dictionary(trx); } @@ -3917,8 +3919,6 @@ funct_exit: mem_heap_free(heap); } - trx_commit_for_mysql(trx); - trx->op_info = ""; return((int) err); diff --git a/innobase/row/row0sel.c b/innobase/row/row0sel.c index 1402d3aaba6..23971767e7e 100644 --- a/innobase/row/row0sel.c +++ b/innobase/row/row0sel.c @@ -1064,11 +1064,12 @@ row_sel_try_search_shortcut( ut_ad(plan->pcur.latch_mode == node->latch_mode); plan->n_rows_fetched++; + ret = SEL_FOUND; func_exit: if (UNIV_LIKELY_NULL(heap)) { mem_heap_free(heap); } - return(SEL_FOUND); + return(ret); } /************************************************************************* diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl index 6fa6bc73bdb..0ca16b61fc2 100644 --- a/mysql-test/lib/mtr_process.pl +++ b/mysql-test/lib/mtr_process.pl @@ -890,19 +890,28 @@ sub mtr_kill_processes ($) { sub mtr_kill_process ($$$$) { my $pid= shift; my $signal= shift; - my $retries= shift; + my $total_retries= shift; my $timeout= shift; - while (1) + for (my $cur_attempt= 1; $cur_attempt <= $total_retries; ++$cur_attempt) { + mtr_debug("Sending $signal to $pid..."); + kill($signal, $pid); - last unless kill (0, $pid) and $retries--; + unless (kill (0, $pid)) + { + mtr_debug("Process $pid died."); + return; + } - mtr_debug("Sleep $timeout second waiting for processes to die"); + mtr_debug("Sleeping $timeout second(s) waiting for processes to die..."); sleep($timeout); } + + mtr_debug("Process $pid is still alive after $total_retries " . + "of sending signal $signal."); } ############################################################################## diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index bfd1f7de059..3293487a0ac 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2860,22 +2860,58 @@ sub im_stop($) { # Try graceful shutdown. + mtr_debug("IM-main pid: $instance_manager->{'pid'}"); + mtr_debug("Stopping IM-main..."); + mtr_kill_process($instance_manager->{'pid'}, 'TERM', 10, 1); + # If necessary, wait for angel process to die. + + if (defined $instance_manager->{'angel_pid'}) + { + mtr_debug("IM-angel pid: $instance_manager->{'angel_pid'}"); + mtr_debug("Waiting for IM-angel to die..."); + + my $total_attempts= 10; + + for (my $cur_attempt=1; $cur_attempt <= $total_attempts; ++$cur_attempt) + { + unless (kill (0, $instance_manager->{'angel_pid'})) + { + mtr_debug("IM-angel died."); + last; + } + + sleep(1); + } + } + # Check that all processes died. my $clean_shutdown= 0; while (1) { - last if kill (0, $instance_manager->{'pid'}); + if (kill (0, $instance_manager->{'pid'})) + { + mtr_debug("IM-main is still alive."); + last; + } - last if (defined $instance_manager->{'angel_pid'}) && - kill (0, $instance_manager->{'angel_pid'}); + if (defined $instance_manager->{'angel_pid'} && + kill (0, $instance_manager->{'angel_pid'})) + { + mtr_debug("IM-angel is still alive."); + last; + } foreach my $pid (@mysqld_pids) { - last if kill (0, $pid); + if (kill (0, $pid)) + { + mtr_debug("Guarded mysqld ($pid) is still alive."); + last; + } } $clean_shutdown= 1; @@ -2886,15 +2922,21 @@ sub im_stop($) { unless ($clean_shutdown) { - mtr_kill_process($instance_manager->{'angel_pid'}, 'KILL', 10, 1) - if defined $instance_manager->{'angel_pid'}; + + if (defined $instance_manager->{'angel_pid'}) + { + mtr_debug("Killing IM-angel..."); + mtr_kill_process($instance_manager->{'angel_pid'}, 'KILL', 10, 1) + } + mtr_debug("Killing IM-main..."); mtr_kill_process($instance_manager->{'pid'}, 'KILL', 10, 1); # Shutdown managed mysqld-processes. Some of them may be nonguarded, so IM # will not stop them on shutdown. So, we should firstly try to end them # legally. + mtr_debug("Killing guarded mysqld(s)..."); mtr_kill_processes(\@mysqld_pids); # Complain in error log so that a warning will be shown. diff --git a/mysql-test/r/func_in.result b/mysql-test/r/func_in.result index f758e2adfd9..e38e2624e19 100644 --- a/mysql-test/r/func_in.result +++ b/mysql-test/r/func_in.result @@ -202,35 +202,6 @@ select count(*) from t1 where id not in (1,2); count(*) 1 drop table t1; -create table t1 (f1 char(1), f2 int); -insert into t1 values (1,0),('a',1),('z',2); -select f1 from t1 where f1 in (1,'z'); -f1 -1 -z -select f2 from t1 where f2 in (1,'z'); -f2 -0 -1 -Warnings: -Warning 1292 Truncated incorrect INTEGER value: 'z' -select f1 from t1 where 'z' in (1,f1); -f1 -z -select * from t1 where 'z' in (f2,f1); -f1 f2 -1 0 -a 1 -z 2 -Warnings: -Warning 1292 Truncated incorrect DOUBLE value: 'z' -Warning 1292 Truncated incorrect DOUBLE value: 'z' -Warning 1292 Truncated incorrect DOUBLE value: 'z' -select * from t1 where 1 in (f2,f1); -f1 f2 -1 0 -a 1 -drop table t1; CREATE TABLE t1 (a int PRIMARY KEY); INSERT INTO t1 VALUES (44), (45), (46); SELECT * FROM t1 WHERE a IN (45); diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index f1da903ae98..5b24480f2e9 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -785,8 +785,8 @@ select f1 from t1 where "2006-1-1" between f1 and 'zzz'; f1 Warnings: Warning 1292 Incorrect date value: 'zzz' for column 'f1' at row 1 -Warning 1292 Truncated incorrect INTEGER value: 'zzz' -Warning 1292 Truncated incorrect INTEGER value: 'zzz' +Warning 1292 Truncated incorrect DOUBLE value: 'zzz' +Warning 1292 Truncated incorrect DOUBLE value: 'zzz' select f1 from t1 where makedate(2006,1) between date(f1) and date(f3); f1 2006-01-01 diff --git a/mysql-test/r/im_daemon_life_cycle.result b/mysql-test/r/im_daemon_life_cycle.result index d0a76b450fe..ea27fcb6db1 100644 --- a/mysql-test/r/im_daemon_life_cycle.result +++ b/mysql-test/r/im_daemon_life_cycle.result @@ -1,3 +1,4 @@ +Success: the process has been started. SHOW INSTANCES; instance_name status mysqld1 online diff --git a/mysql-test/r/im_life_cycle.result b/mysql-test/r/im_life_cycle.result index 36277f6aa28..a9f78aea7d3 100644 --- a/mysql-test/r/im_life_cycle.result +++ b/mysql-test/r/im_life_cycle.result @@ -1,44 +1,45 @@ + +-------------------------------------------------------------------- +-- 1.1.1. +-------------------------------------------------------------------- +Success: the process has been started. SHOW INSTANCES; instance_name status mysqld1 online mysqld2 offline -SHOW INSTANCE STATUS mysqld1; -instance_name status version -mysqld1 online VERSION -SHOW INSTANCE STATUS mysqld2; -instance_name status version -mysqld2 offline VERSION + +-------------------------------------------------------------------- +-- 1.1.2. +-------------------------------------------------------------------- START INSTANCE mysqld2; -SHOW INSTANCES; -instance_name status -mysqld1 online -mysqld2 online -SHOW INSTANCE STATUS mysqld1; -instance_name status version -mysqld1 online VERSION -SHOW INSTANCE STATUS mysqld2; -instance_name status version -mysqld2 online VERSION +Success: the process has been started. SHOW VARIABLES LIKE 'port'; Variable_name Value -port IM_MYSQLD1_PORT +port IM_MYSQLD2_PORT + +-------------------------------------------------------------------- +-- 1.1.3. +-------------------------------------------------------------------- STOP INSTANCE mysqld2; -SHOW INSTANCES; -instance_name status -mysqld1 online -mysqld2 offline -SHOW INSTANCE STATUS mysqld1; -instance_name status version -mysqld1 online VERSION -SHOW INSTANCE STATUS mysqld2; -instance_name status version -mysqld2 offline VERSION +Success: the process has been stopped. + +-------------------------------------------------------------------- +-- 1.1.4. +-------------------------------------------------------------------- START INSTANCE mysqld3; ERROR HY000: Bad instance name. Check that the instance with such a name exists START INSTANCE mysqld1; ERROR HY000: The instance is already started + +-------------------------------------------------------------------- +-- 1.1.5. +-------------------------------------------------------------------- STOP INSTANCE mysqld3; ERROR HY000: Bad instance name. Check that the instance with such a name exists + +-------------------------------------------------------------------- +-- 1.1.6. +-------------------------------------------------------------------- SHOW INSTANCES; instance_name status mysqld1 online @@ -50,20 +51,25 @@ SHOW INSTANCES; instance_name status mysqld1 online mysqld2 offline + +-------------------------------------------------------------------- +-- 1.1.7. +-------------------------------------------------------------------- START INSTANCE mysqld2; -SHOW INSTANCES; -instance_name status -mysqld1 online -mysqld2 online +Success: the process has been started. Killing the process... Sleeping... Success: the process was killed. -SHOW INSTANCES; -instance_name status -mysqld1 online -mysqld2 offline + +-------------------------------------------------------------------- +-- 1.1.8. +-------------------------------------------------------------------- SHOW INSTANCE STATUS; ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use + +-------------------------------------------------------------------- +-- BUG#12813 +-------------------------------------------------------------------- START INSTANCE mysqld1,mysqld2,mysqld3; ERROR 42000: You have an error in your command syntax. Check the manual that corresponds to your MySQL Instance Manager version for the right syntax to use STOP INSTANCE mysqld1,mysqld2,mysqld3; diff --git a/mysql-test/r/im_utils.result b/mysql-test/r/im_utils.result index fbfaeaebcac..e6a5e007ed4 100644 --- a/mysql-test/r/im_utils.result +++ b/mysql-test/r/im_utils.result @@ -1,3 +1,4 @@ +Success: the process has been started. SHOW INSTANCES; instance_name status mysqld1 online @@ -42,7 +43,9 @@ skip-innodb VALUE skip-bdb VALUE skip-ndbcluster VALUE START INSTANCE mysqld2; +Success: the process has been started. STOP INSTANCE mysqld2; +Success: the process has been stopped. SHOW mysqld1 LOG FILES; Logfile Path File size ERROR LOG PATH FILE_SIZE diff --git a/mysql-test/r/insert.result b/mysql-test/r/insert.result index 00a987c9254..82fad8e912c 100644 --- a/mysql-test/r/insert.result +++ b/mysql-test/r/insert.result @@ -305,3 +305,29 @@ insert delayed into v1 values (1); ERROR HY000: 'test.v1' is not BASE TABLE drop table t1; drop view v1; +create table t1 (id int primary key, data int); +insert into t1 values (1, 1), (2, 2), (3, 3); +select row_count(); +row_count() +3 +insert ignore into t1 values (1, 1); +select row_count(); +row_count() +0 +replace into t1 values (1, 11); +select row_count(); +row_count() +2 +replace into t1 values (4, 4); +select row_count(); +row_count() +1 +insert into t1 values (2, 2) on duplicate key update data= data + 10; +select row_count(); +row_count() +2 +insert into t1 values (5, 5) on duplicate key update data= data + 10; +select row_count(); +row_count() +1 +drop table t1; diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index 2cb122fb988..2188d58e526 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -67,3 +67,9 @@ Select_priv N use test; use test; +create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb; +lock tables t1 write; + alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // + alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // +unlock tables; +drop table t1; diff --git a/mysql-test/r/myisam.result b/mysql-test/r/myisam.result index 14195447b54..6004575a0e4 100644 --- a/mysql-test/r/myisam.result +++ b/mysql-test/r/myisam.result @@ -747,6 +747,14 @@ select count(id1) from t1 where id2 = 10; count(id1) 5 drop table t1; +CREATE TABLE t1(a CHAR(9), b VARCHAR(7)) ENGINE=MyISAM; +INSERT INTO t1(a) VALUES('xxxxxxxxx'),('xxxxxxxxx'); +UPDATE t1 AS ta1,t1 AS ta2 SET ta1.b='aaaaaa',ta2.b='bbbbbb'; +SELECT * FROM t1; +a b +xxxxxxxxx bbbbbb +xxxxxxxxx bbbbbb +DROP TABLE t1; set storage_engine=MyISAM; drop table if exists t1,t2,t3; --- Testing varchar --- diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index eff46ecc2d6..e496e1ef35d 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1458,7 +1458,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t2` ENABLE KEYS */; DROP TABLE IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 CREATE TABLE `v2` ( `a` varchar(30) ) */; @@ -1764,7 +1763,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t1` ENABLE KEYS */; DROP TABLE IF EXISTS `v1`; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 CREATE TABLE `v1` ( `a` int(11) ) */; @@ -1822,7 +1820,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t2` ENABLE KEYS */; DROP TABLE IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 CREATE TABLE `v2` ( `a` varchar(30) ) */; @@ -1915,7 +1912,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t1` ENABLE KEYS */; DROP TABLE IF EXISTS `v1`; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 CREATE TABLE `v1` ( `a` int(11), `b` int(11), @@ -1923,13 +1919,11 @@ DROP TABLE IF EXISTS `v1`; ) */; DROP TABLE IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 CREATE TABLE `v2` ( `a` int(11) ) */; DROP TABLE IF EXISTS `v3`; /*!50001 DROP VIEW IF EXISTS `v3`*/; -/*!50001 DROP TABLE IF EXISTS `v3`*/; /*!50001 CREATE TABLE `v3` ( `a` int(11), `b` int(11), @@ -2490,7 +2484,6 @@ UNLOCK TABLES; /*!40000 ALTER TABLE `t1` ENABLE KEYS */; DROP TABLE IF EXISTS `v0`; /*!50001 DROP VIEW IF EXISTS `v0`*/; -/*!50001 DROP TABLE IF EXISTS `v0`*/; /*!50001 CREATE TABLE `v0` ( `a` int(11), `b` varchar(32), @@ -2498,7 +2491,6 @@ DROP TABLE IF EXISTS `v0`; ) */; DROP TABLE IF EXISTS `v1`; /*!50001 DROP VIEW IF EXISTS `v1`*/; -/*!50001 DROP TABLE IF EXISTS `v1`*/; /*!50001 CREATE TABLE `v1` ( `a` int(11), `b` varchar(32), @@ -2506,16 +2498,11 @@ DROP TABLE IF EXISTS `v1`; ) */; DROP TABLE IF EXISTS `v2`; /*!50001 DROP VIEW IF EXISTS `v2`*/; -/*!50001 DROP TABLE IF EXISTS `v2`*/; /*!50001 CREATE TABLE `v2` ( `a` int(11), `b` varchar(32), `c` varchar(32) ) */; - -CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET latin1 */; - -USE `test`; /*!50001 DROP TABLE IF EXISTS `v0`*/; /*!50001 DROP VIEW IF EXISTS `v0`*/; /*!50001 CREATE ALGORITHM=UNDEFINED */ @@ -2770,3 +2757,62 @@ p CREATE DEFINER=`root`@`localhost` PROCEDURE `p`() select 42 drop function f; drop procedure p; +create database mysqldump_test_db; +use mysqldump_test_db; +create table t1 (id int); +create view v1 as select * from t1; +insert into t1 values (1232131); +insert into t1 values (4711); +insert into t1 values (3231); +insert into t1 values (0815); + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +/*!40000 DROP DATABASE IF EXISTS `mysqldump_test_db`*/; + +CREATE DATABASE /*!32312 IF NOT EXISTS*/ `mysqldump_test_db` /*!40100 DEFAULT CHARACTER SET latin1 */; + +USE `mysqldump_test_db`; +DROP TABLE IF EXISTS `t1`; +CREATE TABLE `t1` ( + `id` int(11) default NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1; + + +/*!40000 ALTER TABLE `t1` DISABLE KEYS */; +LOCK TABLES `t1` WRITE; +INSERT INTO `t1` VALUES (1232131),(4711),(3231),(815); +UNLOCK TABLES; +/*!40000 ALTER TABLE `t1` ENABLE KEYS */; +DROP TABLE IF EXISTS `v1`; +/*!50001 DROP VIEW IF EXISTS `v1`*/; +/*!50001 CREATE TABLE `v1` ( + `id` int(11) +) */; +/*!50001 DROP TABLE IF EXISTS `v1`*/; +/*!50001 DROP VIEW IF EXISTS `v1`*/; +/*!50001 CREATE ALGORITHM=UNDEFINED */ +/*!50013 DEFINER=`root`@`localhost` SQL SECURITY DEFINER */ +/*!50001 VIEW `v1` AS select `t1`.`id` AS `id` from `t1` */; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +drop view v1; +drop table t1; +drop database mysqldump_test_db; diff --git a/mysql-test/r/rpl_auto_increment_11932.result b/mysql-test/r/rpl_auto_increment_11932.result new file mode 100644 index 00000000000..25eda6ee454 --- /dev/null +++ b/mysql-test/r/rpl_auto_increment_11932.result @@ -0,0 +1,47 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +drop database if exists test1; +create database test1; +use test1; +CREATE TABLE `t1` ( +`id` int(10) unsigned NOT NULL auto_increment, +`fname` varchar(100) default NULL, +PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; +INSERT INTO `t1` VALUES (1, 'blablabla'); +CREATE TABLE `t2` ( +`id` int(10) NOT NULL auto_increment, +`comment` varchar(255) NOT NULL default '', +PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=3 ; +INSERT INTO `t2` VALUES (1, 'testtest 1'); +INSERT INTO `t2` VALUES (2, 'test 2'); +CREATE PROCEDURE simpleproc3 () +NOT DETERMINISTIC +BEGIN +INSERT INTO t1 (fname) (SELECT t2.comment FROM t2 WHERE t2.id = '1'); +INSERT INTO t1 (fname) VALUES('test'); +END +$ +CALL simpleproc3(); +select * from t2; +id comment +1 testtest 1 +2 test 2 +TRUNCATE TABLE `t1`; +CALL simpleproc3(); +select * from t1; +id fname +1 testtest 1 +2 test +use test1; +select * from t1; +id fname +1 testtest 1 +2 test +drop database test1; +drop database test1; diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index b385c576f2e..e6c590489a0 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2730,6 +2730,12 @@ ERROR HY000: Key 'a' doesn't exist in table 't1' EXPLAIN SELECT * FROM t1 FORCE INDEX (a); ERROR HY000: Key 'a' doesn't exist in table 't1' DROP TABLE t1; +CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL); +INSERT INTO t1 VALUES (10); +SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1; +i='1e+01' i=1e+01 i in (1e+01,1e+01) i in ('1e+01','1e+01') +0 1 1 1 +DROP TABLE t1; CREATE TABLE t1 ( K2C4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '', K4N4 varchar(4) character set latin1 collate latin1_bin NOT NULL default '0000', diff --git a/mysql-test/r/sql_mode.result b/mysql-test/r/sql_mode.result index b05680f9c54..474659f7dfc 100644 --- a/mysql-test/r/sql_mode.result +++ b/mysql-test/r/sql_mode.result @@ -485,6 +485,10 @@ set sql_mode=2097152; select @@sql_mode; @@sql_mode STRICT_TRANS_TABLES +set sql_mode=4194304; +select @@sql_mode; +@@sql_mode +STRICT_ALL_TABLES set sql_mode=16384+(65536*4); select @@sql_mode; @@sql_mode diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 8b4aba367fb..d4791c6b117 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -169,21 +169,22 @@ select @log; @log (BEFORE_INSERT: new=(id=1, data=2)) set @log:= ""; -replace t1 values (1, 3), (2, 2); +insert into t1 (id, data) values (1, 3), (2, 2) on duplicate key update data= data + 1; select @log; @log -(BEFORE_INSERT: new=(id=1, data=3))(BEFORE_UPDATE: old=(id=1, data=1) new=(id=1, data=3))(AFTER_UPDATE: old=(id=1, data=1) new=(id=1, data=3))(BEFORE_INSERT: new=(id=2, data=2))(AFTER_INSERT: new=(id=2, data=2)) -alter table t1 add ts timestamp default now(); +(BEFORE_INSERT: new=(id=1, data=3))(BEFORE_UPDATE: old=(id=1, data=1) new=(id=1, data=2))(AFTER_UPDATE: old=(id=1, data=1) new=(id=1, data=2))(BEFORE_INSERT: new=(id=2, data=2))(AFTER_INSERT: new=(id=2, data=2)) set @log:= ""; -replace t1 (id, data) values (1, 4); +replace t1 values (1, 4), (3, 3); select @log; @log -(BEFORE_INSERT: new=(id=1, data=4))(BEFORE_DELETE: old=(id=1, data=3))(AFTER_DELETE: old=(id=1, data=3))(AFTER_INSERT: new=(id=1, data=4)) +(BEFORE_INSERT: new=(id=1, data=4))(BEFORE_DELETE: old=(id=1, data=2))(AFTER_DELETE: old=(id=1, data=2))(AFTER_INSERT: new=(id=1, data=4))(BEFORE_INSERT: new=(id=3, data=3))(AFTER_INSERT: new=(id=3, data=3)) +drop trigger t1_bd; +drop trigger t1_ad; set @log:= ""; -insert into t1 (id, data) values (1, 5), (3, 3) on duplicate key update data= data + 2; +replace t1 values (1, 5); select @log; @log -(BEFORE_INSERT: new=(id=1, data=5))(BEFORE_UPDATE: old=(id=1, data=4) new=(id=1, data=6))(AFTER_UPDATE: old=(id=1, data=4) new=(id=1, data=6))(BEFORE_INSERT: new=(id=3, data=3))(AFTER_INSERT: new=(id=3, data=3)) +(BEFORE_INSERT: new=(id=1, data=5))(AFTER_INSERT: new=(id=1, data=5)) drop table t1; create table t1 (id int primary key, data varchar(10), fk int); create table t2 (event varchar(100)); @@ -493,15 +494,9 @@ select * from t1; i k 3 13 replace into t1 values (3, 3); -ERROR 42S22: Unknown column 'at' in 'NEW' -select * from t1; -i k -3 3 -alter table t1 add ts timestamp default now(); -replace into t1 (i, k) values (3, 13); ERROR 42S22: Unknown column 'at' in 'OLD' select * from t1; -i k ts +i k drop table t1, t2; create table t1 (i int, bt int, k int, key(k)) engine=myisam; create table t2 (i int); @@ -574,18 +569,11 @@ i k 1 1 2 2 replace into t1 values (2, 4); -ERROR 42S22: Unknown column 'bt' in 'NEW' +ERROR 42S22: Unknown column 'bt' in 'OLD' select * from t1; i k 1 1 2 2 -alter table t1 add ts timestamp default now(); -replace into t1 (i, k) values (2, 11); -ERROR 42S22: Unknown column 'bt' in 'OLD' -select * from t1; -i k ts -1 1 0000-00-00 00:00:00 -2 2 0000-00-00 00:00:00 drop table t1, t2; drop function if exists bug5893; create table t1 (col1 int, col2 int); diff --git a/mysql-test/t/func_in.test b/mysql-test/t/func_in.test index 5a5e3ec798d..8ddf1fbe314 100644 --- a/mysql-test/t/func_in.test +++ b/mysql-test/t/func_in.test @@ -109,18 +109,6 @@ select count(*) from t1 where id not in (1); select count(*) from t1 where id not in (1,2); drop table t1; -# -# Bug#18360 Incorrect type coercion in IN() results in false comparison -# -create table t1 (f1 char(1), f2 int); -insert into t1 values (1,0),('a',1),('z',2); -select f1 from t1 where f1 in (1,'z'); -select f2 from t1 where f2 in (1,'z'); -select f1 from t1 where 'z' in (1,f1); -select * from t1 where 'z' in (f2,f1); -select * from t1 where 1 in (f2,f1); -drop table t1; - # End of 4.1 tests # diff --git a/mysql-test/t/im_daemon_life_cycle-im.opt b/mysql-test/t/im_daemon_life_cycle-im.opt index 21c01191e4c..3a45c7a41f7 100644 --- a/mysql-test/t/im_daemon_life_cycle-im.opt +++ b/mysql-test/t/im_daemon_life_cycle-im.opt @@ -1,2 +1,3 @@ --run-as-service --log=$MYSQLTEST_VARDIR/log/im.log +--monitoring-interval=1 diff --git a/mysql-test/t/im_daemon_life_cycle.imtest b/mysql-test/t/im_daemon_life_cycle.imtest index 87388d7c1e6..3afc36935f8 100644 --- a/mysql-test/t/im_daemon_life_cycle.imtest +++ b/mysql-test/t/im_daemon_life_cycle.imtest @@ -10,6 +10,22 @@ ########################################################################### +# Wait for mysqld1 (guarded instance) to start. + +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started + +# Let IM detect that mysqld1 is online. This delay should be longer than +# monitoring interval. + +--sleep 3 + +# Check that start conditions are as expected. + SHOW INSTANCES; ---exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted +########################################################################### + +# Kill the IM main process and check that the IM Angel will restart the main +# process. + +--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_PATH_PID restarted 30 diff --git a/mysql-test/t/im_life_cycle-im.opt b/mysql-test/t/im_life_cycle-im.opt new file mode 100644 index 00000000000..34b74ce0c95 --- /dev/null +++ b/mysql-test/t/im_life_cycle-im.opt @@ -0,0 +1 @@ +--monitoring-interval=1 diff --git a/mysql-test/t/im_life_cycle.imtest b/mysql-test/t/im_life_cycle.imtest index 445ae7f72fa..2cbe53a7b28 100644 --- a/mysql-test/t/im_life_cycle.imtest +++ b/mysql-test/t/im_life_cycle.imtest @@ -17,11 +17,23 @@ # ########################################################################### +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.1. +--echo -------------------------------------------------------------------- + +# Wait for mysqld1 (guarded instance) to start. + +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started + +# Let IM detect that mysqld1 is online. This delay should be longer than +# monitoring interval. + +--sleep 3 + +# Check that start conditions are as expected. + SHOW INSTANCES; ---replace_column 3 VERSION -SHOW INSTANCE STATUS mysqld1; ---replace_column 3 VERSION -SHOW INSTANCE STATUS mysqld2; ########################################################################### # @@ -33,20 +45,24 @@ SHOW INSTANCE STATUS mysqld2; # ########################################################################### +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.2. +--echo -------------------------------------------------------------------- + START INSTANCE mysqld2; -# FIXME ---sleep 3 +# FIXME: START INSTANCE should be synchronous. +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started -SHOW INSTANCES; ---replace_column 3 VERSION -SHOW INSTANCE STATUS mysqld1; ---replace_column 3 VERSION -SHOW INSTANCE STATUS mysqld2; +# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is +# synchronous. Even waiting for mysqld to start by looking at its pid file is +# not enough, because IM may not detect that mysqld has started. +# SHOW INSTANCES; ---connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD1_PORT,$IM_MYSQLD1_SOCK) +--connect (mysql_con,localhost,root,,mysql,$IM_MYSQLD2_PORT,$IM_MYSQLD2_SOCK) --connection mysql_con ---replace_result $IM_MYSQLD1_PORT IM_MYSQLD1_PORT +--replace_result $IM_MYSQLD2_PORT IM_MYSQLD2_PORT SHOW VARIABLES LIKE 'port'; --connection default @@ -61,15 +77,19 @@ SHOW VARIABLES LIKE 'port'; # ########################################################################### -STOP INSTANCE mysqld2; -# FIXME ---sleep 3 +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.3. +--echo -------------------------------------------------------------------- -SHOW INSTANCES; ---replace_column 3 VERSION -SHOW INSTANCE STATUS mysqld1; ---replace_column 3 VERSION -SHOW INSTANCE STATUS mysqld2; +STOP INSTANCE mysqld2; +# FIXME: STOP INSTANCE should be synchronous. +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped + +# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is +# synchronous. Even waiting for mysqld to start by looking at its pid file is +# not enough, because IM may not detect that mysqld has started. +# SHOW INSTANCES; ########################################################################### # @@ -81,16 +101,17 @@ SHOW INSTANCE STATUS mysqld2; # ########################################################################### ---error 3000 +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.4. +--echo -------------------------------------------------------------------- + +--error 3000 # ER_BAD_INSTANCE_NAME START INSTANCE mysqld3; ---error 3002 +--error 3002 # ER_INSTANCE_ALREADY_STARTED START INSTANCE mysqld1; -# FIXME TODO -# BUG#12813: START/STOP INSTANCE commands accept a list as argument -# START INSTANCE mysqld1, mysqld2; - ########################################################################### # # 1.1.5. Check that Instance Manager reports correct errors for 'STOP INSTANCE' @@ -101,27 +122,40 @@ START INSTANCE mysqld1; # ########################################################################### ---error 3000 +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.5. +--echo -------------------------------------------------------------------- + +--error 3000 # ER_BAD_INSTANCE_NAME STOP INSTANCE mysqld3; # TODO: IM should be fixed. # BUG#12673: Instance Manager allows to stop the instance many times -# --error 3002 +# --error 3002 # ER_INSTANCE_ALREADY_STARTED # STOP INSTANCE mysqld2; -# FIXME TODO -# BUG#12813: START/STOP INSTANCE commands accept a list as argument -# STOP INSTANCE mysqld1, mysqld2; - ########################################################################### # # 1.1.6. Check that Instance Manager is able to restart guarded instances. # ########################################################################### +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.6. +--echo -------------------------------------------------------------------- + SHOW INSTANCES; ---exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted +--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD1_PATH_PID restarted 30 + +# Give some time to IM to detect that mysqld was restarted. It should be longer +# than monitoring interval. + +--sleep 3 + +SHOW INSTANCES; ########################################################################### # @@ -129,17 +163,26 @@ SHOW INSTANCES; # ########################################################################### -SHOW INSTANCES; +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.7. +--echo -------------------------------------------------------------------- START INSTANCE mysqld2; -# FIXME ---sleep 3 +# FIXME: START INSTANCE should be synchronous. +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started -SHOW INSTANCES; +# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is +# synchronous. Even waiting for mysqld to start by looking at its pid file is +# not enough, because IM may not detect that mysqld has started. +# SHOW INSTANCES; ---exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed +--exec $MYSQL_TEST_DIR/t/kill_n_check.sh $IM_MYSQLD2_PATH_PID killed 10 -SHOW INSTANCES; +# FIXME: SHOW INSTANCES is not deterministic unless START INSTANCE is +# synchronous. Even waiting for mysqld to start by looking at its pid file is +# not enough, because IM may not detect that mysqld has started. +# SHOW INSTANCES; ########################################################################### # @@ -147,7 +190,13 @@ SHOW INSTANCES; # incomplete SHOW INSTANCE STATUS command. # ########################################################################### ---error 1149 + +--echo +--echo -------------------------------------------------------------------- +--echo -- 1.1.8. +--echo -------------------------------------------------------------------- + +--error ER_SYNTAX_ERROR SHOW INSTANCE STATUS; # @@ -159,8 +208,13 @@ SHOW INSTANCE STATUS; # a list as argument. # ---error 1149 +--echo +--echo -------------------------------------------------------------------- +--echo -- BUG#12813 +--echo -------------------------------------------------------------------- + +--error ER_SYNTAX_ERROR START INSTANCE mysqld1,mysqld2,mysqld3; ---error 1149 +--error ER_SYNTAX_ERROR STOP INSTANCE mysqld1,mysqld2,mysqld3; diff --git a/mysql-test/t/im_utils-im.opt b/mysql-test/t/im_utils-im.opt new file mode 100644 index 00000000000..34b74ce0c95 --- /dev/null +++ b/mysql-test/t/im_utils-im.opt @@ -0,0 +1 @@ +--monitoring-interval=1 diff --git a/mysql-test/t/im_utils.imtest b/mysql-test/t/im_utils.imtest index dc6fb93c4ff..47902eeba52 100644 --- a/mysql-test/t/im_utils.imtest +++ b/mysql-test/t/im_utils.imtest @@ -17,6 +17,17 @@ # - the second instance is offline; # +# Wait for mysqld1 (guarded instance) to start. + +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD1_PATH_PID 30 started + +# Let IM detect that mysqld1 is online. This delay should be longer than +# monitoring interval. + +--sleep 3 + +# Check that start conditions are as expected. + SHOW INSTANCES; # @@ -40,11 +51,10 @@ SHOW INSTANCE OPTIONS mysqld2; # START INSTANCE mysqld2; - -# FIXME --- sleep 3 +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 started STOP INSTANCE mysqld2; +--exec $MYSQL_TEST_DIR/t/wait_for_process.sh $IM_MYSQLD2_PATH_PID 30 stopped # # Check 'SHOW LOG FILES' command: diff --git a/mysql-test/t/innodb.test b/mysql-test/t/innodb.test index e4c8bf89cca..71b178d0e57 100644 --- a/mysql-test/t/innodb.test +++ b/mysql-test/t/innodb.test @@ -2196,3 +2196,16 @@ drop table t2, t1; # --error ER_TABLE_CANT_HANDLE_SPKEYS create table t1 (g geometry not null, spatial gk(g)) engine=innodb; + +####################################################################### +# # +# Please, DO NOT TOUCH this file as well as the innodb.result file. # +# These files are to be modified ONLY BY INNOBASE guys. # +# # +# Use innodb_mysql.[test|result] files instead. # +# # +# If nevertheless you need to make some changes here, please, forward # +# your commit message To: dev@innodb.com Cc: dev-innodb@mysql.com # +# (otherwise your changes may be erased). # +# # +####################################################################### diff --git a/mysql-test/t/insert.test b/mysql-test/t/insert.test index 0c64dd80bec..ac43d0bc818 100644 --- a/mysql-test/t/insert.test +++ b/mysql-test/t/insert.test @@ -187,3 +187,26 @@ create view v1 as select * from t1; insert delayed into v1 values (1); drop table t1; drop view v1; + +# +# Test for values returned by ROW_COUNT() function +# (and thus for values returned by mysql_affected_rows()) +# for various forms of INSERT +# +create table t1 (id int primary key, data int); +insert into t1 values (1, 1), (2, 2), (3, 3); +select row_count(); +insert ignore into t1 values (1, 1); +select row_count(); +# Reports that 2 rows are affected (1 deleted + 1 inserted) +replace into t1 values (1, 11); +select row_count(); +replace into t1 values (4, 4); +select row_count(); +# Reports that 2 rows are affected. This conforms to documentation. +# (Useful for differentiating inserts from updates). +insert into t1 values (2, 2) on duplicate key update data= data + 10; +select row_count(); +insert into t1 values (5, 5) on duplicate key update data= data + 10; +select row_count(); +drop table t1; diff --git a/mysql-test/t/kill_n_check.sh b/mysql-test/t/kill_n_check.sh index e722b3a180d..64cc869d1ec 100755 --- a/mysql-test/t/kill_n_check.sh +++ b/mysql-test/t/kill_n_check.sh @@ -1,66 +1,115 @@ #!/bin/sh -if [ $# -ne 2 ]; then - echo "Usage: kill_n_check.sh killed|restarted" +########################################################################### + +# NOTE: this script returns 0 (success) even in case of failure. This is +# because this script is executed under mysql-test-run[.pl] and it's better to +# examine particular problem in log file, than just having said that the test +# case has failed. + +########################################################################### + +check_restart() +{ + if [ ! -r "$pid_path" ]; then + user_msg='the process was killed' + return 1 + fi + + new_pid=`cat "$pid_path" 2>/dev/null` + + if [ $? -eq 0 -a "$original_pid" = "$new_pid" ]; then + user_msg='the process was not restarted' + return 1 + fi + + user_msg='the process was restarted' + return 0 +} + +########################################################################### + +if [ $# -ne 3 ]; then + echo "Usage: kill_n_check.sh killed|restarted " exit 0 fi pid_path="$1" expected_result="$2" +total_timeout="$3" -if [ -z "$pid_path" -o ! -r "$pid_path" ]; then - echo "Error: invalid PID path ($pid_path) or PID file does not exist." +if [ "$expected_result" != 'killed' -a \ + "$expected_result" != 'restarted' ]; then + echo "Error: invalid second argument ('killed' or 'restarted' expected)." exit 0 fi -if [ "$expected_result" != "killed" -a \ - "$expected_result" != "restarted" ]; then - echo "Error: expected result must be either 'killed' or 'restarted'." +if [ -z "$pid_path" ]; then + echo "Error: invalid PID path ($pid_path)." exit 0 fi -# echo "PID path: '$pid_path'" +if [ $expected_result = 'killed' -a ! -r "$pid_path" ]; then + echo "Error: PID file ($pid_path) does not exist." + exit 0 +fi + +if [ -z "$total_timeout" ]; then + echo "Error: timeout is not specified." + exit 0 +fi + +########################################################################### original_pid=`cat "$pid_path"` -# echo "Original PID: $original_pid" - echo "Killing the process..." kill -9 $original_pid +########################################################################### + echo "Sleeping..." -sleep 3 - -new_pid="" - -[ -r "$pid_path" ] && new_pid=`cat "$pid_path"` - -# echo "New PID: $new_pid" - if [ "$expected_result" = "restarted" ]; then - if [ -z "$new_pid" ]; then - echo "Error: the process was killed." - exit 0 - fi + # Wait for the process to restart. - if [ "$original_pid" -eq "$new_pid" ]; then - echo "Error: the process was not restarted." - exit 0 - fi - - echo "Success: the process was restarted." + cur_attempt=1 + + while true; do + + if check_restart; then + echo "Success: $user_msg." + exit 0 + fi + + [ $cur_attempt -ge $total_timeout ] && break + + sleep 1 + + cur_attempt=`expr $cur_attempt + 1` + + done + + echo "Error: $user_msg." exit 0 - -else # $expected_result = killed - + +else # $expected_result == killed + + # Here we have to sleep for some long time to ensure that the process will + # not be restarted. + + sleep $total_timeout + + new_pid=`cat "$pid_path" 2>/dev/null` + if [ "$new_pid" -a "$new_pid" -ne "$original_pid" ]; then echo "Error: the process was restarted." - exit 0 + else + echo "Success: the process was killed." fi - echo "Success: the process was killed." exit 0 + fi diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index ee03088b8c3..905d0699e6a 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -171,4 +171,30 @@ use test; # connection default; +# +# Bug #17264: MySQL Server freeze +# +connection locker; +create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb; +lock tables t1 write; +connection writer; +--sleep 2 +delimiter //; +send alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // +delimiter ;// +connection reader; +--sleep 2 +delimiter //; +send alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; alter table t1 auto_increment=0; // +delimiter ;// +connection locker; +--sleep 2 +unlock tables; +connection writer; +reap; +connection reader; +reap; +connection locker; +drop table t1; + # End of 5.0 tests diff --git a/mysql-test/t/myisam.test b/mysql-test/t/myisam.test index 15533ca00e6..a30548f46ff 100644 --- a/mysql-test/t/myisam.test +++ b/mysql-test/t/myisam.test @@ -697,6 +697,15 @@ select count(*) from t1 where id2 = 10; select count(id1) from t1 where id2 = 10; drop table t1; +# +# BUG#18036 - update of table joined to self reports table as crashed +# +CREATE TABLE t1(a CHAR(9), b VARCHAR(7)) ENGINE=MyISAM; +INSERT INTO t1(a) VALUES('xxxxxxxxx'),('xxxxxxxxx'); +UPDATE t1 AS ta1,t1 AS ta2 SET ta1.b='aaaaaa',ta2.b='bbbbbb'; +SELECT * FROM t1; +DROP TABLE t1; + # End of 4.1 tests # @@ -823,4 +832,3 @@ create table t3 (c1 int) engine=myisam pack_keys=default; --error 1064 create table t4 (c1 int) engine=myisam pack_keys=2; drop table t1, t2, t3; - diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index d53022665a0..ab865594d42 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1161,3 +1161,20 @@ show create procedure p; drop function f; drop procedure p; +# +# BUG#17201 Spurious 'DROP DATABASE' in output, +# also confusion between tables and views. +# Example code from Markus Popp + +create database mysqldump_test_db; +use mysqldump_test_db; +create table t1 (id int); +create view v1 as select * from t1; +insert into t1 values (1232131); +insert into t1 values (4711); +insert into t1 values (3231); +insert into t1 values (0815); +--exec $MYSQL_DUMP --skip-comments --add-drop-database --databases mysqldump_test_db +drop view v1; +drop table t1; +drop database mysqldump_test_db; diff --git a/mysql-test/t/rpl_auto_increment_11932.test b/mysql-test/t/rpl_auto_increment_11932.test new file mode 100644 index 00000000000..d4b7872fb2b --- /dev/null +++ b/mysql-test/t/rpl_auto_increment_11932.test @@ -0,0 +1,63 @@ +# +# Test of auto_increment +# BUG#11932 +# +# Bug reported that master and slave get out of sync after TRUNCATE +# TABLE. +# +# Test supplied by Are Casilla + +source include/master-slave.inc; +--disable_warnings +connection master; +drop database if exists test1; +--enable_warnings +create database test1; +use test1; + +CREATE TABLE `t1` ( + `id` int(10) unsigned NOT NULL auto_increment, + `fname` varchar(100) default NULL, + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; + +INSERT INTO `t1` VALUES (1, 'blablabla'); + +CREATE TABLE `t2` ( + `id` int(10) NOT NULL auto_increment, + `comment` varchar(255) NOT NULL default '', + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=3 ; + +INSERT INTO `t2` VALUES (1, 'testtest 1'); +INSERT INTO `t2` VALUES (2, 'test 2'); + +DELIMITER $; +CREATE PROCEDURE simpleproc3 () + NOT DETERMINISTIC + BEGIN + INSERT INTO t1 (fname) (SELECT t2.comment FROM t2 WHERE t2.id = '1'); + INSERT INTO t1 (fname) VALUES('test'); + END + $ +DELIMITER ;$ + +CALL simpleproc3(); + +select * from t2; + +TRUNCATE TABLE `t1`; +CALL simpleproc3(); + +select * from t1; + +save_master_pos; +connection slave; +sync_with_master; + +use test1; +select * from t1; + +drop database test1; +connection master; +drop database test1; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index ae3981ce47b..b75d0dd8bb6 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2285,6 +2285,25 @@ EXPLAIN SELECT * FROM t1 FORCE INDEX (a); DROP TABLE t1; +# +# Bug #18759 "Incorrect string to numeric conversion" +# +# This test is here so that the behavior will not be changed to 4.1 +# and not to 5.0 either. In 4.1 and 5.0 sending an integer as a string +# will be converted internally to real (double) value and it is not +# as accurate as bigint (longlong) for integers. Thus the results may +# vary. In 5.1 internally it is decimal, which is a string type and +# will be more accurate. Due to rather big changes needed to fix this +# in 4.1 or 5.0 it is not desired to do it in the stable versions. +# +# This test is here only to make sure that behavior is not changed in +# 4.1 and 5.0 +# +CREATE TABLE t1 (i BIGINT UNSIGNED NOT NULL); +INSERT INTO t1 VALUES (10); +SELECT i='1e+01',i=1e+01, i in (1e+01,1e+01), i in ('1e+01','1e+01') FROM t1; +DROP TABLE t1; + # End of 4.1 tests # diff --git a/mysql-test/t/sql_mode.test b/mysql-test/t/sql_mode.test index b67f1a73db6..2699cb66471 100644 --- a/mysql-test/t/sql_mode.test +++ b/mysql-test/t/sql_mode.test @@ -258,6 +258,9 @@ drop table t1, t2; select @@sql_mode; set sql_mode=2097152; select @@sql_mode; +# BUG#14675 +set sql_mode=4194304; +select @@sql_mode; set sql_mode=16384+(65536*4); select @@sql_mode; --error 1231 diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index a5bd2ba0b38..3743d8f5c76 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -185,24 +185,26 @@ select @log; set @log:= ""; insert ignore t1 values (1, 2); select @log; -# REPLACE: before insert trigger should be called for both records, -# but then for first one update will be executed (and both update -# triggers should fire). For second after insert trigger will be -# called as for usual insert +# INSERT ... ON DUPLICATE KEY UPDATE ... set @log:= ""; -replace t1 values (1, 3), (2, 2); +insert into t1 (id, data) values (1, 3), (2, 2) on duplicate key update data= data + 1; select @log; -# Now let us change table in such way that REPLACE on won't be executed -# using update. -alter table t1 add ts timestamp default now(); +# REPLACE (also test for bug#13479 "REPLACE activates UPDATE trigger, +# not the DELETE and INSERT triggers") +# We define REPLACE as INSERT which DELETEs old rows which conflict with +# row being inserted. So for the first record in statement below we will +# call before insert trigger, then delete will be executed (and both delete +# triggers should fire). Finally after insert trigger will be called. +# For the second record we will just call both on insert triggers. set @log:= ""; -# This REPLACE should be executed via DELETE and INSERT so proper -# triggers should be invoked. -replace t1 (id, data) values (1, 4); +replace t1 values (1, 4), (3, 3); select @log; -# Finally let us test INSERT ... ON DUPLICATE KEY UPDATE ... +# Now we will drop ON DELETE triggers to test REPLACE which is internally +# executed via update +drop trigger t1_bd; +drop trigger t1_ad; set @log:= ""; -insert into t1 (id, data) values (1, 5), (3, 3) on duplicate key update data= data + 2; +replace t1 values (1, 5); select @log; # This also drops associated triggers @@ -531,14 +533,11 @@ alter table t1 add primary key (i); --error 1054 insert into t1 values (3, 4) on duplicate key update k= k + 10; select * from t1; +# The following statement will delete old row and won't +# insert new one since after delete trigger will fail. --error 1054 replace into t1 values (3, 3); select * from t1; -# Change table in such way that REPLACE will delete row -alter table t1 add ts timestamp default now(); ---error 1054 -replace into t1 (i, k) values (3, 13); -select * from t1; # Also drops all triggers drop table t1, t2; @@ -594,11 +593,6 @@ select * from t1; --error 1054 replace into t1 values (2, 4); select * from t1; -# Change table in such way that REPLACE will delete row -alter table t1 add ts timestamp default now(); ---error 1054 -replace into t1 (i, k) values (2, 11); -select * from t1; # Also drops all triggers drop table t1, t2; diff --git a/mysql-test/t/wait_for_process.sh b/mysql-test/t/wait_for_process.sh new file mode 100755 index 00000000000..df0f4a17e3a --- /dev/null +++ b/mysql-test/t/wait_for_process.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +########################################################################### + +pid_path="$1" +total_attempts="$2" +event="$3" + +case "$3" in + started) + check_fn='check_started'; + ;; + + stopped) + check_fn='check_stopped'; + ;; + + *) + echo "Error: invalid third argument ('started' or 'stopped' expected)." + exit 0 +esac + +########################################################################### + +check_started() +{ + [ ! -r "$pid_path" ] && return 1 + + new_pid=`cat "$pid_path" 2>/dev/null` + + [ $? -eq 0 -a "$original_pid" = "$new_pid" ] && return 1 + + return 0 +} + +########################################################################### + +check_stopped() +{ + [ -r "$pid_path" ] && return 1 + + return 0 +} + +########################################################################### + +cur_attempt=1 + +while true; do + + if ( eval $check_fn ); then + echo "Success: the process has been $event." + exit 0 + fi + + [ $cur_attempt -ge $total_attempts ] && break + + sleep 1 + + cur_attempt=`expr $cur_attempt + 1` + +done + +echo "Error: the process has not been $event in $total_attempts secs." +exit 0 + diff --git a/ndb/include/util/ConfigValues.hpp b/ndb/include/util/ConfigValues.hpp index 457488e3c42..8dfb3c83df3 100644 --- a/ndb/include/util/ConfigValues.hpp +++ b/ndb/include/util/ConfigValues.hpp @@ -96,6 +96,7 @@ public: public: ConfigValuesFactory(Uint32 keys = 50, Uint32 data = 10); // Initial ConfigValuesFactory(ConfigValues * m_cfg); // + ~ConfigValuesFactory(); ConfigValues * m_cfg; ConfigValues * getConfigValues(); diff --git a/ndb/src/common/util/ConfigValues.cpp b/ndb/src/common/util/ConfigValues.cpp index 5c4b17c73ca..ae4fbfd2f71 100644 --- a/ndb/src/common/util/ConfigValues.cpp +++ b/ndb/src/common/util/ConfigValues.cpp @@ -294,6 +294,12 @@ ConfigValuesFactory::ConfigValuesFactory(ConfigValues * cfg){ } } +ConfigValuesFactory::~ConfigValuesFactory() +{ + if(m_cfg) + free(m_cfg); +} + ConfigValues * ConfigValuesFactory::create(Uint32 keys, Uint32 data){ Uint32 sz = sizeof(ConfigValues); @@ -528,7 +534,7 @@ ConfigValuesFactory::extractCurrentSection(const ConfigValues::ConstIterator & c } } - ConfigValues * ret = fac->m_cfg; + ConfigValues * ret = fac->getConfigValues(); delete fac; return ret; } diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index 7ad20e504f6..4428b158b6b 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -1945,7 +1945,7 @@ ndb_mgm_get_configuration(NdbMgmHandle handle, unsigned int version) { } delete prop; - return (ndb_mgm_configuration*)cvf.m_cfg; + return (ndb_mgm_configuration*)cvf.getConfigValues(); } while(0); delete prop; diff --git a/ndb/src/mgmsrv/ConfigInfo.cpp b/ndb/src/mgmsrv/ConfigInfo.cpp index e9093d59494..dfe4f9aa63e 100644 --- a/ndb/src/mgmsrv/ConfigInfo.cpp +++ b/ndb/src/mgmsrv/ConfigInfo.cpp @@ -2241,11 +2241,11 @@ ConfigInfo::ConfigInfo() if (!m_info.getCopy(param._section, §ion)) { Properties newsection(true); m_info.put(param._section, &newsection); + + // Get copy of section + m_info.getCopy(param._section, §ion); } - - // Get copy of section - m_info.getCopy(param._section, §ion); - + // Create pinfo (parameter info) entry Properties pinfo(true); pinfo.put("Id", param._paramId); @@ -2299,6 +2299,7 @@ ConfigInfo::ConfigInfo() // Replace section with modified section m_info.put(param._section, section, true); + delete section; if(param._type != ConfigInfo::CI_SECTION){ Properties * p; diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp index 2505515c086..b9466ed1173 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.cpp +++ b/ndb/src/mgmsrv/MgmtSrvr.cpp @@ -1863,7 +1863,7 @@ MgmtSrvr::handleReceivedSignal(NdbApiSignal* signal) break; case GSN_EVENT_REP: { - EventReport *rep = CAST_PTR(EventReport, signal->getDataPtrSend()); + EventReport *rep = (EventReport*) signal->getDataPtr(); if (rep->getNodeId() == 0) rep->setNodeId(refToNode(signal->theSendersBlockRef)); eventReport(signal->getDataPtr()); diff --git a/regex/regexec.c b/regex/regexec.c index b7ad83ba883..88bcc02323d 100644 --- a/regex/regexec.c +++ b/regex/regexec.c @@ -19,7 +19,7 @@ static int nope = 0; /* for use in asserts; shuts lint up */ /* macros for manipulating states, small version */ #define states long -#define states1 states /* for later use in regexec() decision */ +#define states1 long /* for later use in regexec() decision. Ensure Win64 definition is correct.*/ #define CLEAR(v) ((v) = 0) #define SET0(v, n) ((v) &= ~((states) 1 << (n))) #define SET1(v, n) ((v) |= (states) 1 << (n)) diff --git a/server-tools/instance-manager/guardian.cc b/server-tools/instance-manager/guardian.cc index fa9d877fde6..24844e05776 100644 --- a/server-tools/instance-manager/guardian.cc +++ b/server-tools/instance-manager/guardian.cc @@ -271,10 +271,7 @@ int Guardian_thread::init() { if (!(instance->options.nonguarded)) if (guard(instance, TRUE)) /* do not lock guardian */ - { - instance_map->unlock(); return 1; - } } return 0; diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc index 543c9c31bfa..3b7f58d8a09 100644 --- a/server-tools/instance-manager/instance_map.cc +++ b/server-tools/instance-manager/instance_map.cc @@ -215,7 +215,7 @@ int Instance_map::flush_instances() hash_init(&hash, default_charset_info, START_HASH_SIZE, 0, 0, get_instance_key, delete_instance, 0); rc= load(); - guardian->init(); + guardian->init(); // TODO: check error status. pthread_mutex_unlock(&LOCK_instance_map); guardian->unlock(); return rc; diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc index 00ef50a84e1..353dfcf64dc 100644 --- a/server-tools/instance-manager/manager.cc +++ b/server-tools/instance-manager/manager.cc @@ -147,6 +147,25 @@ void manager(const Options &options) if (create_pid_file(options.pid_file_name, manager_pid)) return; + /* + Initialize signals and alarm-infrastructure. + + NOTE: To work nicely with LinuxThreads, the signal thread is the first + thread in the process. + + NOTE: + After init_thr_alarm() call it's possible to call thr_alarm() (from + different threads), that results in sending ALARM signal to the alarm + thread (which can be the main thread). That signal can interrupt + blocking calls. + + In other words, a blocking call can be interrupted in the main thread + after init_thr_alarm(). + */ + + sigset_t mask; + set_signals(&mask); + /* create guardian thread */ { pthread_t guardian_thd_id; @@ -154,9 +173,16 @@ void manager(const Options &options) int rc; /* - NOTE: Guardian should be shutdown first. Only then all other threads - need to be stopped. This should be done, as guardian is responsible for - shutting down the instances, and this is a long operation. + NOTE: Guardian should be shutdown first. Only then all other threads + need to be stopped. This should be done, as guardian is responsible + for shutting down the instances, and this is a long operation. + + NOTE: Guardian uses thr_alarm() when detects current state of + instances (is_running()), but it is not interfere with + flush_instances() later in the code, because until flush_instances() + complete in the main thread, Guardian thread is not permitted to + process instances. And before flush_instances() there is no instances + to proceed. */ pthread_attr_init(&guardian_thd_attr); @@ -172,10 +198,8 @@ void manager(const Options &options) } - /* - To work nicely with LinuxThreads, the signal thread is the first thread - in the process. - */ + /* Load instances. */ + int signo; bool shutdown_complete; @@ -189,11 +213,6 @@ void manager(const Options &options) return; } - /* Initialize signals and alarm-infrastructure. */ - - sigset_t mask; - set_signals(&mask); - /* create the listener */ { pthread_t listener_thd_id; diff --git a/sql/field.cc b/sql/field.cc index 33fc5ab3128..7c25e4ad9f7 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4566,7 +4566,7 @@ int Field_timestamp::store(const char *from,uint len,CHARSET_INFO *cs) } #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr,tmp); } @@ -4632,7 +4632,7 @@ int Field_timestamp::store(longlong nr, bool unsigned_val) nr, MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr,timestamp); } @@ -4656,7 +4656,7 @@ longlong Field_timestamp::val_int(void) THD *thd= table ? table->in_use : current_thd; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) temp=uint4korr(ptr); else #endif @@ -4686,7 +4686,7 @@ String *Field_timestamp::val_str(String *val_buffer, String *val_ptr) val_buffer->length(field_length); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) temp=uint4korr(ptr); else #endif @@ -4751,7 +4751,7 @@ bool Field_timestamp::get_date(TIME *ltime, uint fuzzydate) long temp; THD *thd= table ? table->in_use : current_thd; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) temp=uint4korr(ptr); else #endif @@ -4788,7 +4788,7 @@ int Field_timestamp::cmp(const char *a_ptr, const char *b_ptr) { int32 a,b; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { a=sint4korr(a_ptr); b=sint4korr(b_ptr); @@ -4806,7 +4806,7 @@ int Field_timestamp::cmp(const char *a_ptr, const char *b_ptr) void Field_timestamp::sort_string(char *to,uint length __attribute__((unused))) { #ifdef WORDS_BIGENDIAN - if (!table->s->db_low_byte_first) + if (!table || !table->s->db_low_byte_first) { to[0] = ptr[0]; to[1] = ptr[1]; @@ -4836,7 +4836,7 @@ void Field_timestamp::set_time() long tmp= (long) thd->query_start(); set_notnull(); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr,tmp); } @@ -5238,7 +5238,7 @@ int Field_date::store(const char *from, uint len,CHARSET_INFO *cs) from, len, MYSQL_TIMESTAMP_DATE, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr,tmp); } @@ -5299,7 +5299,7 @@ int Field_date::store(longlong nr, bool unsigned_val) MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int4store(ptr, nr); } @@ -5325,7 +5325,7 @@ double Field_date::val_real(void) { int32 j; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) j=sint4korr(ptr); else #endif @@ -5338,7 +5338,7 @@ longlong Field_date::val_int(void) { int32 j; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) j=sint4korr(ptr); else #endif @@ -5354,7 +5354,7 @@ String *Field_date::val_str(String *val_buffer, val_buffer->alloc(field_length); int32 tmp; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) tmp=sint4korr(ptr); else #endif @@ -5372,7 +5372,7 @@ int Field_date::cmp(const char *a_ptr, const char *b_ptr) { int32 a,b; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { a=sint4korr(a_ptr); b=sint4korr(b_ptr); @@ -5390,7 +5390,7 @@ int Field_date::cmp(const char *a_ptr, const char *b_ptr) void Field_date::sort_string(char *to,uint length __attribute__((unused))) { #ifdef WORDS_BIGENDIAN - if (!table->s->db_low_byte_first) + if (!table || !table->s->db_low_byte_first) { to[0] = ptr[0]; to[1] = ptr[1]; @@ -5630,7 +5630,7 @@ int Field_datetime::store(const char *from,uint len,CHARSET_INFO *cs) from, len, MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int8store(ptr,tmp); } @@ -5683,7 +5683,7 @@ int Field_datetime::store(longlong nr, bool unsigned_val) MYSQL_TIMESTAMP_DATETIME, 1); #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int8store(ptr,nr); } @@ -5712,7 +5712,7 @@ int Field_datetime::store_time(TIME *ltime,timestamp_type type) set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1); } #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { int8store(ptr,tmp); } @@ -5739,7 +5739,7 @@ longlong Field_datetime::val_int(void) { longlong j; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) j=sint8korr(ptr); else #endif @@ -5759,7 +5759,7 @@ String *Field_datetime::val_str(String *val_buffer, int part3; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) tmp=sint8korr(ptr); else #endif @@ -5824,7 +5824,7 @@ int Field_datetime::cmp(const char *a_ptr, const char *b_ptr) { longlong a,b; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) { a=sint8korr(a_ptr); b=sint8korr(b_ptr); @@ -5842,7 +5842,7 @@ int Field_datetime::cmp(const char *a_ptr, const char *b_ptr) void Field_datetime::sort_string(char *to,uint length __attribute__((unused))) { #ifdef WORDS_BIGENDIAN - if (!table->s->db_low_byte_first) + if (!table || !table->s->db_low_byte_first) { to[0] = ptr[0]; to[1] = ptr[1]; diff --git a/sql/field.h b/sql/field.h index e7b7aa45c27..ed13372df71 100644 --- a/sql/field.h +++ b/sql/field.h @@ -813,7 +813,7 @@ public: if ((*null_value= is_null())) return 0; #ifdef WORDS_BIGENDIAN - if (table->s->db_low_byte_first) + if (table && table->s->db_low_byte_first) return sint4korr(ptr); #endif long tmp; diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 28cdfd23b6a..6aadce0191a 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -6684,6 +6684,17 @@ ha_innobase::store_lock( && !thd->tablespace_op && thd->lex->sql_command != SQLCOM_TRUNCATE && thd->lex->sql_command != SQLCOM_OPTIMIZE +#ifdef __WIN__ + /* + for alter table on win32 for succesfull operation + completion it is used TL_WRITE(=10) lock instead of + TL_WRITE_ALLOW_READ(=6), however here in innodb handler + TL_WRITE is lifted to TL_WRITE_ALLOW_WRITE, which causes + race condition when several clients do alter table + simultaneously (bug #17264). This fix avoids the problem. + */ + && thd->lex->sql_command != SQLCOM_ALTER_TABLE +#endif && thd->lex->sql_command != SQLCOM_CREATE_TABLE) { lock_type = TL_WRITE_ALLOW_WRITE; diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 15a05fe7050..80cf756d852 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -80,9 +80,6 @@ static void agg_result_type(Item_result *type, Item **items, uint nitems) NOTES Aggregation rules: - If all items are constants the type will be aggregated from all items. - If there are some non-constant items then only types of non-constant - items will be used for aggregation. If there are DATE/TIME fields/functions in the list and no string fields/functions in the list then: The INT_RESULT type will be used for aggregation instead of original @@ -141,7 +138,8 @@ static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems) } continue; } - if ((res= items[i]->real_item()->type()) == Item::FIELD_ITEM) + if ((res= items[i]->real_item()->type()) == Item::FIELD_ITEM && + items[i]->result_type() != INT_RESULT) { field= ((Item_field *)items[i]->real_item())->field; break; @@ -169,34 +167,29 @@ static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems) } } } - /* Reset to 0 on first occurence of non-const item. 1 otherwise */ - bool is_const= items[0]->const_item(); /* If the first item is a date/time function then its result should be compared as int */ if (field) - { - /* Suppose we are comparing dates and some non-constant items are present. */ + /* Suppose we are comparing dates */ type[0]= INT_RESULT; - is_const= 0; - } else type[0]= items[0]->result_type(); for (i= 0; i < nitems ; i++) { - if (!items[i]->const_item()) - { - Item_result result= field && items[i]->result_as_longlong() ? - INT_RESULT : items[i]->result_type(); - type[0]= is_const ? result : item_cmp_type(type[0], result); - is_const= 0; - } - else if (is_const) - type[0]= item_cmp_type(type[0], items[i]->result_type()); - else if (field) - convert_constant_item(thd, field, &items[i]); + Item_result result= items[i]->result_type(); + /* + Use INT_RESULT as result type for DATE/TIME fields/functions and + for constants successfully converted to DATE/TIME + */ + if (field && + ((!items[i]->const_item() && items[i]->result_as_longlong()) || + (items[i]->const_item() && convert_constant_item(thd, field, + &items[i])))) + result= INT_RESULT; + type[0]= item_cmp_type(type[0], result); } if (res == Item::FUNC_ITEM && field) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index ae5e85ca15f..d7a38d6b715 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5872,7 +5872,8 @@ The minimum value for this variable is 4096.", "Each thread that does a sequential scan allocates a buffer of this size for each table it scans. If you do many sequential scans, you may want to increase this value.", (gptr*) &global_system_variables.read_buff_size, (gptr*) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG, - 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ~0L, MALLOC_OVERHEAD, IO_SIZE, 0}, + 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, SSIZE_MAX, MALLOC_OVERHEAD, IO_SIZE, + 0}, {"read_only", OPT_READONLY, "Make all non-temporary tables read-only, with the exception for replication (slave) threads and users with the SUPER privilege", (gptr*) &opt_readonly, @@ -5883,12 +5884,12 @@ The minimum value for this variable is 4096.", (gptr*) &global_system_variables.read_rnd_buff_size, (gptr*) &max_system_variables.read_rnd_buff_size, 0, GET_ULONG, REQUIRED_ARG, 256*1024L, IO_SIZE*2+MALLOC_OVERHEAD, - ~0L, MALLOC_OVERHEAD, IO_SIZE, 0}, + SSIZE_MAX, MALLOC_OVERHEAD, IO_SIZE, 0}, {"record_buffer", OPT_RECORD_BUFFER, "Alias for read_buffer_size", (gptr*) &global_system_variables.read_buff_size, (gptr*) &max_system_variables.read_buff_size,0, GET_ULONG, REQUIRED_ARG, - 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, ~0L, MALLOC_OVERHEAD, IO_SIZE, 0}, + 128*1024L, IO_SIZE*2+MALLOC_OVERHEAD, SSIZE_MAX, MALLOC_OVERHEAD, IO_SIZE, 0}, #ifdef HAVE_REPLICATION {"relay_log_purge", OPT_RELAY_LOG_PURGE, "0 = do not purge relay logs. 1 = purge them as soon as they are no more needed.", diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 5630702fe52..8ffc6f53a43 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1057,16 +1057,19 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) to convert the latter operation internally to an UPDATE. We also should not perform this conversion if we have timestamp field with ON UPDATE which is different from DEFAULT. + Another case when conversion should not be performed is when + we have ON DELETE trigger on table so user may notice that + we cheat here. Note that it is ok to do such conversion for + tables which have ON UPDATE but have no ON DELETE triggers, + we just should not expose this fact to users by invoking + ON UPDATE triggers. */ if (last_uniq_key(table,key_nr) && !table->file->referenced_by_foreign_key() && (table->timestamp_field_type == TIMESTAMP_NO_AUTO_SET || - table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH)) + table->timestamp_field_type == TIMESTAMP_AUTO_SET_ON_BOTH) && + (!table->triggers || !table->triggers->has_delete_triggers())) { - if (table->triggers && - table->triggers->process_triggers(thd, TRG_EVENT_UPDATE, - TRG_ACTION_BEFORE, TRUE)) - goto before_trg_err; if (thd->clear_next_insert_id) { /* Reset auto-increment cacheing if we do an update */ @@ -1077,13 +1080,11 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) table->record[0]))) goto err; info->deleted++; - trg_error= (table->triggers && - table->triggers->process_triggers(thd, TRG_EVENT_UPDATE, - TRG_ACTION_AFTER, - TRUE)); - /* Update logfile and count */ - info->copied++; - goto ok_or_after_trg_err; + /* + Since we pretend that we have done insert we should call + its after triggers. + */ + goto after_trg_n_copied_inc; } else { @@ -1107,10 +1108,6 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) } } } - info->copied++; - trg_error= (table->triggers && - table->triggers->process_triggers(thd, TRG_EVENT_INSERT, - TRG_ACTION_AFTER, TRUE)); } else if ((error=table->file->write_row(table->record[0]))) { @@ -1118,14 +1115,14 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) (error != HA_ERR_FOUND_DUPP_KEY && error != HA_ERR_FOUND_DUPP_UNIQUE)) goto err; table->file->restore_auto_increment(); + goto ok_or_after_trg_err; } - else - { - info->copied++; - trg_error= (table->triggers && - table->triggers->process_triggers(thd, TRG_EVENT_INSERT, - TRG_ACTION_AFTER, TRUE)); - } + +after_trg_n_copied_inc: + info->copied++; + trg_error= (table->triggers && + table->triggers->process_triggers(thd, TRG_EVENT_INSERT, + TRG_ACTION_AFTER, TRUE)); ok_or_after_trg_err: if (key) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index fe4993fddbf..9f317842d98 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -8834,6 +8834,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List &fields, null_pack_length-=hidden_null_pack_length; keyinfo->key_parts= ((field_count-param->hidden_field_count)+ test(null_pack_length)); + set_if_smaller(table->s->max_rows, rows_limit); + param->end_write_records= rows_limit; table->distinct= 1; table->s->keys= 1; if (blob_count) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index b4ae779f9e2..c2b7624c9e7 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -859,7 +859,12 @@ reopen_tables: } } } - + /* + Set exclude_from_table_unique_test value back to FALSE. It is needed for + further check in multi_update::prepare whether to use record cache. + */ + lex->select_lex.exclude_from_table_unique_test= FALSE; + if (thd->fill_derived_tables() && mysql_handle_derived(lex, &mysql_derived_filling)) DBUG_RETURN(TRUE); @@ -1038,7 +1043,7 @@ int multi_update::prepare(List ¬_used_values, for (table_ref= leaves; table_ref; table_ref= table_ref->next_leaf) { TABLE *table=table_ref->table; - if (!(tables_to_update & table->map) && + if ((tables_to_update & table->map) && unique_table(thd, table_ref, update_tables)) table->no_cache= 1; // Disable row cache }