diff options
361 files changed, 16796 insertions, 6592 deletions
diff --git a/.bzrignore b/.bzrignore index 6abf5d3eb8b..9c9121c5dc5 100644 --- a/.bzrignore +++ b/.bzrignore @@ -567,8 +567,10 @@ heap/hp_test2 help help.c help.h +include/check_abi include/my_config.h include/my_global.h +include/mysql_h.ic include/mysql_version.h include/mysqld_ername.h include/mysqld_error.h @@ -1260,6 +1262,7 @@ mysql-test/r/bdb-deadlock.err mysql-test/r/bdb.err mysql-test/r/bdb.log mysql-test/r/bdb_cache.err +mysql-test/r/blackhole.log mysql-test/r/client_test.err mysql-test/r/csv.err mysql-test/r/ctype_ucs.err diff --git a/BitKeeper/etc/collapsed b/BitKeeper/etc/collapsed index dd7fddf1de3..1a7ce408cf3 100644 --- a/BitKeeper/etc/collapsed +++ b/BitKeeper/etc/collapsed @@ -5,7 +5,15 @@ 45001f7c3b2hhCXDKfUvzkX9TNe6VA 45002051rHJfMEXAIMiAZV0clxvKSA 4513d8e4Af4dQWuk13sArwofRgFDQw +45143312u0Tz4r0wPXCbUKwdHa2jWA +45143b90ewOQuTW8-jrB3ZSAQvMRJw +45184588w9U72A6KX1hUFeAC4shSHA +45185df8mZbxfp85FbA0VxUXkmDewA 4519a6c5BVUxEHTf5iJnjZkixMBs8g 451ab499rgdjXyOnUDqHu-wBDoS-OQ +451b110a3ZV6MITl93ehXk2wxrbW7g +45214442pBGT9KuZEGixBH71jTzbOA +45214a07hVsIGwvwa-WrO-jpeaSwVw +452a92d0-31-8wSzSfZi165fcGcXPA 452c6c6dAjuNghfc1ObZ_UQ5SCl85g 4538a7b0EbDHHkWPbIwxO6ZIDdg6Dg diff --git a/BitKeeper/triggers/pre-outgoing.crash-protect.pl b/BitKeeper/triggers/pre-outgoing.crash-protect.pl index bbaa092e335..80567012c0f 100755 --- a/BitKeeper/triggers/pre-outgoing.crash-protect.pl +++ b/BitKeeper/triggers/pre-outgoing.crash-protect.pl @@ -9,8 +9,6 @@ unless($event eq 'outgoing pull' || $event eq 'outgoing push' || exit 0; } -print "Checking for bad changesets from old crashed 5.1 tree...\n"; - my @bad_csets= ( 'monty@mysql.com|ChangeSet|20060418090255|16983', 'monty@mysql.com|ChangeSet|20060418090458|02628', @@ -80,6 +78,4 @@ END } } -print "No bad changesets found, proceeding.\n"; - exit 0; diff --git a/BitKeeper/triggers/pre-resolve.crash-protect.pl b/BitKeeper/triggers/pre-resolve.crash-protect.pl index bbaa092e335..80567012c0f 100755 --- a/BitKeeper/triggers/pre-resolve.crash-protect.pl +++ b/BitKeeper/triggers/pre-resolve.crash-protect.pl @@ -9,8 +9,6 @@ unless($event eq 'outgoing pull' || $event eq 'outgoing push' || exit 0; } -print "Checking for bad changesets from old crashed 5.1 tree...\n"; - my @bad_csets= ( 'monty@mysql.com|ChangeSet|20060418090255|16983', 'monty@mysql.com|ChangeSet|20060418090458|02628', @@ -80,6 +78,4 @@ END } } -print "No bad changesets found, proceeding.\n"; - exit 0; diff --git a/Docs/Makefile.am b/Docs/Makefile.am index 40e987bb254..09291132e73 100644 --- a/Docs/Makefile.am +++ b/Docs/Makefile.am @@ -66,7 +66,7 @@ INSTALL-BINARY: mysql.info $(GT) # It is not in BitKeeper, but is downloaded from intranet by Bootstrap. dist-hook: if [ -e $(srcdir)/manual.chm ] ; then \ - cp $(srcdir)/manual.chm $(distdir); \ + cp -f $(srcdir)/manual.chm $(distdir); \ fi # Don't update the files from bitkeeper diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 26cc36c7f6f..b2b734a48f4 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -65,6 +65,9 @@ TARGET_LINK_LIBRARIES(mysqldump mysqlclient mysys dbug yassl taocrypt zlib wsock ADD_EXECUTABLE(mysqlimport mysqlimport.c) TARGET_LINK_LIBRARIES(mysqlimport mysqlclient mysys dbug yassl taocrypt zlib wsock32) +ADD_EXECUTABLE(mysql_upgrade mysql_upgrade.c) +TARGET_LINK_LIBRARIES(mysql_upgrade mysqlclient mysys dbug yassl taocrypt zlib wsock32) + ADD_EXECUTABLE(mysqlshow mysqlshow.c) TARGET_LINK_LIBRARIES(mysqlshow mysqlclient mysys dbug yassl taocrypt zlib wsock32) diff --git a/client/Makefile.am b/client/Makefile.am index d3e96dd126f..7d48e34b37b 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -46,7 +46,8 @@ mysqladmin_SOURCES = mysqladmin.cc mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) $(CXXLDFLAGS) mysqltest_SOURCES= mysqltest.c $(top_srcdir)/mysys/my_getsystime.c \ $(yassl_dummy_link_fix) -mysqltest_LDADD = $(top_builddir)/regex/libregex.a $(LDADD) +mysqltest_LDADD = $(top_builddir)/regex/libregex.a $(LDADD) \ + $(top_builddir)/mysys/libmysys.a mysqlbinlog_SOURCES = mysqlbinlog.cc $(top_srcdir)/mysys/mf_tempdir.c \ $(top_srcdir)/mysys/my_new.cc \ $(top_srcdir)/mysys/my_bit.c \ diff --git a/client/mysql.cc b/client/mysql.cc index 1dbdeb8be97..486e5bc113c 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -386,6 +386,21 @@ int main(int argc,char *argv[]) else status.add_to_history=1; status.exit_status=1; + + { + /* + The file descriptor-layer may be out-of-sync with the file-number layer, + so we make sure that "stdout" is really open. If its file is closed then + explicitly close the FD layer. + */ + int stdout_fileno_copy; + stdout_fileno_copy= dup(fileno(stdout)); /* Okay if fileno fails. */ + if (stdout_fileno_copy == -1) + fclose(stdout); + else + close(stdout_fileno_copy); /* Clean up dup(). */ + } + load_defaults("my",load_default_groups,&argc,&argv); defaults_argv=argv; if (get_options(argc, (char **) argv)) @@ -2091,6 +2106,8 @@ com_go(String *buffer,char *line __attribute__((unused))) (long) mysql_num_rows(result), (long) mysql_num_rows(result) == 1 ? "row" : "rows"); end_pager(); + if (mysql_errno(&mysql)) + error= put_error(&mysql); } } else if (mysql_affected_rows(&mysql) == ~(ulonglong) 0) @@ -2905,7 +2922,11 @@ com_connect(String *buffer, char *line) bzero(buff, sizeof(buff)); if (buffer) { - strmake(buff, line, sizeof(buff) - 1); + /* + Two null bytes are needed in the end of buff to allow + get_arg to find end of string the second time it's called. + */ + strmake(buff, line, sizeof(buff)-2); tmp= get_arg(buff, 0); if (tmp && *tmp) { diff --git a/client/mysqldump.c b/client/mysqldump.c index 2d2961e465c..992f20db6b6 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -45,6 +45,7 @@ #include <m_string.h> #include <m_ctype.h> #include <hash.h> +#include <stdarg.h> #include "client_priv.h" #include "mysql.h" @@ -536,6 +537,8 @@ static void write_header(FILE *sql_file, char *db_name) if (opt_xml) { fputs("<?xml version=\"1.0\"?>\n", sql_file); + /* Schema reference. Allows use of xsi:nil for NULL values and + xsi:type to define an element's data type. */ fputs("<mysqldump ", sql_file); fputs("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", sql_file); @@ -1136,7 +1139,7 @@ static char *quote_for_like(const char *name, char *buff) SYNOPSIS print_quoted_xml() - output - output file + xml_file - output file str - string to print len - its length @@ -1173,34 +1176,63 @@ static void print_quoted_xml(FILE *xml_file, const char *str, ulong len) /* - Print xml tag with one attribute. + Print xml tag. Optionally add attribute(s). SYNOPSIS - print_xml_tag1() - xml_file - output file - sbeg - line beginning - stag_atr - tag and attribute - sval - value of attribute - send - line ending + print_xml_tag(xml_file, sbeg, send, tag_name, first_attribute_name, + ..., attribute_name_n, attribute_value_n, NullS) + xml_file - output file + sbeg - line beginning + send - line ending + tag_name - XML tag name. + first_attribute_name - tag and first attribute + first_attribute_value - (Implied) value of first attribute + attribute_name_n - attribute n + attribute_value_n - value of attribute n DESCRIPTION - Print tag with one attribute to the xml_file. Format is: - sbeg<stag_atr="sval">send + Print XML tag with any number of attribute="value" pairs to the xml_file. + + Format is: + sbeg<tag_name first_attribute_name="first_attribute_value" ... + attribute_name_n="attribute_value_n">send NOTE - sval MUST be a NULL terminated string. - sval string will be qouted before output. + Additional arguments must be present in attribute/value pairs. + The last argument should be the null character pointer. + All attribute_value arguments MUST be NULL terminated strings. + All attribute_value arguments will be quoted before output. */ -static void print_xml_tag1(FILE * xml_file, const char* sbeg, - const char* stag_atr, const char* sval, - const char* send) +static void print_xml_tag(FILE * xml_file, const char* sbeg, const char* send, + const char* tag_name, + const char* first_attribute_name, ...) { + va_list arg_list; + const char *attribute_name, *attribute_value; + fputs(sbeg, xml_file); - fputs("<", xml_file); - fputs(stag_atr, xml_file); - fputs("\"", xml_file); - print_quoted_xml(xml_file, sval, strlen(sval)); - fputs("\">", xml_file); + fputc('<', xml_file); + fputs(tag_name, xml_file); + + va_start(arg_list, first_attribute_name); + attribute_name= first_attribute_name; + while (attribute_name != NullS) + { + attribute_value= va_arg(arg_list, char *); + DBUG_ASSERT(attribute_value != NullS); + + fputc(' ', xml_file); + fputs(attribute_name, xml_file); + fputc('\"', xml_file); + + print_quoted_xml(xml_file, attribute_value, strlen(attribute_value)); + fputc('\"', xml_file); + + attribute_name= va_arg(arg_list, char *); + } + va_end(arg_list); + + fputc('>', xml_file); fputs(send, xml_file); check_io(xml_file); } @@ -1411,6 +1443,28 @@ static uint dump_events_for_db(char *db) /* + Print hex value for blob data. + + SYNOPSIS + print_blob_as_hex() + output_file - output file + str - string to print + len - its length + + DESCRIPTION + Print hex value for blob data. +*/ + +static void print_blob_as_hex(FILE *output_file, const char *str, ulong len) +{ + /* sakaik got the idea to to provide blob's in hex notation. */ + const char *ptr= str, *end= ptr + len; + for (; ptr < end ; ptr++) + fprintf(output_file, "%02X", *((uchar *)ptr)); + check_io(output_file); +} + +/* dump_routines_for_db -- retrieves list of routines for a given db, and prints out the CREATE PROCEDURE definition into the output (the dump). @@ -1857,7 +1911,8 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (!opt_xml) fprintf(sql_file, "CREATE TABLE %s (\n", result_table); else - print_xml_tag1(sql_file, "\t", "table_structure name=", table, "\n"); + print_xml_tag(sql_file, "\t", "\n", "table_structure", "name=", table, + NullS); check_io(sql_file); } @@ -2429,8 +2484,8 @@ static void dump_table(char *table, char *db) rownr=0; init_length=(uint) insert_pat.length+4; if (opt_xml) - print_xml_tag1(md_result_file, "\t", "table_data name=", table, "\n"); - + print_xml_tag(md_result_file, "\t", "\n", "table_data", "name=", table, + NullS); if (opt_autocommit) { fprintf(md_result_file, "set autocommit=0;\n"); @@ -2484,7 +2539,7 @@ 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 (extended_insert && !opt_xml) { if (i == 0) dynstr_set(&extended_row,"("); @@ -2573,18 +2628,25 @@ static void dump_table(char *table, char *db) { if (opt_xml) { - print_xml_tag1(md_result_file, "\t\t", "field name=", - field->name, ""); - print_quoted_xml(md_result_file, row[i], length); + if (opt_hex_blob && is_blob && length) + { + /* Define xsi:type="xs:hexBinary" for hex encoded data */ + print_xml_tag(md_result_file, "\t\t", "", "field", "name=", + field->name, "xsi:type=", "xs:hexBinary", NullS); + print_blob_as_hex(md_result_file, row[i], length); + } + else + { + print_xml_tag(md_result_file, "\t\t", "", "field", "name=", + field->name, NullS); + print_quoted_xml(md_result_file, row[i], length); + } fputs("</field>\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)); + print_blob_as_hex(md_result_file, row[i], length); } else unescape(md_result_file, row[i], length); @@ -2595,8 +2657,8 @@ static void dump_table(char *table, char *db) char *ptr= row[i]; if (opt_xml) { - print_xml_tag1(md_result_file, "\t\t", "field name=", - field->name, ""); + print_xml_tag(md_result_file, "\t\t", "", "field", "name=", + field->name, NullS); fputs(!my_isalpha(charset_info, *ptr) ? ptr: "NULL", md_result_file); fputs("</field>\n", md_result_file); @@ -3070,7 +3132,7 @@ static int dump_all_tables_in_db(char *database) if (init_dumping(database, init_dumping_tables)) return 1; if (opt_xml) - print_xml_tag1(md_result_file, "", "database name=", database, "\n"); + print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS); if (lock_tables) { DYNAMIC_STRING query; @@ -3153,7 +3215,7 @@ static my_bool dump_all_views_in_db(char *database) if (init_dumping(database, init_dumping_views)) return 1; if (opt_xml) - print_xml_tag1(md_result_file, "", "database name=", database, "\n"); + print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS); if (lock_tables) { DYNAMIC_STRING query; @@ -3292,7 +3354,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) /* We shall countinue here, if --force was given */ } if (opt_xml) - print_xml_tag1(md_result_file, "", "database name=", db, "\n"); + print_xml_tag(md_result_file, "", "\n", "database", "name=", db, NullS); /* Dump each selected table */ for (pos= dump_tables; pos < end; pos++) @@ -3405,7 +3467,7 @@ static int do_reset_master(MYSQL *mysql_con) } -static int start_transaction(MYSQL *mysql_con, my_bool consistent_read_now) +static int start_transaction(MYSQL *mysql_con) { /* We use BEGIN for old servers. --single-transaction --master-data will fail @@ -3420,10 +3482,8 @@ static int start_transaction(MYSQL *mysql_con, my_bool consistent_read_now) "SET SESSION TRANSACTION ISOLATION " "LEVEL REPEATABLE READ") || mysql_query_with_error_report(mysql_con, 0, - consistent_read_now ? "START TRANSACTION " - "WITH CONSISTENT SNAPSHOT" : - "BEGIN")); + "/*!40100 WITH CONSISTENT SNAPSHOT */")); } @@ -3913,7 +3973,7 @@ int main(int argc, char **argv) if ((opt_lock_all_tables || opt_master_data) && do_flush_tables_read_lock(mysql)) goto err; - if (opt_single_transaction && start_transaction(mysql, test(opt_master_data))) + if (opt_single_transaction && start_transaction(mysql)) goto err; if (opt_delete_master_logs && do_reset_master(mysql)) goto err; diff --git a/client/mysqltest.c b/client/mysqltest.c index f9c4ae617fd..aeb86575333 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -14,35 +14,24 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* mysqltest test tool - * See the manual for more information - * TODO: document better how mysqltest works - * - * Written by: - * Sasha Pachev <sasha@mysql.com> - * Matt Wagner <matt@mysql.com> - * Monty - * Jani - **/ - -/********************************************************************** - TODO: +/* + mysqltest -- Do comparison line by line, instead of doing a full comparison of - the text file. This will save space as we don't need to keep many - results in memory. It will also make it possible to do simple - 'comparison' fixes like accepting the result even if a float differed - in the last decimals. + Tool used for executing a .test file -- Don't buffer lines from the test that you don't expect to need - again. + See the "MySQL Test framework manual" for more information + http://dev.mysql.com/doc/mysqltest/en/index.html -- Change 'read_line' to be faster by using the readline.cc code; - We can do better than calling feof() for each character! + Please keep the test framework tools identical in all versions! -**********************************************************************/ + Written by: + Sasha Pachev <sasha@mysql.com> + Matt Wagner <matt@mysql.com> + Monty + Jani +*/ -#define MTEST_VERSION "2.6" +#define MTEST_VERSION "3.0" #include <my_global.h> #include <mysql_embed.h> @@ -51,18 +40,18 @@ #include <mysql.h> #include <mysql_version.h> #include <mysqld_error.h> +#include <errmsg.h> #include <m_ctype.h> #include <my_dir.h> -#include <errmsg.h> /* Error codes */ #include <hash.h> #include <my_getopt.h> #include <stdarg.h> -#include <sys/stat.h> #include <violite.h> -#include "my_regex.h" /* Our own version of lib */ +#include "my_regex.h" /* Our own version of regex */ #ifdef HAVE_SYS_WAIT_H #include <sys/wait.h> #endif + #ifndef WEXITSTATUS # ifdef __WIN__ # define WEXITSTATUS(stat_val) (stat_val) @@ -70,169 +59,116 @@ # define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8) # endif #endif -/* MAX_QUERY is 256K -- there is a test in sp-big that is >128K */ -#define MAX_QUERY (256*1024) -#define MAX_VAR_NAME 256 -#define MAX_COLUMNS 256 -#define MAX_CONS 128 -#define MAX_INCLUDE_DEPTH 16 -#define INIT_Q_LINES 1024 -#define MIN_VAR_ALLOC 32 -#define BLOCK_STACK_DEPTH 32 -#define MAX_EXPECTED_ERRORS 10 -#define QUERY_SEND 1 -#define QUERY_REAP 2 -#define MAX_SERVER_ARGS 64 - - -#define SLAVE_POLL_INTERVAL 300000 /* 0.3 of a sec */ -#define DEFAULT_DELIMITER ";" -#define MAX_DELIMITER 16 - -#define RESULT_OK 0 -#define RESULT_CONTENT_MISMATCH 1 -#define RESULT_LENGTH_MISMATCH 2 - -enum {OPT_SKIP_SAFEMALLOC=256, OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, - OPT_SSL_CA, OPT_SSL_CAPATH, OPT_SSL_CIPHER, OPT_PS_PROTOCOL, - OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL, - OPT_SSL_VERIFY_SERVER_CERT, OPT_MAX_CONNECT_RETRIES, - OPT_MARK_PROGRESS}; - -/* ************************************************************************ */ -/* - The list of error codes to --error are stored in an internal array of - structs. This struct can hold numeric SQL error codes or SQLSTATE codes - as strings. The element next to the last active element in the list is - set to type ERR_EMPTY. When an SQL statement returns an error, we use - this list to check if this is an expected error. -*/ - -enum match_err_type -{ - ERR_EMPTY= 0, - ERR_ERRNO, - ERR_SQLSTATE -}; - -typedef struct -{ - enum match_err_type type; - union - { - uint errnum; - char sqlstate[SQLSTATE_LENGTH+1]; /* \0 terminated string */ - } code; -} match_err; - -typedef struct -{ - const char *name; - long code; -} st_error; -static st_error global_error[] = -{ -#include <mysqld_ername.h> - { 0, 0 } +#define MAX_VAR_NAME_LENGTH 256 +#define MAX_COLUMNS 256 +#define MAX_EMBEDDED_SERVER_ARGS 64 +#define MAX_DELIMITER_LENGTH 16 + +/* Flags controlling send and reap */ +#define QUERY_SEND_FLAG 1 +#define QUERY_REAP_FLAG 2 + + enum { + RESULT_OK= 0, + RESULT_CONTENT_MISMATCH= 1, + RESULT_LENGTH_MISMATCH= 2 + }; + +enum { + OPT_SKIP_SAFEMALLOC=256, OPT_SSL_SSL, OPT_SSL_KEY, OPT_SSL_CERT, + OPT_SSL_CA, OPT_SSL_CAPATH, OPT_SSL_CIPHER, OPT_PS_PROTOCOL, + OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL, + OPT_SSL_VERIFY_SERVER_CERT, OPT_MAX_CONNECT_RETRIES, + OPT_MARK_PROGRESS }; -static match_err global_expected_errno[MAX_EXPECTED_ERRORS]; -static uint global_expected_errors; - -/* ************************************************************************ */ - static int record= 0, opt_sleep= -1; -static char *db = 0, *pass=0; -const char *user = 0, *host = 0, *unix_sock = 0, *opt_basedir="./"; +static char *db= 0, *pass= 0; +const char *user= 0, *host= 0, *unix_sock= 0, *opt_basedir= "./"; const char *opt_include= 0; -static int port = 0; +static int port= 0; static int opt_max_connect_retries; -static my_bool opt_big_test= 0, opt_compress= 0, silent= 0, verbose = 0; +static my_bool opt_compress= 0, silent= 0, verbose= 0; static my_bool tty_password= 0; static my_bool opt_mark_progress= 0; static my_bool ps_protocol= 0, ps_protocol_enabled= 0; static my_bool sp_protocol= 0, sp_protocol_enabled= 0; static my_bool view_protocol= 0, view_protocol_enabled= 0; static my_bool cursor_protocol= 0, cursor_protocol_enabled= 0; -static my_bool opt_valgrind_test= 0; -static int parsing_disabled= 0; +static my_bool parsing_disabled= 0; +static my_bool display_result_vertically= FALSE, display_metadata= FALSE; +static my_bool disable_query_log= 0, disable_result_log= 0; +static my_bool disable_warnings= 0, disable_ps_warnings= 0; +static my_bool disable_info= 1; +static my_bool abort_on_error= 1; static char **default_argv; -static const char *load_default_groups[]= { "mysqltest","client",0 }; -static char line_buffer[MAX_DELIMITER], *line_buffer_pos= line_buffer; +static const char *load_default_groups[]= { "mysqltest", "client", 0 }; +static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer; -typedef struct -{ - FILE* file; - const char *file_name; - uint lineno; /* Current line in file */ -} test_file; +static uint start_lineno= 0; /* Start line of current command */ + +static char delimiter[MAX_DELIMITER_LENGTH]= ";"; +static uint delimiter_length= 1; -static test_file file_stack[MAX_INCLUDE_DEPTH]; -static test_file* cur_file; -static test_file* file_stack_end; -uint start_lineno= 0; /* Start line of query */ +static char TMPDIR[FN_REFLEN]; -/* Stores regex substitutions */ +/* Block stack */ +enum block_cmd { + cmd_none, + cmd_if, + cmd_while +}; -struct st_regex +struct st_block { - char* pattern; /* Pattern to be replaced */ - char* replace; /* String or expression to replace the pattern with */ - int icase; /* true if the match is case insensitive */ + int line; /* Start line of block */ + my_bool ok; /* Should block be executed */ + enum block_cmd cmd; /* Command owning the block */ }; -struct st_replace_regex +static struct st_block block_stack[32]; +static struct st_block *cur_block, *block_stack_end; + +/* Open file stack */ +struct st_test_file { - DYNAMIC_ARRAY regex_arr; /* stores a list of st_regex subsitutions */ - - /* - Temporary storage areas for substitutions. To reduce unnessary copying - and memory freeing/allocation, we pre-allocate two buffers, and alternate - their use, one for input/one for output, the roles changing on the next - st_regex substition. At the end of substitutions buf points to the - one containing the final result. - */ - char* buf; - char* even_buf; - char* odd_buf; - int even_buf_len; - int odd_buf_len; + FILE* file; + const char *file_name; + uint lineno; /* Current line in file */ }; -struct st_replace_regex *glob_replace_regex= 0; - -static char TMPDIR[FN_REFLEN]; -static char delimiter[MAX_DELIMITER]= DEFAULT_DELIMITER; -static uint delimiter_length= 1; +static struct st_test_file file_stack[16]; +static struct st_test_file* cur_file; +static struct st_test_file* file_stack_end; -/* Block stack */ -enum block_cmd { cmd_none, cmd_if, cmd_while }; -typedef struct -{ - int line; /* Start line of block */ - my_bool ok; /* Should block be executed */ - enum block_cmd cmd; /* Command owning the block */ -} BLOCK; -static BLOCK block_stack[BLOCK_STACK_DEPTH]; -static BLOCK *cur_block, *block_stack_end; static CHARSET_INFO *charset_info= &my_charset_latin1; /* Default charset */ static const char *charset_name= "latin1"; /* Default character set name */ -static int embedded_server_arg_count=0; -static char *embedded_server_args[MAX_SERVER_ARGS]; +static const char *embedded_server_groups[]= +{ + "server", + "embedded", + "mysqltest_SERVER", + NullS +}; -static my_bool display_result_vertically= FALSE, display_metadata= FALSE; +static int embedded_server_arg_count=0; +static char *embedded_server_args[MAX_EMBEDDED_SERVER_ARGS]; -/* See the timer_output() definition for details */ +/* + Timer related variables + See the timer_output() definition for details +*/ static char *timer_file = NULL; -static ulonglong timer_start, progress_start= 0; -static int got_end_timer= FALSE; +static ulonglong timer_start; static void timer_output(void); static ulonglong timer_now(void); +static ulonglong progress_start= 0; + /* Precompiled re's */ static my_regex_t ps_re; /* the query can be run using PS protocol */ static my_regex_t sp_re; /* the query can be run as a SP */ @@ -242,47 +178,25 @@ static void init_re(void); static int match_re(my_regex_t *, char *); static void free_re(void); -static int reg_replace(char** buf_p, int* buf_len_p, char *pattern, char *replace, - char *string, int icase); - -static const char *embedded_server_groups[]= -{ - "server", - "embedded", - "mysqltest_SERVER", - NullS -}; - DYNAMIC_ARRAY q_lines; #include "sslopt-vars.h" -typedef struct -{ - char file[FN_REFLEN]; - ulong pos; -} MASTER_POS ; - -struct connection +struct { - MYSQL mysql; - /* Used when creating views and sp, to avoid implicit commit */ - MYSQL* util_mysql; - char *name; - MYSQL_STMT* stmt; -}; + int read_lines,current_line; +} parser; -typedef struct +struct { - int read_lines,current_line; -} PARSER; + char file[FN_REFLEN]; + ulong pos; +} master_pos; -PARSER parser; -MASTER_POS master_pos; /* if set, all results are concated and compared against this file */ -const char *result_file = 0; +const char *result_file_name= 0; -typedef struct +typedef struct st_var { char *name; int name_len; @@ -295,70 +209,68 @@ typedef struct char *env_s; } VAR; -VAR var_reg[10]; /*Perl/shell-like variable registers */ -HASH var_hash; -my_bool disable_query_log=0, disable_result_log=0, disable_warnings=0; -my_bool disable_ps_warnings= 0; -my_bool disable_info= 1; /* By default off */ -my_bool abort_on_error= 1; +VAR var_reg[10]; -struct connection cons[MAX_CONS]; -struct connection* cur_con, *next_con, *cons_end; +HASH var_hash; - /* Add new commands before Q_UNKNOWN !*/ +struct st_connection +{ + MYSQL mysql; + /* Used when creating views and sp, to avoid implicit commit */ + MYSQL* util_mysql; + char *name; + MYSQL_STMT* stmt; +}; +struct st_connection connections[128]; +struct st_connection* cur_con, *next_con, *connections_end; +/* + List of commands in mysqltest + Must match the "command_names" array + Add new commands before Q_UNKNOWN! +*/ enum enum_commands { -Q_CONNECTION=1, Q_QUERY, -Q_CONNECT, Q_SLEEP, Q_REAL_SLEEP, -Q_INC, Q_DEC, -Q_SOURCE, Q_DISCONNECT, -Q_LET, Q_ECHO, -Q_WHILE, Q_END_BLOCK, -Q_SYSTEM, Q_RESULT, -Q_REQUIRE, Q_SAVE_MASTER_POS, -Q_SYNC_WITH_MASTER, -Q_SYNC_SLAVE_WITH_MASTER, -Q_ERROR, -Q_SEND, Q_REAP, -Q_DIRTY_CLOSE, Q_REPLACE, Q_REPLACE_COLUMN, -Q_PING, Q_EVAL, -Q_RPL_PROBE, Q_ENABLE_RPL_PARSE, -Q_DISABLE_RPL_PARSE, Q_EVAL_RESULT, -Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG, -Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG, -Q_WAIT_FOR_SLAVE_TO_STOP, -Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS, -Q_ENABLE_PS_WARNINGS, Q_DISABLE_PS_WARNINGS, -Q_ENABLE_INFO, Q_DISABLE_INFO, -Q_ENABLE_METADATA, Q_DISABLE_METADATA, -Q_EXEC, Q_DELIMITER, -Q_DISABLE_ABORT_ON_ERROR, Q_ENABLE_ABORT_ON_ERROR, -Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS, -Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, -Q_START_TIMER, Q_END_TIMER, -Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL, -Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT, -Q_IF, -Q_DISABLE_PARSING, Q_ENABLE_PARSING, -Q_REPLACE_REGEX, Q_DIE, - -Q_UNKNOWN, /* Unknown command. */ -Q_COMMENT, /* Comments, ignored. */ -Q_COMMENT_WITH_COMMAND + Q_CONNECTION=1, Q_QUERY, + Q_CONNECT, Q_SLEEP, Q_REAL_SLEEP, + Q_INC, Q_DEC, + Q_SOURCE, Q_DISCONNECT, + Q_LET, Q_ECHO, + Q_WHILE, Q_END_BLOCK, + Q_SYSTEM, Q_RESULT, + Q_REQUIRE, Q_SAVE_MASTER_POS, + Q_SYNC_WITH_MASTER, + Q_SYNC_SLAVE_WITH_MASTER, + Q_ERROR, + Q_SEND, Q_REAP, + Q_DIRTY_CLOSE, Q_REPLACE, Q_REPLACE_COLUMN, + Q_PING, Q_EVAL, + Q_RPL_PROBE, Q_ENABLE_RPL_PARSE, + Q_DISABLE_RPL_PARSE, Q_EVAL_RESULT, + Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG, + Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG, + Q_WAIT_FOR_SLAVE_TO_STOP, + Q_ENABLE_WARNINGS, Q_DISABLE_WARNINGS, + Q_ENABLE_PS_WARNINGS, Q_DISABLE_PS_WARNINGS, + Q_ENABLE_INFO, Q_DISABLE_INFO, + Q_ENABLE_METADATA, Q_DISABLE_METADATA, + Q_EXEC, Q_DELIMITER, + Q_DISABLE_ABORT_ON_ERROR, Q_ENABLE_ABORT_ON_ERROR, + Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS, + Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, + Q_START_TIMER, Q_END_TIMER, + Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL, + Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT, + Q_IF, + Q_DISABLE_PARSING, Q_ENABLE_PARSING, + Q_REPLACE_REGEX, Q_REMOVE_FILE, Q_FILE_EXIST, + Q_WRITE_FILE, Q_COPY_FILE, Q_PERL, Q_DIE, Q_EXIT, + + Q_UNKNOWN, /* Unknown command. */ + Q_COMMENT, /* Comments, ignored. */ + Q_COMMENT_WITH_COMMAND }; -/* this should really be called command */ -struct st_query -{ - char *query, *query_buf,*first_argument,*last_argument,*end; - int first_word_len; - my_bool abort_on_error, require_file; - match_err expected_errno[MAX_EXPECTED_ERRORS]; - uint expected_errors; - char record_file[FN_REFLEN]; - enum enum_commands type; -}; const char *command_names[]= { @@ -427,69 +339,118 @@ const char *command_names[]= "disable_parsing", "enable_parsing", "replace_regex", + "remove_file", + "file_exists", + "write_file", + "copy_file", + "perl", "die", + /* Don't execute any more commands, compare result */ + "exit", 0 }; -TYPELIB command_typelib= {array_elements(command_names),"", - command_names, 0}; - -DYNAMIC_STRING ds_res, ds_progress; -static void die(const char *fmt, ...); -static void init_var_hash(); -static VAR* var_from_env(const char *, const char *); -static byte* get_var_key(const byte* rec, uint* len, my_bool t); -static VAR* var_init(VAR* v, const char *name, int name_len, const char *val, - int val_len); -static void var_free(void* v); +/* + The list of error codes to --error are stored in an internal array of + structs. This struct can hold numeric SQL error codes, error names or + SQLSTATE codes as strings. The element next to the last active element + in the list is set to type ERR_EMPTY. When an SQL statement returns an + error, we use this list to check if this is an expected error. +*/ +enum match_err_type +{ + ERR_EMPTY= 0, + ERR_ERRNO, + ERR_SQLSTATE +}; -void dump_result_to_reject_file(const char *record_file, char *buf, int size); -void dump_result_to_log_file(const char *record_file, char *buf, int size); +struct st_match_err +{ + enum match_err_type type; + union + { + uint errnum; + char sqlstate[SQLSTATE_LENGTH+1]; /* \0 terminated string */ + } code; +}; -int close_connection(struct st_query*); -static void set_charset(struct st_query*); -VAR* var_get(const char *var_name, const char** var_name_end, my_bool raw, - my_bool ignore_not_existing); -int eval_expr(VAR* v, const char *p, const char** p_end); -static int read_server_arguments(const char *name); +struct st_expected_errors +{ + struct st_match_err err[10]; + uint count; +}; +static struct st_expected_errors saved_expected_errors; -/* Definitions for replace result */ +struct st_command +{ + char *query, *query_buf,*first_argument,*last_argument,*end; + int first_word_len, query_len; + my_bool abort_on_error; + struct st_expected_errors expected_errors; + char require_file[FN_REFLEN]; + enum enum_commands type; +}; -typedef struct st_pointer_array { /* when using array-strings */ - TYPELIB typelib; /* Pointer to strings */ - byte *str; /* Strings is here */ - int7 *flag; /* Flag about each var. */ - uint array_allocs,max_count,length,max_length; -} POINTER_ARRAY; +TYPELIB command_typelib= {array_elements(command_names),"", + command_names, 0}; -struct st_replace; -struct st_replace *init_replace(my_string *from, my_string *to, uint count, - my_string word_end_chars); -void free_replace(); -static void free_replace_regex(); -static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name); -static void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds, - const char *from, int len); -void free_pointer_array(POINTER_ARRAY *pa); -static void do_eval(DYNAMIC_STRING *query_eval, const char *query, - my_bool pass_through_escape_chars); -static void str_to_file(const char *fname, char *str, int size); +DYNAMIC_STRING ds_res, ds_progress, ds_warning_messages; + +void die(const char *fmt, ...) + ATTRIBUTE_FORMAT(printf, 1, 2); +void abort_not_supported_test(const char *fmt, ...) + ATTRIBUTE_FORMAT(printf, 1, 2); +void verbose_msg(const char *fmt, ...) + ATTRIBUTE_FORMAT(printf, 1, 2); +void warning_msg(const char *fmt, ...) + ATTRIBUTE_FORMAT(printf, 1, 2); + +VAR* var_from_env(const char *, const char *); +VAR* var_init(VAR* v, const char *name, int name_len, const char *val, + int val_len); +void var_free(void* v); +VAR* var_get(const char *var_name, const char** var_name_end, + my_bool raw, my_bool ignore_not_existing); +void eval_expr(VAR* v, const char *p, const char** p_end); +my_bool match_delimiter(int c, const char *delim, uint length); +void dump_result_to_reject_file(char *buf, int size); +void dump_result_to_log_file(char *buf, int size); +void dump_warning_messages(); +void dump_progress(); + +void do_eval(DYNAMIC_STRING *query_eval, const char *query, + const char *query_end, my_bool pass_through_escape_chars); +void str_to_file(const char *fname, char *str, int size); #ifdef __WIN__ -static void free_tmp_sh_file(); -static void free_win_path_patterns(); +void free_tmp_sh_file(); +void free_win_path_patterns(); #endif -struct st_replace *glob_replace; static int eval_result = 0; -/* For column replace */ -char *replace_column[MAX_COLUMNS]; -uint max_replace_column= 0; +/* For replace_column */ +static char *replace_column[MAX_COLUMNS]; +static uint max_replace_column= 0; +void do_get_replace_column(struct st_command*); +void free_replace_column(); + +/* For replace */ +void do_get_replace(struct st_command *command); +void free_replace(); + +/* For replace_regex */ +void do_get_replace_regex(struct st_command *command); +void free_replace_regex(); + + +void free_all_replace(){ + free_replace(); + free_replace_regex(); + free_replace_column(); +} -static void get_replace_column(struct st_query *q); -static void free_replace_column(); /* Disable functions that only exist in MySQL 4.0 */ #if MYSQL_VERSION_ID < 40000 @@ -498,35 +459,40 @@ void mysql_disable_rpl_parse(MYSQL* mysql __attribute__((unused))) {} int mysql_rpl_parse_enabled(MYSQL* mysql __attribute__((unused))) { return 1; } my_bool mysql_rpl_probe(MYSQL *mysql __attribute__((unused))) { return 1; } #endif -static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, - int len); -static void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val); -static void handle_error(const char *query, struct st_query *q, - unsigned int err_errno, const char *err_error, - const char *err_sqlstate, DYNAMIC_STRING *ds); -static void handle_no_error(struct st_query *q); -static void do_eval(DYNAMIC_STRING* query_eval, const char *query, - my_bool pass_through_escape_chars) +void replace_dynstr_append_mem(DYNAMIC_STRING *ds, const char *val, + int len); +void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val); +void replace_dynstr_append_uint(DYNAMIC_STRING *ds, uint val); + +void handle_error(struct st_command*, + unsigned int err_errno, const char *err_error, + const char *err_sqlstate, DYNAMIC_STRING *ds); +void handle_no_error(struct st_command*); + + + +void do_eval(DYNAMIC_STRING *query_eval, const char *query, + const char *query_end, my_bool pass_through_escape_chars) { const char *p; register char c, next_c; register int escaped = 0; - VAR* v; + VAR *v; DBUG_ENTER("do_eval"); - for (p= query; (c = *p); ++p) + for (p= query; (c= *p) && p < query_end; ++p) { switch(c) { case '$': if (escaped) { - escaped = 0; + escaped= 0; dynstr_append_mem(query_eval, p, 1); } else { - if (!(v = var_get(p, &p, 0, 0))) + if (!(v= var_get(p, &p, 0, 0))) die("Bad variable in eval"); dynstr_append_mem(query_eval, v->str_val, v->str_val_len); } @@ -535,13 +501,13 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char *query, next_c= *(p+1); if (escaped) { - escaped = 0; + escaped= 0; dynstr_append_mem(query_eval, p, 1); } - else if (next_c == '\\' || next_c == '$') + else if (next_c == '\\' || next_c == '$' || next_c == '"') { - /* Set escaped only if next char is \ or $ */ - escaped = 1; + /* Set escaped only if next char is \, " or $ */ + escaped= 1; if (pass_through_escape_chars) { @@ -561,10 +527,131 @@ static void do_eval(DYNAMIC_STRING* query_eval, const char *query, } -static void close_cons() +enum arg_type +{ + ARG_STRING, + ARG_REST +}; + +struct command_arg { + const char *argname; /* Name of argument */ + enum arg_type type; /* Type of argument */ + my_bool required; /* Argument required */ + DYNAMIC_STRING *ds; /* Storage for argument */ + const char *description; /* Description of the argument */ +}; + + +void check_command_args(struct st_command *command, + const char *arguments, + const struct command_arg *args, + int num_args, const char delimiter_arg) +{ + int i; + const char *ptr= arguments; + const char *start; + + DBUG_ENTER("check_command_args"); + DBUG_PRINT("enter", ("num_args: %d", num_args)); + for (i= 0; i < num_args; i++) + { + const struct command_arg *arg= &args[i]; + + switch (arg->type) + { + /* A string */ + case ARG_STRING: + /* Skip leading spaces */ + while (*ptr && *ptr == ' ') + ptr++; + start= ptr; + /* Find end of arg, terminated by "delimiter_arg" */ + while (*ptr && *ptr != delimiter_arg) + ptr++; + if (ptr > start) + { + init_dynamic_string(arg->ds, 0, ptr-start, 32); + do_eval(arg->ds, start, ptr, FALSE); + } + else + { + /* Empty string */ + init_dynamic_string(arg->ds, "", 0, 0); + } + command->last_argument= (char*)ptr; + + /* Step past the delimiter */ + if (*ptr && *ptr == delimiter_arg) + ptr++; + DBUG_PRINT("info", ("val: %s", arg->ds->str)); + break; + + /* Rest of line */ + case ARG_REST: + start= ptr; + init_dynamic_string(arg->ds, 0, command->query_len, 256); + do_eval(arg->ds, start, command->end, FALSE); + command->last_argument= command->end; + DBUG_PRINT("info", ("val: %s", arg->ds->str)); + break; + + default: + DBUG_ASSERT("Unknown argument type"); + break; + } + + /* Check required arg */ + if (arg->ds->length == 0 && arg->required) + die("Missing required argument '%s' to command '%.*s'", arg->argname, + command->first_word_len, command->query); + + } + DBUG_VOID_RETURN; +} + + +void handle_command_error(struct st_command *command, uint error) +{ + DBUG_ENTER("handle_command_error"); + DBUG_PRINT("enter", ("error: %d", error)); + if (error != 0) + { + uint i; + + if (command->abort_on_error) + die("command \"%.*s\" failed with error %d", + command->first_word_len, command->query, error); + for (i= 0; i < command->expected_errors.count; i++) + { + DBUG_PRINT("info", ("expected error: %d", + command->expected_errors.err[i].code.errnum)); + if ((command->expected_errors.err[i].type == ERR_ERRNO) && + (command->expected_errors.err[i].code.errnum == error)) + { + DBUG_PRINT("info", ("command \"%.*s\" failed with expected error: %d", + command->first_word_len, command->query, error)); + DBUG_VOID_RETURN; + } + } + die("command \"%.*s\" failed with wrong error: %d", + command->first_word_len, command->query, error); + } + else if (command->expected_errors.err[0].type == ERR_ERRNO && + command->expected_errors.err[0].code.errnum != 0) + { + /* Error code we wanted was != 0, i.e. not an expected success */ + die("command \"%.*s\" succeeded - should have failed with errno %d...", + command->first_word_len, command->query, + command->expected_errors.err[0].code.errnum); + } + DBUG_VOID_RETURN; +} + + +void close_connections() { - DBUG_ENTER("close_cons"); - for (--next_con; next_con >= cons; --next_con) + DBUG_ENTER("close_connections"); + for (--next_con; next_con >= connections; --next_con) { if (next_con->stmt) mysql_stmt_close(next_con->stmt); @@ -578,14 +665,16 @@ static void close_cons() } -static void close_files() +void close_files() { DBUG_ENTER("close_files"); for (; cur_file >= file_stack; cur_file--) { - DBUG_PRINT("info", ("file_name: %s", cur_file->file_name)); if (cur_file->file && cur_file->file != stdin) + { + DBUG_PRINT("info", ("closing file: %s", cur_file->file_name)); my_fclose(cur_file->file, MYF(0)); + } my_free((gptr)cur_file->file_name, MYF(MY_ALLOW_ZERO_PTR)); cur_file->file_name= 0; } @@ -593,22 +682,22 @@ static void close_files() } -static void free_used_memory() +void free_used_memory() { uint i; DBUG_ENTER("free_used_memory"); - close_cons(); + close_connections(); close_files(); hash_free(&var_hash); - for (i=0 ; i < q_lines.elements ; i++) + for (i= 0 ; i < q_lines.elements ; i++) { - struct st_query **q= dynamic_element(&q_lines, i, struct st_query**); + struct st_command **q= dynamic_element(&q_lines, i, struct st_command**); my_free((gptr) (*q)->query_buf,MYF(MY_ALLOW_ZERO_PTR)); my_free((gptr) (*q),MYF(0)); } - for (i=0; i < 10; i++) + for (i= 0; i < 10; i++) { if (var_reg[i].alloced_len) my_free(var_reg[i].str_val, MYF(MY_WME)); @@ -618,8 +707,8 @@ static void free_used_memory() delete_dynamic(&q_lines); dynstr_free(&ds_res); dynstr_free(&ds_progress); - free_replace(); - free_replace_column(); + dynstr_free(&ds_warning_messages); + free_all_replace(); my_free(pass,MYF(MY_ALLOW_ZERO_PTR)); free_defaults(default_argv); mysql_server_end(); @@ -631,10 +720,12 @@ static void free_used_memory() DBUG_VOID_RETURN; } -static void die(const char *fmt, ...) + +void die(const char *fmt, ...) { va_list args; DBUG_ENTER("die"); + DBUG_PRINT("enter", ("start_lineno: %d", start_lineno)); /* Print the error message */ va_start(args, fmt); @@ -653,8 +744,12 @@ static void die(const char *fmt, ...) va_end(args); /* Dump the result that has been accumulated so far to .log file */ - if (result_file && ds_res.length) - dump_result_to_log_file(result_file, ds_res.str, ds_res.length); + if (result_file_name && ds_res.length) + dump_result_to_log_file(ds_res.str, ds_res.length); + + /* Dump warning messages */ + if (result_file_name && ds_warning_messages.length) + dump_warning_messages(); /* Clean up and exit */ free_used_memory(); @@ -667,10 +762,10 @@ static void die(const char *fmt, ...) } -static void abort_not_supported_test(const char *fmt, ...) +void abort_not_supported_test(const char *fmt, ...) { va_list args; - test_file* err_file= cur_file; + struct st_test_file* err_file= cur_file; DBUG_ENTER("abort_not_supported_test"); /* Print include filestack */ @@ -706,7 +801,14 @@ static void abort_not_supported_test(const char *fmt, ...) exit(62); } -static void verbose_msg(const char *fmt, ...) + +void abort_not_in_this_version() +{ + die("Not available in this version of mysqltest"); +} + + +void verbose_msg(const char *fmt, ...) { va_list args; DBUG_ENTER("verbose_msg"); @@ -715,6 +817,9 @@ static void verbose_msg(const char *fmt, ...) va_start(args, fmt); fprintf(stderr, "mysqltest: "); + if (cur_file && cur_file != file_stack) + fprintf(stderr, "In included file \"%s\": ", + cur_file->file_name); if (start_lineno != 0) fprintf(stderr, "At line %u: ", start_lineno); vfprintf(stderr, fmt, args); @@ -725,14 +830,46 @@ static void verbose_msg(const char *fmt, ...) } -void init_parser() +void warning_msg(const char *fmt, ...) { - parser.current_line= parser.read_lines= 0; - memset(&var_reg, 0, sizeof(var_reg)); + va_list args; + char buff[512]; + size_t len; + DBUG_ENTER("warning_msg"); + + va_start(args, fmt); + dynstr_append(&ds_warning_messages, "mysqltest: "); + if (start_lineno != 0) + { + dynstr_append(&ds_warning_messages, "Warning detected "); + if (cur_file && cur_file != file_stack) + { + len= my_snprintf(buff, sizeof(buff), "in included file %s ", + cur_file->file_name); + dynstr_append_mem(&ds_warning_messages, + buff, len); + } + len= my_snprintf(buff, sizeof(buff), "at line %d: ", + start_lineno); + dynstr_append_mem(&ds_warning_messages, + buff, len); + } +#ifndef __WIN__ + len= vsnprintf(buff, sizeof(buff), fmt, args); + dynstr_append_mem(&ds_warning_messages, buff, len); +#endif + dynstr_append(&ds_warning_messages, "\n"); + va_end(args); + + DBUG_VOID_RETURN; } -static int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) +/* + Compare content of the string ds to content of file fname +*/ + +int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) { MY_STAT stat_info; char *tmp, *res_ptr; @@ -755,25 +892,26 @@ static int dyn_string_cmp(DYNAMIC_STRING* ds, const char *fname) die(NullS); if (!eval_result && (uint) stat_info.st_size != ds->length) { - DBUG_PRINT("info",("Size differs: result size: %u file size: %u", + DBUG_PRINT("info",("Size differs: result size: %u file size: %llu", ds->length, stat_info.st_size)); DBUG_PRINT("info",("result: '%s'", ds->str)); DBUG_RETURN(RESULT_LENGTH_MISMATCH); } if (!(tmp = (char*) my_malloc(stat_info.st_size + 1, MYF(MY_WME)))) - die(NullS); + die("Out of memory"); if ((fd = my_open(eval_file, O_RDONLY, MYF(MY_WME))) < 0) - die(NullS); + die("Failed to open file %s", eval_file); if (my_read(fd, (byte*)tmp, stat_info.st_size, MYF(MY_WME|MY_NABP))) - die(NullS); + die("Failed to read from file %s, errno: %d", eval_file, errno); tmp[stat_info.st_size] = 0; - init_dynamic_string(&res_ds, "", 0, 65536); + init_dynamic_string(&res_ds, "", stat_info.st_size+256, 256); if (eval_result) { - do_eval(&res_ds, tmp, FALSE); - res_ptr = res_ds.str; - if ((res_len = res_ds.length) != ds->length) + do_eval(&res_ds, tmp, tmp + stat_info.st_size, FALSE); + res_ptr= res_ds.str; + res_len= res_ds.length; + if (res_len != ds->length) { res= RESULT_LENGTH_MISMATCH; goto err; @@ -794,48 +932,41 @@ err: MY_REPLACE_EXT), res_ptr, res_len); + dynstr_free(&res_ds); my_free((gptr) tmp, MYF(0)); my_close(fd, MYF(MY_WME)); - dynstr_free(&res_ds); DBUG_RETURN(res); } + /* - Check the content of ds against content of file fname + Check the content of ds against result file SYNOPSIS check_result ds - content to be checked - fname - name of file to check against - require_option - if set and check fails, the test will be aborted - with the special exit code "not supported test" RETURN VALUES - error - the function will not return + error - the function will not return */ -static void check_result(DYNAMIC_STRING* ds, const char *fname, - my_bool require_option) + +void check_result(DYNAMIC_STRING* ds) { - int res= dyn_string_cmp(ds, fname); DBUG_ENTER("check_result"); + DBUG_ASSERT(result_file_name); - if (res && require_option) + switch (dyn_string_cmp(ds, result_file_name)) { - char reason[FN_REFLEN]; - fn_format(reason, fname, "", "", MY_REPLACE_EXT | MY_REPLACE_DIR); - abort_not_supported_test("Test requires: '%s'", reason); - } - switch (res) { case RESULT_OK: break; /* ok */ case RESULT_LENGTH_MISMATCH: - dump_result_to_reject_file(fname, ds->str, ds->length); + dump_result_to_reject_file(ds->str, ds->length); die("Result length mismatch"); break; case RESULT_CONTENT_MISMATCH: - dump_result_to_reject_file(fname, ds->str, ds->length); + dump_result_to_reject_file(ds->str, ds->length); die("Result content mismatch"); break; default: /* impossible */ @@ -846,13 +977,109 @@ static void check_result(DYNAMIC_STRING* ds, const char *fname, } -VAR* var_get(const char *var_name, const char** var_name_end, my_bool raw, +/* + Check the content of ds against a require file + If match fails, abort the test with special error code + indicating that test is not supported + + SYNOPSIS + check_result + ds - content to be checked + fname - name of file to check against + + RETURN VALUES + error - the function will not return + +*/ + +void check_require(DYNAMIC_STRING* ds, const char *fname) +{ + DBUG_ENTER("check_require"); + + if (dyn_string_cmp(ds, fname)) + { + char reason[FN_REFLEN]; + fn_format(reason, fname, "", "", MY_REPLACE_EXT | MY_REPLACE_DIR); + abort_not_supported_test("Test requires: '%s'", reason); + } + DBUG_VOID_RETURN; +} + + +static byte *get_var_key(const byte* var, uint* len, + my_bool __attribute__((unused)) t) +{ + register char* key; + key = ((VAR*)var)->name; + *len = ((VAR*)var)->name_len; + return (byte*)key; +} + + +VAR *var_init(VAR *v, const char *name, int name_len, const char *val, + int val_len) +{ + int val_alloc_len; + VAR *tmp_var; + if (!name_len && name) + name_len = strlen(name); + if (!val_len && val) + val_len = strlen(val) ; + val_alloc_len = val_len + 16; /* room to grow */ + if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var) + + name_len+1, MYF(MY_WME)))) + die("Out of memory"); + + tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0; + tmp_var->alloced = (v == 0); + + if (!(tmp_var->str_val = my_malloc(val_alloc_len+1, MYF(MY_WME)))) + die("Out of memory"); + + memcpy(tmp_var->name, name, name_len); + if (val) + { + memcpy(tmp_var->str_val, val, val_len); + tmp_var->str_val[val_len]= 0; + } + tmp_var->name_len = name_len; + tmp_var->str_val_len = val_len; + tmp_var->alloced_len = val_alloc_len; + tmp_var->int_val = (val) ? atoi(val) : 0; + tmp_var->int_dirty = 0; + tmp_var->env_s = 0; + return tmp_var; +} + + +void var_free(void *v) +{ + my_free(((VAR*) v)->str_val, MYF(MY_WME)); + if (((VAR*)v)->alloced) + my_free((char*) v, MYF(MY_WME)); +} + + +VAR* var_from_env(const char *name, const char *def_val) +{ + const char *tmp; + VAR *v; + if (!(tmp = getenv(name))) + tmp = def_val; + + v = var_init(0, name, strlen(name), tmp, strlen(tmp)); + my_hash_insert(&var_hash, (byte*)v); + return v; +} + + +VAR* var_get(const char *var_name, const char **var_name_end, my_bool raw, my_bool ignore_not_existing) { int digit; - VAR* v; + VAR *v; DBUG_ENTER("var_get"); - DBUG_PRINT("enter",("var_name: %s",var_name)); + DBUG_PRINT("enter", ("var_name: %s",var_name)); if (*var_name != '$') goto err; @@ -871,16 +1098,16 @@ VAR* var_get(const char *var_name, const char** var_name_end, my_bool raw, die("Empty variable"); } length= (uint) (var_name - save_var_name); - if (length >= MAX_VAR_NAME) + if (length >= MAX_VAR_NAME_LENGTH) die("Too long variable name: %s", save_var_name); if (!(v = (VAR*) hash_search(&var_hash, save_var_name, length))) { - char buff[MAX_VAR_NAME+1]; + char buff[MAX_VAR_NAME_LENGTH+1]; strmake(buff, save_var_name, length); v= var_from_env(buff, ""); } - var_name--; /* Point at last character */ + var_name--; /* Point at last character */ } else v = var_reg + digit; @@ -901,7 +1128,8 @@ err: DBUG_RETURN(0); } -static VAR *var_obtain(const char *name, int len) + +VAR *var_obtain(const char *name, int len) { VAR* v; if ((v = (VAR*)hash_search(&var_hash, name, len))) @@ -911,16 +1139,18 @@ static VAR *var_obtain(const char *name, int len) return v; } + /* - if variable starts with a $ it is regarded as a local test varable - if not it is treated as a environment variable, and the corresponding environment variable will be updated */ -int var_set(const char *var_name, const char *var_name_end, - const char *var_val, const char *var_val_end) + +void var_set(const char *var_name, const char *var_name_end, + const char *var_val, const char *var_val_end) { - int digit, result, env_var= 0; - VAR* v; + int digit, env_var= 0; + VAR *v; DBUG_ENTER("var_set"); DBUG_PRINT("enter", ("var_name: '%.*s' = '%.*s' (length: %d)", (int) (var_name_end - var_name), var_name, @@ -932,15 +1162,15 @@ int var_set(const char *var_name, const char *var_name_end, else var_name++; - digit = *var_name - '0'; + digit= *var_name - '0'; if (!(digit < 10 && digit >= 0)) { - v = var_obtain(var_name, (uint) (var_name_end - var_name)); + v= var_obtain(var_name, (uint) (var_name_end - var_name)); } else - v = var_reg + digit; + v= var_reg + digit; - result= eval_expr(v, var_val, (const char**) &var_val_end); + eval_expr(v, var_val, (const char**) &var_val_end); if (env_var) { @@ -957,7 +1187,183 @@ int var_set(const char *var_name, const char *var_name_end, putenv(v->env_s); my_free((gptr)old_env_s, MYF(MY_ALLOW_ZERO_PTR)); } - DBUG_RETURN(result); + DBUG_VOID_RETURN; +} + +/* + Store an integer (typically the returncode of the last SQL) + statement in the mysqltest builtin variable $mysql_errno, by + simulating of a user statement "let $mysql_errno= <integer>" +*/ + +void var_set_errno(int sql_errno) +{ + /* TODO MASV make easier */ + const char *var_name= "$mysql_errno"; + char var_val[21]; + uint length= my_sprintf(var_val, (var_val, "%d", sql_errno)); + var_set(var_name, var_name + 12, var_val, var_val + length); + return; +} + + +/* + Set variable from the result of a query + + SYNOPSIS + var_query_set() + var variable to set from query + query start of query string to execute + query_end end of the query string to execute + + + DESCRIPTION + let @<var_name> = `<query>` + + Execute the query and assign the first row of result to var as + a tab separated strings + + Also assign each column of the result set to + variable "$<var_name>_<column_name>" + Thus the tab separated output can be read from $<var_name> and + and each individual column can be read as $<var_name>_<col_name> + +*/ + +void var_query_set(VAR *var, const char *query, const char** query_end) +{ + char* end = (char*)((query_end && *query_end) ? + *query_end : query + strlen(query)); + MYSQL_RES *res; + MYSQL_ROW row; + MYSQL* mysql = &cur_con->mysql; + DBUG_ENTER("var_query_set"); + LINT_INIT(res); + + while (end > query && *end != '`') + --end; + if (query == end) + die("Syntax error in query, missing '`'"); + ++query; + + if (mysql_real_query(mysql, query, (int)(end - query)) || + !(res = mysql_store_result(mysql))) + { + *end = 0; + die("Error running query '%s': %d %s", query, + mysql_errno(mysql), mysql_error(mysql)); + } + + if ((row = mysql_fetch_row(res)) && row[0]) + { + /* + Concatenate all row results with tab in between to allow us to work + with results from many columns (for example from SHOW VARIABLES) + */ + DYNAMIC_STRING result; + uint i; + ulong *lengths; + char *end; +#ifdef NOT_YET + MYSQL_FIELD *fields= mysql_fetch_fields(res); +#endif + + init_dynamic_string(&result, "", 2048, 2048); + lengths= mysql_fetch_lengths(res); + for (i=0; i < mysql_num_fields(res); i++) + { + if (row[0]) + { +#ifdef NOT_YET + /* Add to <var_name>_<col_name> */ + uint j; + char var_col_name[MAX_VAR_NAME_LENGTH]; + uint length= snprintf(var_col_name, MAX_VAR_NAME_LENGTH, + "$%s_%s", var->name, fields[i].name); + /* Convert characters not allowed in variable names to '_' */ + for (j= 1; j < length; j++) + { + if (!my_isvar(charset_info,var_col_name[j])) + var_col_name[j]= '_'; + } + var_set(var_col_name, var_col_name + length, + row[i], row[i] + lengths[i]); +#endif + /* Add column to tab separated string */ + dynstr_append_mem(&result, row[i], lengths[i]); + } + dynstr_append_mem(&result, "\t", 1); + } + end= result.str + result.length-1; + eval_expr(var, result.str, (const char**) &end); + dynstr_free(&result); + } + else + eval_expr(var, "", 0); + + mysql_free_result(res); + DBUG_VOID_RETURN; +} + + +void var_copy(VAR *dest, VAR *src) +{ + dest->int_val= src->int_val; + dest->int_dirty= src->int_dirty; + + /* Alloc/realloc data for str_val in dest */ + if (dest->alloced_len < src->alloced_len && + !(dest->str_val= dest->str_val + ? my_realloc(dest->str_val, src->alloced_len, MYF(MY_WME)) + : my_malloc(src->alloced_len, MYF(MY_WME)))) + die("Out of memory"); + else + dest->alloced_len= src->alloced_len; + + /* Copy str_val data to dest */ + dest->str_val_len= src->str_val_len; + if (src->str_val_len) + memcpy(dest->str_val, src->str_val, src->str_val_len); +} + + +void eval_expr(VAR *v, const char *p, const char **p_end) +{ + static int MIN_VAR_ALLOC= 32; /* MASV why 32? */ + VAR *vp; + if (*p == '$') + { + if ((vp= var_get(p, p_end, 0, 0))) + { + var_copy(v, vp); + return; + } + } + else if (*p == '`') + { + var_query_set(v, p, p_end); + } + else + { + int new_val_len = (p_end && *p_end) ? + (int) (*p_end - p) : (int) strlen(p); + if (new_val_len + 1 >= v->alloced_len) + { + v->alloced_len = (new_val_len < MIN_VAR_ALLOC - 1) ? + MIN_VAR_ALLOC : new_val_len + 1; + if (!(v->str_val = + v->str_val ? my_realloc(v->str_val, v->alloced_len+1, + MYF(MY_WME)) : + my_malloc(v->alloced_len+1, MYF(MY_WME)))) + die("Out of memory"); + } + v->str_val_len = new_val_len; + memcpy(v->str_val, p, new_val_len); + v->str_val[new_val_len] = 0; + v->int_val=atoi(p); + v->int_dirty=0; + } + return; } @@ -988,103 +1394,53 @@ int open_file(const char *name) /* - Check for unexpected "junk" after the end of query - This is normally caused by missing delimiters -*/ - -int check_eol_junk(const char *eol) -{ - const char *p= eol; - DBUG_ENTER("check_eol_junk"); - DBUG_PRINT("enter", ("eol: %s", eol)); - /* Remove all spacing chars except new line */ - while (*p && my_isspace(charset_info, *p) && (*p != '\n')) - p++; - - /* Check for extra delimiter */ - if (*p && !strncmp(p, delimiter, delimiter_length)) - die("Extra delimiter \"%s\" found", delimiter); - - /* Allow trailing # comment */ - if (*p && *p != '#') - { - if (*p == '\n') - die("Missing delimiter"); - die("End of line junk detected: \"%s\"", p); - } - DBUG_RETURN(0); -} - - -/* ugly long name, but we are following the convention */ -int do_wait_for_slave_to_stop(struct st_query *q __attribute__((unused))) -{ - MYSQL* mysql = &cur_con->mysql; - for (;;) - { - MYSQL_RES *res; - MYSQL_ROW row; - int done; - LINT_INIT(res); - - if (mysql_query(mysql,"show status like 'Slave_running'") || - !(res=mysql_store_result(mysql))) - die("Query failed while probing slave for stop: %s", - mysql_error(mysql)); - if (!(row=mysql_fetch_row(res)) || !row[1]) - { - mysql_free_result(res); - die("Strange result from query while probing slave for stop"); - } - done = !strcmp(row[1],"OFF"); - mysql_free_result(res); - if (done) - break; - my_sleep(SLAVE_POLL_INTERVAL); - } - return 0; -} - - -/* Source and execute the given file SYNOPSIS - do_source() - query called command + do_source() + query called command DESCRIPTION - source <file_name> + source <file_name> - Open the file <file_name> and execute it + Open the file <file_name> and execute it */ -int do_source(struct st_query *query) +void do_source(struct st_command *command) { - char *p= query->first_argument, *name; - if (!*p) - die("Missing file name in source"); - name= p; - while (*p && !my_isspace(charset_info,*p)) - p++; - if (*p) - *p++= 0; - query->last_argument= p; + static DYNAMIC_STRING ds_filename; + const struct command_arg source_args[] = { + "filename", ARG_STRING, TRUE, &ds_filename, "File to source" + }; + DBUG_ENTER("do_source"); + + check_command_args(command, command->first_argument, source_args, + sizeof(source_args)/sizeof(struct command_arg), + ' '); + /* - If this file has already been sourced, don't source it again. - It's already available in the q_lines cache. + If this file has already been sourced, don't source it again. + It's already available in the q_lines cache. */ if (parser.current_line < (parser.read_lines - 1)) - return 0; - return open_file(name); + ; /* Do nothing */ + else + { + DBUG_PRINT("info", ("sourcing file: %s", ds_filename.str)); + open_file(ds_filename.str); + } + + dynstr_free(&ds_filename); + return; } + #ifdef __WIN__ -/* Variables used for temuprary sh files used for emulating Unix on Windows */ +/* Variables used for temporary sh files used for emulating Unix on Windows */ char tmp_sh_name[64], tmp_sh_cmd[70]; -static void init_tmp_sh_file() +void init_tmp_sh_file() { /* Format a name for the tmp sh file that is unique for this process */ my_snprintf(tmp_sh_name, sizeof(tmp_sh_name), "tmp_%d.sh", getpid()); @@ -1092,13 +1448,15 @@ static void init_tmp_sh_file() my_snprintf(tmp_sh_cmd, sizeof(tmp_sh_cmd), "sh %s", tmp_sh_name); } -static void free_tmp_sh_file() + +void free_tmp_sh_file() { my_delete(tmp_sh_name, MYF(0)); } #endif -FILE* my_popen(DYNAMIC_STRING* ds_cmd, const char* mode) + +FILE* my_popen(DYNAMIC_STRING *ds_cmd, const char *mode) { #ifdef __WIN__ /* Dump the command into a sh script file and execute with popen */ @@ -1114,49 +1472,49 @@ FILE* my_popen(DYNAMIC_STRING* ds_cmd, const char* mode) Execute given command. SYNOPSIS - do_exec() - query called command + do_exec() + query called command DESCRIPTION - exec <command> + exec <command> - Execute the text between exec and end of line in a subprocess. - The error code returned from the subprocess is checked against the - expected error array, previously set with the --error command. - It can thus be used to execute a command that shall fail. + Execute the text between exec and end of line in a subprocess. + The error code returned from the subprocess is checked against the + expected error array, previously set with the --error command. + It can thus be used to execute a command that shall fail. NOTE - Although mysqltest is executed from cygwin shell, the command will be - executed in "cmd.exe". Thus commands like "rm" etc can NOT be used, use - system for those commands. + Although mysqltest is executed from cygwin shell, the command will be + executed in "cmd.exe". Thus commands like "rm" etc can NOT be used, use + system for those commands. */ -static void do_exec(struct st_query *query) +void do_exec(struct st_command *command) { int error; char buf[1024]; FILE *res_file; - char *cmd= query->first_argument; + char *cmd= command->first_argument; DYNAMIC_STRING ds_cmd; DBUG_ENTER("do_exec"); DBUG_PRINT("enter", ("cmd: '%s'", cmd)); + /* Skip leading space */ while (*cmd && my_isspace(charset_info, *cmd)) cmd++; if (!*cmd) die("Missing argument in exec"); - query->last_argument= query->end; + command->last_argument= command->end; - init_dynamic_string(&ds_cmd, 0, strlen(cmd)+256, 256); + init_dynamic_string(&ds_cmd, 0, command->query_len+256, 256); /* Eval the command, thus replacing all environment variables */ - do_eval(&ds_cmd, cmd, TRUE); - cmd= ds_cmd.str; + do_eval(&ds_cmd, cmd, command->end, TRUE); DBUG_PRINT("info", ("Executing '%s' as '%s'", - query->first_argument, cmd)); + command->first_argument, ds_cmd.str)); - if (!(res_file= my_popen(&ds_cmd, "r")) && query->abort_on_error) - die("popen(\"%s\", \"r\") failed", query->first_argument); + if (!(res_file= my_popen(&ds_cmd, "r")) && command->abort_on_error) + die("popen(\"%s\", \"r\") failed", command->first_argument); while (fgets(buf, sizeof(buf), res_file)) { @@ -1176,229 +1534,70 @@ static void do_exec(struct st_query *query) uint status= WEXITSTATUS(error), i; my_bool ok= 0; - if (query->abort_on_error) - die("command \"%s\" failed", query->first_argument); + if (command->abort_on_error) + die("command \"%s\" failed", command->first_argument); DBUG_PRINT("info", ("error: %d, status: %d", error, status)); - for (i= 0; i < query->expected_errors; i++) + for (i= 0; i < command->expected_errors.count; i++) { DBUG_PRINT("info", ("expected error: %d", - query->expected_errno[i].code.errnum)); - if ((query->expected_errno[i].type == ERR_ERRNO) && - (query->expected_errno[i].code.errnum == status)) + command->expected_errors.err[i].code.errnum)); + if ((command->expected_errors.err[i].type == ERR_ERRNO) && + (command->expected_errors.err[i].code.errnum == status)) { ok= 1; DBUG_PRINT("info", ("command \"%s\" failed with expected error: %d", - query->first_argument, status)); + command->first_argument, status)); } } if (!ok) die("command \"%s\" failed with wrong error: %d", - query->first_argument, status); + command->first_argument, status); } - else if (query->expected_errno[0].type == ERR_ERRNO && - query->expected_errno[0].code.errnum != 0) + else if (command->expected_errors.err[0].type == ERR_ERRNO && + command->expected_errors.err[0].code.errnum != 0) { /* Error code we wanted was != 0, i.e. not an expected success */ die("command \"%s\" succeeded - should have failed with errno %d...", - query->first_argument, query->expected_errno[0].code.errnum); + command->first_argument, command->expected_errors.err[0].code.errnum); } - free_replace(); + dynstr_free(&ds_cmd); DBUG_VOID_RETURN; } -/* - Set variable from the result of a query - - SYNOPSIS - var_query_set() - var variable to set from query - query start of query string to execute - query_end end of the query string to execute - - - DESCRIPTION - let @<var_name> = `<query>` - - Execute the query and assign the first row of result to var as - a tab separated strings - - Also assign each column of the result set to - variable "$<var_name>_<column_name>" - Thus the tab separated output can be read from $<var_name> and - and each individual column can be read as $<var_name>_<col_name> - -*/ - -int var_query_set(VAR* var, const char *query, const char** query_end) -{ - char* end = (char*)((query_end && *query_end) ? - *query_end : query + strlen(query)); - MYSQL_RES *res; - MYSQL_ROW row; - MYSQL* mysql = &cur_con->mysql; - DBUG_ENTER("var_query_set"); - LINT_INIT(res); - - while (end > query && *end != '`') - --end; - if (query == end) - die("Syntax error in query, missing '`'"); - ++query; - - if (mysql_real_query(mysql, query, (int)(end - query)) || - !(res = mysql_store_result(mysql))) - { - *end = 0; - die("Error running query '%s': %d: %s", query, - mysql_errno(mysql) ,mysql_error(mysql)); - } - - if ((row = mysql_fetch_row(res)) && row[0]) - { - /* - Concatenate all row results with tab in between to allow us to work - with results from many columns (for example from SHOW VARIABLES) - */ - DYNAMIC_STRING result; - uint i; - ulong *lengths; - char *end; -#ifdef NOT_YET - MYSQL_FIELD *fields= mysql_fetch_fields(res); -#endif - - init_dynamic_string(&result, "", 16384, 65536); - lengths= mysql_fetch_lengths(res); - for (i=0; i < mysql_num_fields(res); i++) - { - if (row[0]) - { -#ifdef NOT_YET - /* Add to <var_name>_<col_name> */ - uint j; - char var_col_name[MAX_VAR_NAME]; - uint length= snprintf(var_col_name, MAX_VAR_NAME, - "$%s_%s", var->name, fields[i].name); - /* Convert characters not allowed in variable names to '_' */ - for (j= 1; j < length; j++) - { - if (!my_isvar(charset_info,var_col_name[j])) - var_col_name[j]= '_'; - } - var_set(var_col_name, var_col_name + length, - row[i], row[i] + lengths[i]); -#endif - /* Add column to tab separated string */ - dynstr_append_mem(&result, row[i], lengths[i]); - } - dynstr_append_mem(&result, "\t", 1); - } - end= result.str + result.length-1; - eval_expr(var, result.str, (const char**) &end); - dynstr_free(&result); - } - else - eval_expr(var, "", 0); - - mysql_free_result(res); - DBUG_RETURN(0); -} - -void var_copy(VAR *dest, VAR *src) -{ - dest->int_val= src->int_val; - dest->int_dirty= src->int_dirty; - - /* Alloc/realloc data for str_val in dest */ - if (dest->alloced_len < src->alloced_len && - !(dest->str_val= dest->str_val - ? my_realloc(dest->str_val, src->alloced_len, MYF(MY_WME)) - : my_malloc(src->alloced_len, MYF(MY_WME)))) - die("Out of memory"); - else - dest->alloced_len= src->alloced_len; - - /* Copy str_val data to dest */ - dest->str_val_len= src->str_val_len; - if (src->str_val_len) - memcpy(dest->str_val, src->str_val, src->str_val_len); -} - -int eval_expr(VAR* v, const char *p, const char** p_end) -{ - VAR* vp; - if (*p == '$') - { - if ((vp = var_get(p,p_end,0,0))) - { - var_copy(v, vp); - return 0; - } - } - else if (*p == '`') - { - return var_query_set(v, p, p_end); - } - else - { - int new_val_len = (p_end && *p_end) ? - (int) (*p_end - p) : (int) strlen(p); - if (new_val_len + 1 >= v->alloced_len) - { - v->alloced_len = (new_val_len < MIN_VAR_ALLOC - 1) ? - MIN_VAR_ALLOC : new_val_len + 1; - if (!(v->str_val = - v->str_val ? my_realloc(v->str_val, v->alloced_len+1, - MYF(MY_WME)) : - my_malloc(v->alloced_len+1, MYF(MY_WME)))) - die("Out of memory"); - } - v->str_val_len = new_val_len; - memcpy(v->str_val, p, new_val_len); - v->str_val[new_val_len] = 0; - v->int_val=atoi(p); - v->int_dirty=0; - return 0; - } - - die("Invalid expr: %s", p); - return 1; -} - - enum enum_operator { DO_DEC, DO_INC }; + /* Decrease or increase the value of a variable SYNOPSIS - do_modify_var() - query called command - operator operation to perform on the var + do_modify_var() + query called command + operator operation to perform on the var DESCRIPTION - dec $var_name - inc $var_name + dec $var_name + inc $var_name */ -int do_modify_var(struct st_query *query, +int do_modify_var(struct st_command *command, enum enum_operator operator) { - const char *p= query->first_argument; + const char *p= command->first_argument; VAR* v; if (!*p) - die("Missing argument to %.*s", query->first_word_len, query->query); + die("Missing argument to %.*s", command->first_word_len, command->query); if (*p != '$') die("The argument to %.*s must be a variable (start with $)", - query->first_word_len, query->query); + command->first_word_len, command->query); v= var_get(p, &p, 1, 0); switch (operator) { case DO_DEC: @@ -1412,7 +1611,7 @@ int do_modify_var(struct st_query *query, break; } v->int_dirty= 1; - query->last_argument= (char*)++p; + command->last_argument= (char*)++p; return 0; } @@ -1421,10 +1620,10 @@ int do_modify_var(struct st_query *query, Wrapper for 'system' function NOTE - If mysqltest is executed from cygwin shell, the command will be - executed in the "windows command interpreter" cmd.exe and we prepend "sh" - to make it be executed by cygwins "bash". Thus commands like "rm", - "mkdir" as well as shellscripts can executed by "system" in Windows. + If mysqltest is executed from cygwin shell, the command will be + executed in the "windows command interpreter" cmd.exe and we prepend "sh" + to make it be executed by cygwins "bash". Thus commands like "rm", + "mkdir" as well as shellscripts can executed by "system" in Windows. */ @@ -1441,20 +1640,19 @@ int my_system(DYNAMIC_STRING* ds_cmd) /* - SYNOPSIS do_system - command called command + command called command DESCRIPTION - system <command> + system <command> - Eval the query to expand any $variables in the command. - Execute the command with the "system" command. + Eval the query to expand any $variables in the command. + Execute the command with the "system" command. */ -void do_system(struct st_query *command) +void do_system(struct st_command *command) { DYNAMIC_STRING ds_cmd; DBUG_ENTER("do_system"); @@ -1462,10 +1660,10 @@ void do_system(struct st_query *command) if (strlen(command->first_argument) == 0) die("Missing arguments to system, nothing to do!"); - init_dynamic_string(&ds_cmd, 0, strlen(command->first_argument) + 64, 256); + init_dynamic_string(&ds_cmd, 0, command->query_len + 64, 256); /* Eval the system command, thus replacing all environment variables */ - do_eval(&ds_cmd, command->first_argument, TRUE); + do_eval(&ds_cmd, command->first_argument, command->end, TRUE); DBUG_PRINT("info", ("running system command '%s' as '%s'", command->first_argument, ds_cmd.str)); @@ -1487,50 +1685,375 @@ void do_system(struct st_query *command) /* + SYNOPSIS + do_remove_file + command called command + + DESCRIPTION + remove_file <file_name> + Remove the file <file_name> +*/ + +void do_remove_file(struct st_command *command) +{ + int error; + static DYNAMIC_STRING ds_filename; + const struct command_arg rm_args[] = { + "filename", ARG_STRING, TRUE, &ds_filename, "File to delete" + }; + DBUG_ENTER("do_remove_file"); + + check_command_args(command, command->first_argument, + rm_args, sizeof(rm_args)/sizeof(struct command_arg), + ' '); + + DBUG_PRINT("info", ("removing file: %s", ds_filename.str)); + error= my_delete(ds_filename.str, MYF(0)) != 0; + handle_command_error(command, error); + dynstr_free(&ds_filename); + DBUG_VOID_RETURN; +} + + +/* + SYNOPSIS + do_copy_file + command command handle + + DESCRIPTION + copy_file <from_file> <to_file> + Copy <from_file> to <to_file> + + NOTE! Will fail if <to_file> exists +*/ + +void do_copy_file(struct st_command *command) +{ + int error; + static DYNAMIC_STRING ds_from_file; + static DYNAMIC_STRING ds_to_file; + const struct command_arg copy_file_args[] = { + "from_file", ARG_STRING, TRUE, &ds_from_file, "Filename to copy from", + "to_file", ARG_STRING, TRUE, &ds_to_file, "Filename to copy to" + }; + DBUG_ENTER("do_copy_file"); + + check_command_args(command, command->first_argument, + copy_file_args, + sizeof(copy_file_args)/sizeof(struct command_arg), + ' '); + + DBUG_PRINT("info", ("Copy %s to %s", ds_from_file.str, ds_to_file.str)); + error= (my_copy(ds_from_file.str, ds_to_file.str, + MYF(MY_DONT_OVERWRITE_FILE)) != 0); + handle_command_error(command, error); + dynstr_free(&ds_from_file); + dynstr_free(&ds_to_file); + DBUG_VOID_RETURN; +} + + +/* + SYNOPSIS + do_file_exists + command called command + + DESCRIPTION + fiile_exist <file_name> + Check if file <file_name> exists +*/ + +void do_file_exist(struct st_command *command) +{ + int error; + static DYNAMIC_STRING ds_filename; + const struct command_arg file_exist_args[] = { + "filename", ARG_STRING, TRUE, &ds_filename, "File to check if it exist" + }; + DBUG_ENTER("do_file_exist"); + + check_command_args(command, command->first_argument, + file_exist_args, + sizeof(file_exist_args)/sizeof(struct command_arg), + ' '); + + DBUG_PRINT("info", ("Checking for existence of file: %s", ds_filename.str)); + error= (access(ds_filename.str, F_OK) != 0); + handle_command_error(command, error); + dynstr_free(&ds_filename); + DBUG_VOID_RETURN; +} + + +/* + Read characters from line buffer or file. This is needed to allow + my_ungetc() to buffer MAX_DELIMITER_LENGTH characters for a file + + NOTE: + This works as long as one doesn't change files (with 'source file_name') + when there is things pushed into the buffer. This should however not + happen for any tests in the test suite. +*/ + +int my_getc(FILE *file) +{ + if (line_buffer_pos == line_buffer) + return fgetc(file); + return *--line_buffer_pos; +} + + +void my_ungetc(int c) +{ + *line_buffer_pos++= (char) c; +} + + +void read_until_delimiter(DYNAMIC_STRING *ds, + DYNAMIC_STRING *ds_delimiter) +{ + char c; + DBUG_ENTER("read_until_delimiter"); + DBUG_PRINT("enter", ("delimiter: %s, length: %d", + ds_delimiter->str, ds_delimiter->length)); + + if (ds_delimiter->length > MAX_DELIMITER_LENGTH) + die("Max delimiter length(%d) exceeded", MAX_DELIMITER_LENGTH); + + /* Read from file until delimiter is found */ + while (1) + { + c= my_getc(cur_file->file); + + if (c == '\n') + cur_file->lineno++; + + if (feof(cur_file->file)) + die("End of file encountered before '%s' delimiter was found", + ds_delimiter->str); + + if (match_delimiter(c, ds_delimiter->str, ds_delimiter->length)) + { + DBUG_PRINT("exit", ("Found delimiter '%s'", ds_delimiter->str)); + break; + } + dynstr_append_mem(ds, (const char*)&c, 1); + } + DBUG_PRINT("exit", ("ds: %s", ds->str)); + DBUG_VOID_RETURN; +} + + +/* + SYNOPSIS + do_write_file + command called command + + DESCRIPTION + write_file <file_name> [<delimiter>]; + <what to write line 1> + <...> + < what to write line n> + EOF + + --write_file <file_name>; + <what to write line 1> + <...> + < what to write line n> + EOF + + Write everything between the "write_file" command and 'delimiter' + to "file_name" + + NOTE! Overwrites existing file + + Default <delimiter> is EOF + +*/ + +void do_write_file(struct st_command *command) +{ + static DYNAMIC_STRING ds_content; + static DYNAMIC_STRING ds_filename; + static DYNAMIC_STRING ds_delimiter; + const struct command_arg write_file_args[] = { + "filename", ARG_STRING, TRUE, &ds_filename, "File to write to", + "delimiter", ARG_STRING, FALSE, &ds_delimiter, "Delimiter to read until" + }; + DBUG_ENTER("do_write_file"); + + check_command_args(command, + command->first_argument, + write_file_args, + sizeof(write_file_args)/sizeof(struct command_arg), + ' '); + + /* If no delimiter was provided, use EOF */ + if (ds_delimiter.length == 0) + dynstr_set(&ds_delimiter, "EOF"); + + init_dynamic_string(&ds_content, "", 1024, 1024); + read_until_delimiter(&ds_content, &ds_delimiter); + DBUG_PRINT("info", ("Writing to file: %s", ds_filename.str)); + str_to_file(ds_filename.str, ds_content.str, ds_content.length); + dynstr_free(&ds_content); + dynstr_free(&ds_filename); + dynstr_free(&ds_delimiter); + DBUG_VOID_RETURN; +} + + +/* + SYNOPSIS + do_perl + command command handle + + DESCRIPTION + perl [<delimiter>]; + <perlscript line 1> + <...> + <perlscript line n> + EOF + + Execute everything after "perl" until <delimiter> as perl. + Useful for doing more advanced things + but still being able to execute it on all platforms. + + Default <delimiter> is EOF +*/ + +void do_perl(struct st_command *command) +{ + int error; + char buf[FN_REFLEN]; + FILE *res_file; + static DYNAMIC_STRING ds_script; + static DYNAMIC_STRING ds_delimiter; + const struct command_arg perl_args[] = { + "delimiter", ARG_STRING, FALSE, &ds_delimiter, "Delimiter to read until" + }; + DBUG_ENTER("do_perl"); + + check_command_args(command, + command->first_argument, + perl_args, + sizeof(perl_args)/sizeof(struct command_arg), + ' '); + + /* If no delimiter was provided, use EOF */ + if (ds_delimiter.length == 0) + dynstr_set(&ds_delimiter, "EOF"); + + init_dynamic_string(&ds_script, "", 1024, 1024); + read_until_delimiter(&ds_script, &ds_delimiter); + + DBUG_PRINT("info", ("Executing perl: %s", ds_script.str)); + + /* Format a name for a tmp .pl file that is unique for this process */ + my_snprintf(buf, sizeof(buf), "%s/tmp/tmp_%d.pl", + getenv("MYSQLTEST_VARDIR"), getpid()); + str_to_file(buf, ds_script.str, ds_script.length); + + /* Format the perl <filename> command */ + my_snprintf(buf, sizeof(buf), "perl %s/tmp/tmp_%d.pl", + getenv("MYSQLTEST_VARDIR"), getpid()); + + if (!(res_file= popen(buf, "r")) && command->abort_on_error) + die("popen(\"%s\", \"r\") failed", buf); + + while (fgets(buf, sizeof(buf), res_file)) + { + if (disable_result_log) + { + buf[strlen(buf)-1]=0; + DBUG_PRINT("exec_result",("%s", buf)); + } + else + { + replace_dynstr_append(&ds_res, buf); + } + } + error= pclose(res_file); + handle_command_error(command, WEXITSTATUS(error)); + dynstr_free(&ds_script); + dynstr_free(&ds_delimiter); + DBUG_VOID_RETURN; +} + + +/* Print the content between echo and <delimiter> to result file. Evaluate all variables in the string before printing, allow for variable names to be escaped using \ SYNOPSIS - do_echo() - q called command + do_echo() + command called command DESCRIPTION - echo text - Print the text after echo until end of command to result file + echo text + Print the text after echo until end of command to result file - echo $<var_name> - Print the content of the variable <var_name> to result file + echo $<var_name> + Print the content of the variable <var_name> to result file - echo Some text $<var_name> - Print "Some text" plus the content of the variable <var_name> to - result file + echo Some text $<var_name> + Print "Some text" plus the content of the variable <var_name> to + result file - echo Some text \$<var_name> - Print "Some text" plus $<var_name> to result file + echo Some text \$<var_name> + Print "Some text" plus $<var_name> to result file */ -int do_echo(struct st_query *command) +int do_echo(struct st_command *command) { - DYNAMIC_STRING *ds, ds_echo; + DYNAMIC_STRING ds_echo; - ds= &ds_res; - - init_dynamic_string(&ds_echo, "", 256, 256); - do_eval(&ds_echo, command->first_argument, FALSE); - dynstr_append_mem(ds, ds_echo.str, ds_echo.length); - dynstr_append_mem(ds, "\n", 1); + init_dynamic_string(&ds_echo, "", command->query_len, 256); + do_eval(&ds_echo, command->first_argument, command->end, FALSE); + dynstr_append_mem(&ds_res, ds_echo.str, ds_echo.length); + dynstr_append_mem(&ds_res, "\n", 1); dynstr_free(&ds_echo); command->last_argument= command->end; return(0); } -int do_sync_with_master2(long offset) +void do_wait_for_slave_to_stop(struct st_command *c __attribute__((unused))) { - MYSQL_RES* res; + static int SLAVE_POLL_INTERVAL= 300000; + MYSQL* mysql = &cur_con->mysql; + for (;;) + { + MYSQL_RES *res; + MYSQL_ROW row; + int done; + LINT_INIT(res); + + if (mysql_query(mysql,"show status like 'Slave_running'") || + !(res=mysql_store_result(mysql))) + die("Query failed while probing slave for stop: %s", + mysql_error(mysql)); + if (!(row=mysql_fetch_row(res)) || !row[1]) + { + mysql_free_result(res); + die("Strange result from query while probing slave for stop"); + } + done = !strcmp(row[1],"OFF"); + mysql_free_result(res); + if (done) + break; + my_sleep(SLAVE_POLL_INTERVAL); + } + return; +} + + +void do_sync_with_master2(long offset) +{ + MYSQL_RES *res; MYSQL_ROW row; - MYSQL* mysql= &cur_con->mysql; + MYSQL *mysql= &cur_con->mysql; char query_buf[FN_REFLEN+128]; int tries= 0; int rpl_parse; @@ -1546,7 +2069,7 @@ int do_sync_with_master2(long offset) wait_for_position: if (mysql_query(mysql, query_buf)) - die("failed in %s: %d: %s", query_buf, mysql_errno(mysql), + die("failed in '%s': %d: %s", query_buf, mysql_errno(mysql), mysql_error(mysql)); if (!(res= mysql_store_result(mysql))) @@ -1569,13 +2092,14 @@ wait_for_position: if (rpl_parse) mysql_enable_rpl_parse(mysql); - return 0; + return; } -int do_sync_with_master(struct st_query *query) + +void do_sync_with_master(struct st_command *command) { long offset= 0; - char *p= query->first_argument; + char *p= command->first_argument; const char *offset_start= p; if (*offset_start) { @@ -1584,20 +2108,22 @@ int do_sync_with_master(struct st_query *query) if(*p && !my_isspace(charset_info, *p)) die("Invalid integer argument \"%s\"", offset_start); - query->last_argument= p; + command->last_argument= p; } - return do_sync_with_master2(offset); + do_sync_with_master2(offset); + return; } + /* when ndb binlog is on, this call will wait until last updated epoch (locally in the mysqld) has been received into the binlog */ int do_save_master_pos() { - MYSQL_RES* res; + MYSQL_RES *res; MYSQL_ROW row; - MYSQL* mysql = &cur_con->mysql; + MYSQL *mysql = &cur_con->mysql; const char *query; int rpl_parse; @@ -1606,19 +2132,18 @@ int do_save_master_pos() #ifdef HAVE_NDB_BINLOG /* - Wait for ndb binlog to be up-to-date with all changes - done on the local mysql server + Wait for ndb binlog to be up-to-date with all changes + done on the local mysql server */ { ulong have_ndbcluster; if (mysql_query(mysql, query= "show variables like 'have_ndbcluster'")) - die("At line %u: failed in %s: %d: %s", start_lineno, query, + die("'%s' failed: %d %s", query, mysql_errno(mysql), mysql_error(mysql)); if (!(res= mysql_store_result(mysql))) - die("line %u: mysql_store_result() retuned NULL for '%s'", start_lineno, - query); + die("mysql_store_result() returned NULL for '%s'", query); if (!(row= mysql_fetch_row(res))) - die("line %u: empty result in %s", start_lineno, query); + die("Query '%s' returned empty result", query); have_ndbcluster= strcmp("YES", row[1]) == 0; mysql_free_result(res); @@ -1626,7 +2151,7 @@ int do_save_master_pos() if (have_ndbcluster) { ulonglong start_epoch= 0, applied_epoch= 0, - latest_epoch=0, latest_trans_epoch=0, + latest_epoch=0, latest_trans_epoch=0, latest_handled_binlog_epoch= 0, latest_received_binlog_epoch= 0, latest_applied_binlog_epoch= 0; int count= 0; @@ -1647,11 +2172,10 @@ int do_save_master_pos() if (count) sleep(1); if (mysql_query(mysql, query= "show engine ndb status")) - die("At line %u: failed in '%s': %d: %s", start_lineno, query, + die("failed in '%s': %d %s", query, mysql_errno(mysql), mysql_error(mysql)); if (!(res= mysql_store_result(mysql))) - die("line %u: mysql_store_result() retuned NULL for '%s'", - start_lineno, query); + die("mysql_store_result() returned NULL for '%s'", query); while ((row= mysql_fetch_row(res))) { if (strcmp(row[1], binlog) == 0) @@ -1668,8 +2192,8 @@ int do_save_master_pos() latest_epoch= strtoull(status, (char**) 0, 10); } else - die("line %u: result does not contain '%s' in '%s'", - start_lineno, latest_epoch_str, query); + die("result does not contain '%s' in '%s'", + latest_epoch_str, query); /* latest_trans_epoch */ while (*status && strncmp(status, latest_trans_epoch_str, sizeof(latest_trans_epoch_str)-1)) @@ -1680,10 +2204,10 @@ int do_save_master_pos() latest_trans_epoch= strtoull(status, (char**) 0, 10); } else - die("line %u: result does not contain '%s' in '%s'", - start_lineno, latest_trans_epoch_str, query); + die("result does not contain '%s' in '%s'", + latest_trans_epoch_str, query); /* latest_received_binlog_epoch */ - while (*status && + while (*status && strncmp(status, latest_received_binlog_epoch_str, sizeof(latest_received_binlog_epoch_str)-1)) status++; @@ -1693,10 +2217,10 @@ int do_save_master_pos() latest_received_binlog_epoch= strtoull(status, (char**) 0, 10); } else - die("line %u: result does not contain '%s' in '%s'", - start_lineno, latest_received_binlog_epoch_str, query); + die("result does not contain '%s' in '%s'", + latest_received_binlog_epoch_str, query); /* latest_handled_binlog */ - while (*status && + while (*status && strncmp(status, latest_handled_binlog_epoch_str, sizeof(latest_handled_binlog_epoch_str)-1)) status++; @@ -1706,10 +2230,10 @@ int do_save_master_pos() latest_handled_binlog_epoch= strtoull(status, (char**) 0, 10); } else - die("line %u: result does not contain '%s' in '%s'", - start_lineno, latest_handled_binlog_epoch_str, query); + die("result does not contain '%s' in '%s'", + latest_handled_binlog_epoch_str, query); /* latest_applied_binlog_epoch */ - while (*status && + while (*status && strncmp(status, latest_applied_binlog_epoch_str, sizeof(latest_applied_binlog_epoch_str)-1)) status++; @@ -1719,16 +2243,16 @@ int do_save_master_pos() latest_applied_binlog_epoch= strtoull(status, (char**) 0, 10); } else - die("line %u: result does not contain '%s' in '%s'", - start_lineno, latest_applied_binlog_epoch_str, query); + die("result does not contain '%s' in '%s'", + latest_applied_binlog_epoch_str, query); if (count == 0) start_epoch= latest_trans_epoch; break; } } if (!row) - die("line %u: result does not contain '%s' in '%s'", - start_lineno, binlog, query); + die("result does not contain '%s' in '%s'", + binlog, query); if (latest_applied_binlog_epoch > applied_epoch) count= 0; applied_epoch= latest_applied_binlog_epoch; @@ -1745,7 +2269,7 @@ int do_save_master_pos() } #endif if (mysql_query(mysql, query= "show master status")) - die("failed in show master status: %d: %s", + die("failed in 'show master status': %d %s", mysql_errno(mysql), mysql_error(mysql)); if (!(res = mysql_store_result(mysql))) @@ -1767,28 +2291,29 @@ int do_save_master_pos() Assign the variable <var_name> with <var_val> SYNOPSIS - do_let() - query called command + do_let() + query called command DESCRIPTION - let $<var_name>=<var_val><delimiter> + let $<var_name>=<var_val><delimiter> - <var_name> - is the string string found between the $ and = - <var_val> - is the content between the = and <delimiter>, it may span - multiple line and contain any characters except <delimiter> - <delimiter> - is a string containing of one or more chars, default is ; + <var_name> - is the string string found between the $ and = + <var_val> - is the content between the = and <delimiter>, it may span + multiple line and contain any characters except <delimiter> + <delimiter> - is a string containing of one or more chars, default is ; RETURN VALUES - Program will die if error detected + Program will die if error detected */ -int do_let(struct st_query *query) +void do_let(struct st_command *command) { - int ret; - char *p= query->first_argument; + char *p= command->first_argument; char *var_name, *var_name_end; DYNAMIC_STRING let_rhs_expr; + DBUG_ENTER("do_let"); + init_dynamic_string(&let_rhs_expr, "", 512, 2048); /* Find <var_name> */ @@ -1810,34 +2335,18 @@ int do_let(struct st_query *query) while (*p && my_isspace(charset_info,*p)) p++; - do_eval(&let_rhs_expr, p, FALSE); + do_eval(&let_rhs_expr, p, command->end, FALSE); - query->last_argument= query->end; + command->last_argument= command->end; /* Assign var_val to var_name */ - ret= var_set(var_name, var_name_end, let_rhs_expr.str, - (let_rhs_expr.str + let_rhs_expr.length)); + var_set(var_name, var_name_end, let_rhs_expr.str, + (let_rhs_expr.str + let_rhs_expr.length)); dynstr_free(&let_rhs_expr); - - return(ret); -} - - -/* - Store an integer (typically the returncode of the last SQL) - statement in the mysqltest builtin variable $mysql_errno, by - simulating of a user statement "let $mysql_errno= <integer>" -*/ - -int var_set_errno(int sql_errno) -{ - const char *var_name= "$mysql_errno"; - char var_val[21]; - uint length= my_sprintf(var_val, (var_val, "%d", sql_errno)); - return var_set(var_name, var_name + 12, var_val, var_val + length); + DBUG_VOID_RETURN; } -int do_rpl_probe(struct st_query *query __attribute__((unused))) +int do_rpl_probe(struct st_command *command __attribute__((unused))) { DBUG_ENTER("do_rpl_probe"); if (mysql_rpl_probe(&cur_con->mysql)) @@ -1846,14 +2355,14 @@ int do_rpl_probe(struct st_query *query __attribute__((unused))) } -int do_enable_rpl_parse(struct st_query *query __attribute__((unused))) +int do_enable_rpl_parse(struct st_command *command __attribute__((unused))) { mysql_enable_rpl_parse(&cur_con->mysql); return 0; } -int do_disable_rpl_parse(struct st_query *query __attribute__((unused))) +int do_disable_rpl_parse(struct st_command *command __attribute__((unused))) { mysql_disable_rpl_parse(&cur_con->mysql); return 0; @@ -1861,17 +2370,17 @@ int do_disable_rpl_parse(struct st_query *query __attribute__((unused))) /* - Sleep the number of specifed seconds + Sleep the number of specified seconds SYNOPSIS - do_sleep() - q called command - real_sleep use the value from opt_sleep as number of seconds to sleep - if real_sleep is false + do_sleep() + q called command + real_sleep use the value from opt_sleep as number of seconds to sleep + if real_sleep is false DESCRIPTION - sleep <seconds> - real_sleep <seconds> + sleep <seconds> + real_sleep <seconds> The difference between the sleep and real_sleep commands is that sleep uses the delay from the --sleep command-line option if there is one. @@ -1882,26 +2391,26 @@ int do_disable_rpl_parse(struct st_query *query __attribute__((unused))) used for cpu-independent delays. */ -int do_sleep(struct st_query *query, my_bool real_sleep) +int do_sleep(struct st_command *command, my_bool real_sleep) { int error= 0; - char *p= query->first_argument; - char *sleep_start, *sleep_end= query->end; + char *p= command->first_argument; + char *sleep_start, *sleep_end= command->end; double sleep_val; while (my_isspace(charset_info, *p)) p++; if (!*p) - die("Missing argument to %.*s", query->first_word_len, query->query); + die("Missing argument to %.*s", command->first_word_len, command->query); sleep_start= p; /* Check that arg starts with a digit, not handled by my_strtod */ if (!my_isdigit(charset_info, *sleep_start)) - die("Invalid argument to %.*s \"%s\"", query->first_word_len, query->query, - query->first_argument); + die("Invalid argument to %.*s \"%s\"", command->first_word_len, + command->query,command->first_argument); sleep_val= my_strtod(sleep_start, &sleep_end, &error); if (error) - die("Invalid argument to %.*s \"%s\"", query->first_word_len, query->query, - query->first_argument); + die("Invalid argument to %.*s \"%s\"", command->first_word_len, + command->query, command->first_argument); /* Fixed sleep time selected by --sleep option */ if (opt_sleep >= 0 && !real_sleep) @@ -1910,13 +2419,15 @@ int do_sleep(struct st_query *query, my_bool real_sleep) DBUG_PRINT("info", ("sleep_val: %f", sleep_val)); if (sleep_val) my_sleep((ulong) (sleep_val * 1000000L)); - query->last_argument= sleep_end; + command->last_argument= sleep_end; return 0; } -static void get_file_name(char *filename, struct st_query *q) + +void do_get_file_name(struct st_command *command, + char* dest, uint dest_max_len) { - char *p= q->first_argument, *name; + char *p= command->first_argument, *name; if (!*p) die("Missing file name argument"); name= p; @@ -1924,13 +2435,14 @@ static void get_file_name(char *filename, struct st_query *q) p++; if (*p) *p++= 0; - q->last_argument= p; - strmake(filename, name, FN_REFLEN); + command->last_argument= p; + strmake(dest, name, dest_max_len); } -static void set_charset(struct st_query *q) + +void do_set_charset(struct st_command *command) { - char *charset_name= q->first_argument; + char *charset_name= command->first_argument; char *p; if (!charset_name || !*charset_name) @@ -1941,78 +2453,182 @@ static void set_charset(struct st_query *q) p++; if(*p) *p++= 0; - q->last_argument= p; + command->last_argument= p; charset_info= get_charset_by_csname(charset_name,MY_CS_PRIMARY,MYF(MY_WME)); if (!charset_info) abort_not_supported_test("Test requires charset '%s'", charset_name); } -static uint get_errcodes(match_err *to,struct st_query *q) + +#if MYSQL_VERSION_ID >= 50000 +/* List of error names to error codes, available from 5.0 */ +typedef struct +{ + const char *name; + uint code; +} st_error; + +static st_error global_error_names[] = +{ +#include <mysqld_ername.h> + { 0, 0 } +}; + +uint get_errcode_from_name(char *error_name, char *error_end) { - char *p= q->first_argument; + /* SQL error as string */ + st_error *e= global_error_names; + + DBUG_ENTER("get_errcode_from_name"); + DBUG_PRINT("enter", ("error_name: %s", error_name)); + + /* Loop through the array of known error names */ + for (; e->name; e++) + { + /* + If we get a match, we need to check the length of the name we + matched against in case it was longer than what we are checking + (as in ER_WRONG_VALUE vs. ER_WRONG_VALUE_COUNT). + */ + if (!strncmp(error_name, e->name, (int) (error_end - error_name)) && + (uint) strlen(e->name) == (uint) (error_end - error_name)) + { + DBUG_RETURN(e->code); + } + } + if (!e->name) + die("Unknown SQL error name '%s'", error_name); + DBUG_RETURN(0); +} +#else +uint get_errcode_from_name(char *error_name __attribute__((unused)), + char *error_end __attribute__((unused))) +{ + abort_not_in_this_version(); + return 0; /* Never reached */ +} +#endif + + + +void do_get_errcodes(struct st_command *command) +{ + struct st_match_err *to= saved_expected_errors.err; + char *p= command->first_argument; uint count= 0; - DBUG_ENTER("get_errcodes"); + DBUG_ENTER("do_get_errcodes"); if (!*p) - die("Missing argument in %s", q->query); + die("Missing argument(s) to 'error'"); do { + char *end; + + /* Skip leading spaces */ + while (*p && *p == ' ') + p++; + + /* Find end */ + end= p; + while (*end && *end != ',' && *end != ' ') + end++; + if (*p == 'S') { - /* SQLSTATE string */ - char *end= ++p + SQLSTATE_LENGTH; - char *to_ptr= to[count].code.sqlstate; + char *to_ptr= to->code.sqlstate; - for (; my_isalnum(charset_info, *p) && p != end; p++) - *to_ptr++= *p; - *to_ptr= 0; + /* + SQLSTATE string + - Must be SQLSTATE_LENGTH long + - May contain only digits[0-9] and _uppercase_ letters + */ + p++; /* Step past the S */ + if ((end - p) != SQLSTATE_LENGTH) + die("The sqlstate must be exactly %d chars long", SQLSTATE_LENGTH); - to[count].type= ERR_SQLSTATE; + /* Check sqlstate string validity */ + while (*p && p < end) + { + if (my_isdigit(charset_info, *p) || my_isupper(charset_info, *p)) + *to_ptr++= *p++; + else + die("The sqlstate may only consist of digits[0-9] " \ + "and _uppercase_ letters"); + } + + *to_ptr= 0; + to->type= ERR_SQLSTATE; + DBUG_PRINT("info", ("ERR_SQLSTATE: %s", to->code.sqlstate)); + } + else if (*p == 's') + { + die("The sqlstate definition must start with an uppercase S"); } else if (*p == 'E') { - /* SQL error as string */ - st_error *e= global_error; - char *start= p++; + /* Error name string */ - for (; *p == '_' || my_isalnum(charset_info, *p); p++) - ; - for (; e->name; e++) - { - /* - If we get a match, we need to check the length of the name we - matched against in case it was longer than what we are checking - (as in ER_WRONG_VALUE vs. ER_WRONG_VALUE_COUNT). - */ - if (!strncmp(start, e->name, (int) (p - start)) && - (uint) strlen(e->name) == (uint) (p - start)) - { - to[count].code.errnum= (uint) e->code; - to[count].type= ERR_ERRNO; - break; - } - } - if (!e->name) - die("Unknown SQL error '%s'", start); + DBUG_PRINT("info", ("Error name: %s", p)); + to->code.errnum= get_errcode_from_name(p, end); + to->type= ERR_ERRNO; + DBUG_PRINT("info", ("ERR_ERRNO: %d", to->code.errnum)); + } + else if (*p == 'e') + { + die("The error name definition must start with an uppercase E"); } else { long val; + char *start= p; + /* Check that the string passed to str2int only contain digits */ + while (*p && p != end) + { + if (!my_isdigit(charset_info, *p)) + die("Invalid argument to error: '%s' - "\ + "the errno may only consist of digits[0-9]", + command->first_argument); + p++; + } + + /* Convert the sting to int */ + if (!str2int(start, 10, (long) INT_MIN, (long) INT_MAX, &val)) + die("Invalid argument to error: '%s'", command->first_argument); - if (!(p= str2int(p,10,(long) INT_MIN, (long) INT_MAX, &val))) - die("Invalid argument in %s", q->query); - to[count].code.errnum= (uint) val; - to[count].type= ERR_ERRNO; + to->code.errnum= (uint) val; + to->type= ERR_ERRNO; + DBUG_PRINT("info", ("ERR_ERRNO: %d", to->code.errnum)); } + to++; count++; - } while (*(p++) == ','); - q->last_argument= (p - 1); - to[count].type= ERR_EMPTY; /* End of data */ - DBUG_RETURN(count); + + if (count >= (sizeof(saved_expected_errors.err) / + sizeof(struct st_match_err))) + die("Too many errorcodes specified"); + + /* Set pointer to the end of the last error code */ + p= end; + + /* Find next ',' */ + while (*p && *p != ',') + p++; + + if (*p) + p++; /* Step past ',' */ + + } while (*p); + + command->last_argument= p; + to->type= ERR_EMPTY; /* End of data */ + + DBUG_PRINT("info", ("Expected errors: %d", count)); + saved_expected_errors.count= count; + DBUG_VOID_RETURN; } + /* Get a string; Return ptr to end of string Strings may be surrounded by " or ' @@ -2020,11 +2636,10 @@ static uint get_errcodes(match_err *to,struct st_query *q) If string is a '$variable', return the value of the variable. */ - -static char *get_string(char **to_ptr, char **from_ptr, - struct st_query *q) +char *get_string(char **to_ptr, char **from_ptr, + struct st_command *command) { - reg1 char c,sep; + char c, sep; char *to= *to_ptr, *from= *from_ptr, *start=to; DBUG_ENTER("get_string"); @@ -2070,7 +2685,7 @@ static char *get_string(char **to_ptr, char **from_ptr, *to++=c; } if (*from != ' ' && *from) - die("Wrong string argument in %s", q->query); + die("Wrong string argument in %s", command->query); while (my_isspace(charset_info,*from)) /* Point to next string */ from++; @@ -2093,282 +2708,25 @@ static char *get_string(char **to_ptr, char **from_ptr, DBUG_RETURN(start); } -/* - Finds the next (non-escaped) '/' in the expression. - (If the character '/' is needed, it can be escaped using '\'.) -*/ - -#define PARSE_REGEX_ARG \ - while (p < expr_end) \ - {\ - char c= *p;\ - if (c == '/')\ - {\ - if (last_c == '\\')\ - {\ - buf_p[-1]= '/';\ - }\ - else\ - {\ - *buf_p++ = 0;\ - break;\ - } \ - } \ - else\ - *buf_p++ = c;\ - \ - last_c= c;\ - p++;\ - } \ - -/* - Initializes the regular substitution expression to be used in the - result output of test. - - Returns: st_replace_regex struct with pairs of substitutions -*/ - -static struct st_replace_regex* init_replace_regex(char* expr) -{ - struct st_replace_regex* res; - char* buf,*expr_end; - char* p; - char* buf_p; - uint expr_len= strlen(expr); - char last_c = 0; - struct st_regex reg; - - /* my_malloc() will die on fail with MY_FAE */ - res=(struct st_replace_regex*)my_malloc( - sizeof(*res)+expr_len ,MYF(MY_FAE+MY_WME)); - my_init_dynamic_array(&res->regex_arr,sizeof(struct st_regex),128,128); - - buf= (char*)res + sizeof(*res); - expr_end= expr + expr_len; - p= expr; - buf_p= buf; - - /* for each regexp substitution statement */ - while (p < expr_end) - { - bzero(®,sizeof(reg)); - /* find the start of the statement */ - while (p < expr_end) - { - if (*p == '/') - break; - p++; - } - - if (p == expr_end || ++p == expr_end) - { - if (res->regex_arr.elements) - break; - else - goto err; - } - /* we found the start */ - reg.pattern= buf_p; - - /* Find first argument -- pattern string to be removed */ - PARSE_REGEX_ARG - - if (p == expr_end || ++p == expr_end) - goto err; - - /* buf_p now points to the replacement pattern terminated with \0 */ - reg.replace= buf_p; - - /* Find second argument -- replace string to replace pattern */ - PARSE_REGEX_ARG - - if (p == expr_end) - goto err; - - /* skip the ending '/' in the statement */ - p++; - - /* Check if we should do matching case insensitive */ - if (p < expr_end && *p == 'i') - reg.icase= 1; - - /* done parsing the statement, now place it in regex_arr */ - if (insert_dynamic(&res->regex_arr,(gptr) ®)) - die("Out of memory"); - } - res->odd_buf_len= res->even_buf_len= 8192; - res->even_buf= (char*)my_malloc(res->even_buf_len,MYF(MY_WME+MY_FAE)); - res->odd_buf= (char*)my_malloc(res->odd_buf_len,MYF(MY_WME+MY_FAE)); - res->buf= res->even_buf; - - return res; - -err: - my_free((gptr)res,0); - die("Error parsing replace_regex \"%s\"", expr); - return 0; -} - -/* - Execute all substitutions on val. - - Returns: true if substituition was made, false otherwise - Side-effect: Sets r->buf to be the buffer with all substitutions done. - - IN: - struct st_replace_regex* r - char* val - Out: - struct st_replace_regex* r - r->buf points at the resulting buffer - r->even_buf and r->odd_buf might have been reallocated - r->even_buf_len and r->odd_buf_len might have been changed - - TODO: at some point figure out if there is a way to do everything - in one pass -*/ - -static int multi_reg_replace(struct st_replace_regex* r,char* val) -{ - uint i; - char* in_buf, *out_buf; - int* buf_len_p; - - in_buf= val; - out_buf= r->even_buf; - buf_len_p= &r->even_buf_len; - r->buf= 0; - - /* For each substitution, do the replace */ - for (i= 0; i < r->regex_arr.elements; i++) - { - struct st_regex re; - char* save_out_buf= out_buf; - - get_dynamic(&r->regex_arr,(gptr)&re,i); - - if (!reg_replace(&out_buf, buf_len_p, re.pattern, re.replace, - in_buf, re.icase)) - { - /* if the buffer has been reallocated, make adjustements */ - if (save_out_buf != out_buf) - { - if (save_out_buf == r->even_buf) - r->even_buf= out_buf; - else - r->odd_buf= out_buf; - } - - r->buf= out_buf; - if (in_buf == val) - in_buf= r->odd_buf; - - swap_variables(char*,in_buf,out_buf); - - buf_len_p= (out_buf == r->even_buf) ? &r->even_buf_len : - &r->odd_buf_len; - } - } - - return (r->buf == 0); -} - -/* - Parse the regular expression to be used in all result files - from now on. - - The syntax is --replace_regex /from/to/i /from/to/i ... - i means case-insensitive match. If omitted, the match is - case-sensitive - -*/ -static void get_replace_regex(struct st_query *q) -{ - char *expr= q->first_argument; - free_replace_regex(); - if (!(glob_replace_regex=init_replace_regex(expr))) - die("Could not init replace_regex"); - q->last_argument= q->end; -} - -/* - Get arguments for replace. The syntax is: - replace from to [from to ...] - Where each argument may be quoted with ' or " - A argument may also be a variable, in which case the value of the - variable is replaced. -*/ - -static void get_replace(struct st_query *q) +void set_reconnect(MYSQL* mysql, int val) { - uint i; - char *from= q->first_argument; - char *buff,*start; - char word_end_chars[256],*pos; - POINTER_ARRAY to_array,from_array; - DBUG_ENTER("get_replace"); - - free_replace(); - - bzero((char*) &to_array,sizeof(to_array)); - bzero((char*) &from_array,sizeof(from_array)); - if (!*from) - die("Missing argument in %s", q->query); - start=buff=my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE)); - while (*from) - { - char *to=buff; - to=get_string(&buff, &from, q); - if (!*from) - die("Wrong number of arguments to replace_result in '%s'", q->query); - insert_pointer_name(&from_array,to); - to=get_string(&buff, &from, q); - insert_pointer_name(&to_array,to); - } - for (i=1,pos=word_end_chars ; i < 256 ; i++) - if (my_isspace(charset_info,i)) - *pos++= i; - *pos=0; /* End pointer */ - if (!(glob_replace=init_replace((char**) from_array.typelib.type_names, - (char**) to_array.typelib.type_names, - (uint) from_array.typelib.count, - word_end_chars))) - die("Can't initialize replace from '%s'", q->query); - free_pointer_array(&from_array); - free_pointer_array(&to_array); - my_free(start, MYF(0)); - q->last_argument= q->end; + my_bool reconnect= val; + DBUG_ENTER("set_reconnect"); + DBUG_PRINT("info", ("val: %d", val)); +#if MYSQL_VERSION_ID < 50000 + mysql->reconnect= reconnect; +#else + mysql_options(mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect); +#endif DBUG_VOID_RETURN; } -static void free_replace_regex() -{ - if (glob_replace_regex) - { - my_free(glob_replace_regex->even_buf,MYF(MY_ALLOW_ZERO_PTR)); - my_free(glob_replace_regex->odd_buf,MYF(MY_ALLOW_ZERO_PTR)); - my_free((char*) glob_replace_regex,MYF(0)); - glob_replace_regex=0; - } -} - - -void free_replace() -{ - DBUG_ENTER("free_replace"); - if (glob_replace) - { - my_free((char*) glob_replace,MYF(0)); - glob_replace=0; - } - DBUG_VOID_RETURN; -} -struct connection * find_connection_by_name(const char *name) +struct st_connection * find_connection_by_name(const char *name) { - struct connection *con; - for (con= cons; con < next_con; con++) + struct st_connection *con; + for (con= connections; con < next_con; con++) { if (!strcmp(con->name, name)) { @@ -2390,10 +2748,10 @@ int select_connection_name(const char *name) } -int select_connection(struct st_query *query) +int select_connection(struct st_command *command) { char *name; - char *p= query->first_argument; + char *p= command->first_argument; DBUG_ENTER("select_connection"); if (!*p) @@ -2403,15 +2761,16 @@ int select_connection(struct st_query *query) p++; if (*p) *p++= 0; - query->last_argument= p; + command->last_argument= p; return select_connection_name(name); } -int close_connection(struct st_query *q) +void do_close_connection(struct st_command *command) { - char *p= q->first_argument, *name; - struct connection *con; + char *p= command->first_argument, *name; + struct st_connection *con; + DBUG_ENTER("close_connection"); DBUG_PRINT("enter",("name: '%s'",p)); @@ -2423,13 +2782,17 @@ int close_connection(struct st_query *q) if (*p) *p++= 0; - q->last_argument= p; - for (con= cons; con < next_con; con++) + command->last_argument= p; + + /* Loop through connection pool for connection to close */ + for (con= connections; con < next_con; con++) { + DBUG_PRINT("info", ("con->name: %s", con->name)); if (!strcmp(con->name, name)) { + DBUG_PRINT("info", ("Closing connection %s", con->name)); #ifndef EMBEDDED_LIBRARY - if (q->type == Q_DIRTY_CLOSE) + if (command->type == Q_DIRTY_CLOSE) { if (con->mysql.net.vio) { @@ -2443,59 +2806,19 @@ int close_connection(struct st_query *q) mysql_close(con->util_mysql); con->util_mysql= 0; my_free(con->name, MYF(0)); + /* - When the connection is closed set name to "closed_connection" - to make it possible to reuse the connection name. - The connection slot will not be reused - */ + When the connection is closed set name to "closed_connection" + to make it possible to reuse the connection name. + The connection slot will not be reused + */ if (!(con->name = my_strdup("closed_connection", MYF(MY_WME)))) die("Out of memory"); - DBUG_RETURN(0); + + DBUG_VOID_RETURN; } } die("connection '%s' not found in connection pool", name); - DBUG_RETURN(1); /* Never reached */ -} - - -/* - This one now is a hack - we may want to improve in in the - future to handle quotes. For now we assume that anything that is not - a comma, a space or ) belongs to the argument. space is a chopper, comma or - ) are delimiters/terminators - - SYNOPSIS - safe_get_param - str - string to get param from - arg - pointer to string where result will be stored - msg - Message to display if param is not found - if msg is 0 this param is not required and param may be empty - - RETURNS - pointer to str after param - -*/ - -char* safe_get_param(char *str, char** arg, const char *msg) -{ - DBUG_ENTER("safe_get_param"); - if(!*str) - { - if (msg) - die(msg); - *arg= str; - DBUG_RETURN(str); - } - while (*str && my_isspace(charset_info,*str)) - str++; - *arg= str; - while (*str && *str != ',' && *str != ')') - str++; - if (msg && !*arg) - die(msg); - - *str++= 0; - DBUG_RETURN(str); } @@ -2503,54 +2826,60 @@ char* safe_get_param(char *str, char** arg, const char *msg) Connect to a server doing several retries if needed. SYNOPSIS - safe_connect() - con - connection structure to be used - host, user, pass, - connection parameters - db, port, sock + safe_connect() + con - connection structure to be used + host, user, pass, - connection parameters + db, port, sock NOTE - Sometimes in a test the client starts before - the server - to solve the problem, we try again - after some sleep if connection fails the first - time + Sometimes in a test the client starts before + the server - to solve the problem, we try again + after some sleep if connection fails the first + time - This function will try to connect to the given server - "opt_max_connect_retries" times and sleep "connection_retry_sleep" - seconds between attempts before finally giving up. - This helps in situation when the client starts - before the server (which happens sometimes). - It will ignore any errors during these retries. One should use - connect_n_handle_errors() if he expects a connection error and wants - handle as if it was an error from a usual statement. + This function will try to connect to the given server + "opt_max_connect_retries" times and sleep "connection_retry_sleep" + seconds between attempts before finally giving up. + This helps in situation when the client starts + before the server (which happens sometimes). + It will only ignore connection errors during these retries. - RETURN VALUE - 0 - success, non-0 - failure */ -int safe_connect(MYSQL* mysql, const char *host, const char *user, - const char *pass, const char *db, int port, const char *sock) +void safe_connect(MYSQL* mysql, const char *name, const char *host, + const char *user, const char *pass, const char *db, + int port, const char *sock) { - int con_error= 1; - my_bool reconnect= 1; + int failed_attempts= 0; static ulong connection_retry_sleep= 100000; /* Microseconds */ - int i; - for (i= 0; i < opt_max_connect_retries; i++) + + DBUG_ENTER("safe_connect"); + while(!mysql_real_connect(mysql, host,user, pass, db, port, sock, + CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS)) { - if (mysql_real_connect(mysql, host,user, pass, db, port, sock, - CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS)) + /* + Connect failed + + Only allow retry if this was an error indicating the server + could not be contacted + */ + + if (mysql_errno(mysql) == CR_CONNECTION_ERROR && + failed_attempts < opt_max_connect_retries) + my_sleep(connection_retry_sleep); + else { - con_error= 0; - break; + if (failed_attempts > 0) + die("Could not open connection '%s' after %d attempts: %d %s", name, + failed_attempts, mysql_errno(mysql), mysql_error(mysql)); + else + die("Could not open connection '%s': %d %s", name, + mysql_errno(mysql), mysql_error(mysql)); } - my_sleep(connection_retry_sleep); + failed_attempts++; } - /* - TODO: change this to 0 in future versions, but the 'kill' test relies on - existing behavior - */ - mysql_options(mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect); - return con_error; + DBUG_VOID_RETURN; } @@ -2558,45 +2887,41 @@ int safe_connect(MYSQL* mysql, const char *host, const char *user, Connect to a server and handle connection errors in case they occur. SYNOPSIS - connect_n_handle_errors() - q - context of connect "query" (command) - con - connection structure to be used - host, user, pass, - connection parameters - db, port, sock - create_conn - out parameter, set to zero if connection was - not established and is not touched otherwise + connect_n_handle_errors() + q - context of connect "query" (command) + con - connection structure to be used + host, user, pass, - connection parameters + db, port, sock DESCRIPTION - This function will try to establish a connection to server and handle - possible errors in the same manner as if "connect" was usual SQL-statement - (If error is expected it will ignore it once it occurs and log the - "statement" to the query log). - Unlike safe_connect() it won't do several attempts. + This function will try to establish a connection to server and handle + possible errors in the same manner as if "connect" was usual SQL-statement + (If error is expected it will ignore it once it occurs and log the + "statement" to the query log). + Unlike safe_connect() it won't do several attempts. + + RETURN VALUES + 1 - Connected + 0 - Not connected - RETURN VALUE - 0 - success, non-0 - failure */ -int connect_n_handle_errors(struct st_query *q, MYSQL* con, const char* host, +int connect_n_handle_errors(struct st_command *command, + MYSQL* con, const char* host, const char* user, const char* pass, - const char* db, int port, const char* sock, - int* create_conn) + const char* db, int port, const char* sock) { DYNAMIC_STRING *ds; - my_bool reconnect= 1; - int error= 0; ds= &ds_res; - if (!disable_query_log) + /* Only log if an error is expected */ + if (!command->abort_on_error && + !disable_query_log) { /* - It is nice to have connect() statement logged in result file - in this case. - QQ: Should we do this only if we are expecting an error ? + Log the connect to result log */ - char port_buff[22]; /* This should be enough for any int */ - char *port_end; dynstr_append_mem(ds, "connect(", 8); replace_dynstr_append(ds, host); dynstr_append_mem(ds, ",", 1); @@ -2607,8 +2932,7 @@ int connect_n_handle_errors(struct st_query *q, MYSQL* con, const char* host, if (db) replace_dynstr_append(ds, db); dynstr_append_mem(ds, ",", 1); - port_end= int10_to_str(port, port_buff, 10); - replace_dynstr_append_mem(ds, port_buff, port_end - port_buff); + replace_dynstr_append_uint(ds, port); dynstr_append_mem(ds, ",", 1); if (sock) replace_dynstr_append(ds, sock); @@ -2619,148 +2943,150 @@ int connect_n_handle_errors(struct st_query *q, MYSQL* con, const char* host, if (!mysql_real_connect(con, host, user, pass, db, port, sock ? sock: 0, CLIENT_MULTI_STATEMENTS)) { - handle_error("connect", q, mysql_errno(con), mysql_error(con), + handle_error(command, mysql_errno(con), mysql_error(con), mysql_sqlstate(con), ds); - *create_conn= 0; - goto err; + return 0; /* Not connected */ } - handle_no_error(q); - - /* - TODO: change this to 0 in future versions, but the 'kill' test relies on - existing behavior - */ - mysql_options(con, MYSQL_OPT_RECONNECT, (char *)&reconnect); - -err: - free_replace(); - free_replace_regex(); - return error; + handle_no_error(command); + return 1; /* Connected */ } /* Open a new connection to MySQL Server with the parameters - specified + specified. Make the new connection the current connection. SYNOPSIS - do_connect() - q called command + do_connect() + q called command DESCRIPTION - connect(<name>,<host>,<user>,<pass>,<db>,[<port>,<sock>[<opts>]]); - - <name> - name of the new connection - <host> - hostname of server - <user> - user to connect as - <pass> - password used when connecting - <db> - initial db when connected - <port> - server port - <sock> - server socket - <opts> - options to use for the connection - SSL - use SSL if available - COMPRESS - use compression if available - - */ - -int do_connect(struct st_query *q) -{ - char *con_name, *con_user,*con_pass, *con_host, *con_port_str, - *con_db, *con_sock, *con_options; - char *con_buf, *p; - char buff[FN_REFLEN]; - int con_port; - bool con_ssl= 0; - bool con_compress= 0; - int free_con_sock= 0; - int error= 0; - int create_conn= 1; - VAR *var_port, *var_sock; + connect(<name>,<host>,<user>,[<pass>,[<db>,[<port>,<sock>[<opts>]]]]); + connect <name>,<host>,<user>,[<pass>,[<db>,[<port>,<sock>[<opts>]]]]; + + <name> - name of the new connection + <host> - hostname of server + <user> - user to connect as + <pass> - password used when connecting + <db> - initial db when connected + <port> - server port + <sock> - server socket + <opts> - options to use for the connection + * SSL - use SSL if available + * COMPRESS - use compression if available + +*/ + +void do_connect(struct st_command *command) +{ + int con_port= port; + char *con_options; + bool con_ssl= 0, con_compress= 0; + char *ptr; + + static DYNAMIC_STRING ds_connection_name; + static DYNAMIC_STRING ds_host; + static DYNAMIC_STRING ds_user; + static DYNAMIC_STRING ds_password; + static DYNAMIC_STRING ds_database; + static DYNAMIC_STRING ds_port; + static DYNAMIC_STRING ds_sock; + static DYNAMIC_STRING ds_options; + const struct command_arg connect_args[] = { + "connection name", ARG_STRING, TRUE, &ds_connection_name, + "Name of the connection", + "host", ARG_STRING, TRUE, &ds_host, "Host to connect to", + "user", ARG_STRING, FALSE, &ds_user, "User to connect as", + "passsword", ARG_STRING, FALSE, &ds_password, + "Password used when connecting", + "database", ARG_STRING, FALSE, &ds_database, + "Dtabase to select after connect", + "port", ARG_STRING, FALSE, &ds_port, "Port to connect to", + "socket", ARG_STRING, FALSE, &ds_sock, "Socket to connect with", + "options", ARG_STRING, FALSE, &ds_options, + "Options to use while connecting" + }; DBUG_ENTER("do_connect"); - DBUG_PRINT("enter",("connect: %s", q->first_argument)); - - /* Make a copy of query before parsing, safe_get_param will modify */ - if (!(con_buf= my_strdup(q->first_argument, MYF(MY_WME)))) - die("Could not allocate con_buf"); - p= con_buf; - - if (*p != '(') - die("Syntax error in connect - expected '(' found '%c'", *p); - p++; - p= safe_get_param(p, &con_name, "Missing connection name"); - p= safe_get_param(p, &con_host, "Missing connection host"); - p= safe_get_param(p, &con_user, "Missing connection user"); - p= safe_get_param(p, &con_pass, "Missing connection password"); - p= safe_get_param(p, &con_db, "Missing connection db"); + DBUG_PRINT("enter",("connect: %s", command->first_argument)); - /* Port */ - p= safe_get_param(p, &con_port_str, 0); - if (*con_port_str) + /* Remove parenteses around connect arguments */ + if ((ptr= strstr(command->first_argument, "("))) { - if (*con_port_str == '$') + /* Replace it with a space */ + *ptr= ' '; + if ((ptr= strstr(command->first_argument, ")"))) { - if (!(var_port= var_get(con_port_str, 0, 0, 0))) - die("Unknown variable '%s'", con_port_str+1); - con_port= var_port->int_val; + /* Replace it with \0 */ + *ptr= 0; } else - { - con_port= atoi(con_port_str); - if (con_port == 0) - die("Illegal argument for port: '%s'", con_port_str); - } + die("connect - argument list started with '(' must be ended with ')'"); } - else + + check_command_args(command, command->first_argument, connect_args, + sizeof(connect_args)/sizeof(struct command_arg), + ','); + + /* Port */ + if (ds_port.length) { - con_port= port; + con_port= atoi(ds_port.str); + if (con_port == 0) + die("Illegal argument for port: '%s'", ds_port.str); } /* Sock */ - p= safe_get_param(p, &con_sock, 0); - if (*con_sock) + if (ds_sock.length) { - if (*con_sock == '$') + /* + If the socket is specified just as a name without path + append tmpdir in front + */ + if (*ds_sock.str != FN_LIBCHAR) { - if (!(var_sock= var_get(con_sock, 0, 0, 0))) - die("Unknown variable '%s'", con_sock+1); - if (!(con_sock= (char*)my_malloc(var_sock->str_val_len+1, MYF(0)))) - die("Out of memory"); - free_con_sock= 1; - memcpy(con_sock, var_sock->str_val, var_sock->str_val_len); - con_sock[var_sock->str_val_len]= 0; + char buff[FN_REFLEN]; + fn_format(buff, ds_sock.str, TMPDIR, "", 0); + dynstr_set(&ds_sock, buff); } } else { - con_sock= (char*) unix_sock; + /* No socket specified, use default */ + dynstr_set(&ds_sock, unix_sock); } + DBUG_PRINT("info", ("socket: %s", ds_sock.str)); + /* Options */ - p= safe_get_param(p, &con_options, 0); + con_options= ds_options.str; while (*con_options) { - char* str= con_options; - while (*str && !my_isspace(charset_info, *str)) - str++; - *str++= 0; - if (!strcmp(con_options, "SSL")) + char* end; + /* Step past any spaces in beginning of option*/ + while (*con_options && my_isspace(charset_info, *con_options)) + con_options++; + /* Find end of this option */ + end= con_options; + while (*end && !my_isspace(charset_info, *end)) + end++; + if (!strncmp(con_options, "SSL", 3)) con_ssl= 1; - else if (!strcmp(con_options, "COMPRESS")) + else if (!strncmp(con_options, "COMPRESS", 8)) con_compress= 1; else - die("Illegal option to connect: %s", con_options); - con_options= str; + die("Illegal option to connect: %.*s", end - con_options, con_options); + /* Process next option */ + con_options= end; } - /* Note: 'p' is pointing into the copy 'con_buf' */ - q->last_argument= q->first_argument + (p - con_buf); - if (next_con == cons_end) - die("Connection limit exhausted - increase MAX_CONS in mysqltest.c"); + if (next_con == connections_end) + die("Connection limit exhausted, you can have max %d connections", + (sizeof(connections)/sizeof(struct st_connection))); - if (find_connection_by_name(con_name)) - die("Connection %s already exists", con_name); + if (find_connection_by_name(ds_connection_name.str)) + die("Connection %s already exists", ds_connection_name.str); if (!mysql_init(&next_con->mysql)) die("Failed on mysql_init()"); @@ -2772,53 +3098,56 @@ int do_connect(struct st_query *q) #ifdef HAVE_OPENSSL if (opt_use_ssl || con_ssl) { - /* Turn on ssl_verify_server_cert only if host is "localhost" */ - opt_ssl_verify_server_cert= !strcmp(con_host, "localhost"); - mysql_ssl_set(&next_con->mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); +#if MYSQL_VERSION_ID >= 50000 + /* Turn on ssl_verify_server_cert only if host is "localhost" */ + opt_ssl_verify_server_cert= !strcmp(ds_connection_name.str, "localhost"); mysql_options(&next_con->mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &opt_ssl_verify_server_cert); +#endif } #endif - if (con_sock && !free_con_sock && *con_sock && *con_sock != FN_LIBCHAR) - con_sock=fn_format(buff, con_sock, TMPDIR, "", 0); - if (!con_db[0]) - con_db= db; + + /* Use default db name */ + if (ds_database.length == 0) + dynstr_set(&ds_database, db); + /* Special database to allow one to connect without a database name */ - if (con_db && !strcmp(con_db,"*NO-ONE*")) - con_db= 0; - if (q->abort_on_error) - { - if (safe_connect(&next_con->mysql, con_host, con_user, con_pass, - con_db, con_port, con_sock ? con_sock: 0)) - die("Could not open connection '%s': %d %s", con_name, - mysql_errno(&next_con->mysql), mysql_error(&next_con->mysql)); - } - else - error= connect_n_handle_errors(q, &next_con->mysql, con_host, con_user, - con_pass, con_db, con_port, con_sock, - &create_conn); + if (ds_database.length && !strcmp(ds_database.str,"*NO-ONE*")) + dynstr_set(&ds_database, ""); - if (create_conn) + + if (connect_n_handle_errors(command, &next_con->mysql, + ds_host.str,ds_user.str, + ds_password.str, ds_database.str, + con_port, ds_sock.str)) { - if (!(next_con->name= my_strdup(con_name, MYF(MY_WME)))) - die(NullS); + DBUG_PRINT("info", ("Inserting connection %s in connection pool", + ds_connection_name.str)); + if (!(next_con->name= my_strdup(ds_connection_name.str, MYF(MY_WME)))) + die("Out of memory"); cur_con= next_con++; } - if (free_con_sock) - my_free(con_sock, MYF(MY_WME)); - my_free(con_buf, MYF(MY_WME)); - DBUG_RETURN(error); + + dynstr_free(&ds_connection_name); + dynstr_free(&ds_host); + dynstr_free(&ds_user); + dynstr_free(&ds_password); + dynstr_free(&ds_database); + dynstr_free(&ds_port); + dynstr_free(&ds_sock); + dynstr_free(&ds_options); + DBUG_VOID_RETURN; } -int do_done(struct st_query *q) +int do_done(struct st_command *command) { /* Check if empty block stack */ if (cur_block == block_stack) { - if (*q->query != '}') + if (*command->query != '}') die("Stray 'end' command - end of block before beginning"); die("Stray '}' - end of block before beginning"); } @@ -2844,31 +3173,31 @@ int do_done(struct st_query *q) Process start of a "if" or "while" statement SYNOPSIS - do_block() - cmd Type of block - q called command + do_block() + cmd Type of block + q called command DESCRIPTION - if ([!]<expr>) - { - <block statements> - } + if ([!]<expr>) + { + <block statements> + } - while ([!]<expr>) - { - <block statements> - } + while ([!]<expr>) + { + <block statements> + } - Evaluates the <expr> and if it evaluates to - greater than zero executes the following code block. - A '!' can be used before the <expr> to indicate it should - be executed if it evaluates to zero. + Evaluates the <expr> and if it evaluates to + greater than zero executes the following code block. + A '!' can be used before the <expr> to indicate it should + be executed if it evaluates to zero. - */ +*/ -void do_block(enum block_cmd cmd, struct st_query* q) +void do_block(enum block_cmd cmd, struct st_command* command) { - char *p= q->first_argument; + char *p= command->first_argument; const char *expr_start, *expr_end; VAR v; const char *cmd_name= (cmd == cmd_while ? "while" : "if"); @@ -2912,9 +3241,7 @@ void do_block(enum block_cmd cmd, struct st_query* q) while (*p && my_isspace(charset_info, *p)) p++; - if (*p == '{') - die("Missing newline between %s and '{'", cmd_name); - if (*p) + if (*p && *p != '{') die("Missing '{' after %s. Found \"%s\"", cmd_name, p); var_init(&v,0,0,0,0); @@ -2935,43 +3262,41 @@ void do_block(enum block_cmd cmd, struct st_query* q) } -/* - Read characters from line buffer or file. This is needed to allow - my_ungetc() to buffer MAX_DELIMITER characters for a file +void do_delimiter(struct st_command* command) +{ + char* p= command->first_argument; + DBUG_ENTER("do_delimiter"); + DBUG_PRINT("enter", ("first_argument: %s", command->first_argument)); - NOTE: - This works as long as one doesn't change files (with 'source file_name') - when there is things pushed into the buffer. This should however not - happen for any tests in the test suite. -*/ + while (*p && my_isspace(charset_info, *p)) + p++; -int my_getc(FILE *file) -{ - if (line_buffer_pos == line_buffer) - return fgetc(file); - return *--line_buffer_pos; -} + if (!(*p)) + die("Can't set empty delimiter"); -void my_ungetc(int c) -{ - *line_buffer_pos++= (char) c; + strmake(delimiter, p, sizeof(delimiter) - 1); + delimiter_length= strlen(delimiter); + + DBUG_PRINT("exit", ("delimiter: %s", delimiter)); + command->last_argument= p + delimiter_length; + DBUG_VOID_RETURN; } -my_bool end_of_query(int c) +my_bool match_delimiter(int c, const char *delim, uint length) { uint i; - char tmp[MAX_DELIMITER]; + char tmp[MAX_DELIMITER_LENGTH]; - if (c != *delimiter) + if (c != *delim) return 0; - for (i= 1; i < delimiter_length && - (c= my_getc(cur_file->file)) == *(delimiter + i); + for (i= 1; i < length && + (c= my_getc(cur_file->file)) == *(delim + i); i++) tmp[i]= c; - if (i == delimiter_length) + if (i == length) return 1; /* Found delimiter */ /* didn't find delimiter, push back things that we read */ @@ -2982,45 +3307,51 @@ my_bool end_of_query(int c) } +my_bool end_of_query(int c) +{ + return match_delimiter(c, delimiter, delimiter_length); +} + + /* Read one "line" from the file SYNOPSIS - read_line - buf buffer for the read line - size size of the buffer i.e max size to read + read_line + buf buffer for the read line + size size of the buffer i.e max size to read DESCRIPTION - This function actually reads several lines and adds them to the - buffer buf. It continues to read until it finds what it believes - is a complete query. + This function actually reads several lines and adds them to the + buffer buf. It continues to read until it finds what it believes + is a complete query. - Normally that means it will read lines until it reaches the - "delimiter" that marks end of query. Default delimiter is ';' - The function should be smart enough not to detect delimiter's - found inside strings surrounded with '"' and '\'' escaped strings. + Normally that means it will read lines until it reaches the + "delimiter" that marks end of query. Default delimiter is ';' + The function should be smart enough not to detect delimiter's + found inside strings surrounded with '"' and '\'' escaped strings. - If the first line in a query starts with '#' or '-' this line is treated - as a comment. A comment is always terminated when end of line '\n' is - reached. + If the first line in a query starts with '#' or '-' this line is treated + as a comment. A comment is always terminated when end of line '\n' is + reached. */ int read_line(char *buf, int size) { - int c; - char quote; + char c, last_quote; char *p= buf, *buf_end= buf + size - 1; - int no_save= 0; - enum {R_NORMAL, R_Q, R_Q_IN_Q, R_SLASH_IN_Q, - R_COMMENT, R_LINE_START} state= R_LINE_START; + int skip_char= 0; + enum {R_NORMAL, R_Q, R_SLASH_IN_Q, + R_COMMENT, R_LINE_START} state= R_LINE_START; DBUG_ENTER("read_line"); - LINT_INIT(quote); + LINT_INIT(last_quote); start_lineno= cur_file->lineno; + DBUG_PRINT("info", ("Starting to read at lineno: %d", start_lineno)); for (; p < buf_end ;) { - no_save= 0; + skip_char= 0; c= my_getc(cur_file->file); if (feof(cur_file->file)) { @@ -3036,12 +3367,13 @@ int read_line(char *buf, int size) { /* We're back at the first file, check if all { have matching } - */ + */ if (cur_block != block_stack) die("Missing end of block"); - DBUG_PRINT("info", ("end of file")); - DBUG_RETURN(1); + *p= 0; + DBUG_PRINT("info", ("end of file at line %d", cur_file->lineno)); + DBUG_RETURN(1); } cur_file--; start_lineno= cur_file->lineno; @@ -3055,61 +3387,86 @@ int read_line(char *buf, int size) /* Convert cr/lf to lf */ if (p != buf && *(p-1) == '\r') - *(p-1)= 0; + p--; } switch(state) { case R_NORMAL: - /* Only accept '{' in the beginning of a line */ if (end_of_query(c)) { *p= 0; + DBUG_PRINT("exit", ("Found delimiter '%s' at line %d", + delimiter, cur_file->lineno)); DBUG_RETURN(0); } - else if (c == '\'' || c == '"' || c == '`') + else if ((c == '{' && + (!my_strnncoll_simple(charset_info, "while", 5, + buf, min(5, p - buf), 0) || + !my_strnncoll_simple(charset_info, "if", 2, + buf, min(2, p - buf), 0)))) { - quote= c; - state= R_Q; + /* Only if and while commands can be terminated by { */ + *p++= c; + *p= 0; + DBUG_PRINT("exit", ("Found '{' indicating start of block at line %d", + cur_file->lineno)); + DBUG_RETURN(0); } - else if (c == '\n') + else if (c == '\'' || c == '"' || c == '`') { - state = R_LINE_START; + last_quote= c; + state= R_Q; } break; + case R_COMMENT: if (c == '\n') { + /* Comments are terminated by newline */ *p= 0; + DBUG_PRINT("exit", ("Found newline in comment at line: %d", + cur_file->lineno)); DBUG_RETURN(0); } break; + case R_LINE_START: - /* Only accept start of comment if this is the first line in query */ - if ((cur_file->lineno == start_lineno) && - (c == '#' || c == '-' || parsing_disabled)) + if (c == '#' || c == '-') { + /* A # or - in the first position of the line - this is a comment */ state = R_COMMENT; } else if (my_isspace(charset_info, c)) { + /* Skip all space at begining of line */ if (c == '\n') - start_lineno= cur_file->lineno; /* Query hasn't started yet */ - no_save= 1; + { + /* Query hasn't started yet */ + start_lineno= cur_file->lineno; + DBUG_PRINT("info", ("Query hasn't started yet, start_lineno: %d", + start_lineno)); + } + skip_char= 1; } - else if (c == '}') + else if (end_of_query(c)) { - *buf++= '}'; - *buf= 0; + *p= 0; + DBUG_PRINT("exit", ("Found delimiter '%s' at line: %d", + delimiter, cur_file->lineno)); DBUG_RETURN(0); } - else if (end_of_query(c) || c == '{') + else if (c == '}') { + /* A "}" need to be by itself in the begining of a line to terminate */ + *p++= c; *p= 0; + DBUG_PRINT("exit", ("Found '}' in begining of a line at line: %d", + cur_file->lineno)); DBUG_RETURN(0); } else if (c == '\'' || c == '"' || c == '`') { - quote= c; + last_quote= c; state= R_Q; } else @@ -3117,29 +3474,19 @@ int read_line(char *buf, int size) break; case R_Q: - if (c == quote) - state= R_Q_IN_Q; + if (c == last_quote) + state= R_NORMAL; else if (c == '\\') state= R_SLASH_IN_Q; break; - case R_Q_IN_Q: - if (end_of_query(c)) - { - *p= 0; - DBUG_RETURN(0); - } - if (c != quote) - state= R_NORMAL; - else - state= R_Q; - break; + case R_SLASH_IN_Q: state= R_Q; break; } - if (!no_save) + if (!skip_char) { /* Could be a multibyte character */ /* This code is based on the code in "sql_load.cc" */ @@ -3157,7 +3504,7 @@ int read_line(char *buf, int size) for (i= 1; i < charlen; i++) { if (feof(cur_file->file)) - goto found_eof; /* FIXME: could we just break here?! */ + goto found_eof; c= my_getc(cur_file->file); *p++ = c; } @@ -3174,99 +3521,253 @@ int read_line(char *buf, int size) *p++= c; } } - *p= 0; /* Always end with \0 */ - DBUG_RETURN(feof(cur_file->file)); + die("The input buffer is too small for this query.x\n" \ + "check your query or increase MAX_QUERY and recompile"); + DBUG_RETURN(0); } + /* - Create a query from a set of lines + Convert the read query to result format version 1 + + That is: After newline, all spaces need to be skipped + unless the previous char was a quote + + This is due to an old bug that has now been fixed, but the + version 1 output format is preserved by using this function + +*/ + +void convert_to_format_v1(char* query) +{ + int last_c_was_quote= 0; + char *p= query, *write= query; + char *end= strend(query); + char last_c; + + while (p <= end) + { + if (*p == '\n' && !last_c_was_quote) + { + *write++ = *p++; /* Save the newline */ + + /* Skip any spaces on next line */ + while (*p && my_isspace(charset_info, *p)) + p++; + + last_c_was_quote= 0; + } + else if (*p == '\'' || *p == '"' || *p == '`') + { + last_c= *p; + *write++ = *p++; + + /* Copy anything until the next quote of same type */ + while (*p && *p != last_c) + *write++ = *p++; + + *write++ = *p++; + + last_c_was_quote= 1; + } + else + { + *write++ = *p++; + last_c_was_quote= 0; + } + } +} + + +/* + Check a command that is about to be sent (or should have been + sent if parsing was enabled) to mysql server for + suspicious things and generate warnings. +*/ + +void scan_command_for_warnings(struct st_command *command) +{ + const char *ptr= command->query; + DBUG_ENTER("scan_command_for_warnings"); + DBUG_PRINT("enter", ("query: %s", command->query)); + + while(*ptr) + { + /* + Look for query's that lines that start with a -- comment + and has a mysqltest command + */ + if (ptr[0] == '\n' && + ptr[1] && ptr[1] == '-' && + ptr[2] && ptr[2] == '-' && + ptr[3]) + { + uint type; + char save; + char *end, *start= (char*)ptr+3; + /* Skip leading spaces */ + while (*start && my_isspace(charset_info, *start)) + start++; + end= start; + /* Find end of command(next space) */ + while (*end && !my_isspace(charset_info, *end)) + end++; + save= *end; + *end= 0; + DBUG_PRINT("info", ("Checking '%s'", start)); + type= find_type(start, &command_typelib, 1+2); + if (type) + warning_msg("Embedded mysqltest command '--%s' detected in " + "query '%s' was this intentional? ", + start, command->query); + *end= save; + } + + ptr++; + } + DBUG_VOID_RETURN; +} + +/* + Check for unexpected "junk" after the end of query + This is normally caused by missing delimiters or when + switching between different delimiters +*/ + +void check_eol_junk_line(const char *line) +{ + const char *p= line; + DBUG_ENTER("check_eol_junk_line"); + DBUG_PRINT("enter", ("line: %s", line)); + + /* Check for extra delimiter */ + if (*p && !strncmp(p, delimiter, delimiter_length)) + die("Extra delimiter \"%s\" found", delimiter); + + /* Allow trailing # comment */ + if (*p && *p != '#') + { + if (*p == '\n') + die("Missing delimiter"); + die("End of line junk detected: \"%s\"", p); + } + DBUG_VOID_RETURN; +} + +void check_eol_junk(const char *eol) +{ + const char *p= eol; + DBUG_ENTER("check_eol_junk"); + DBUG_PRINT("enter", ("eol: %s", eol)); + + /* Skip past all spacing chars and comments */ + while (*p && (my_isspace(charset_info, *p) || *p == '#' || *p == '\n')) + { + /* Skip past comments started with # and ended with newline */ + if (*p && *p == '#') + { + p++; + while (*p && *p != '\n') + p++; + } + + /* Check this line */ + if (*p && *p == '\n') + check_eol_junk_line(p); + + if (*p) + p++; + } + + check_eol_junk_line(p); + + DBUG_VOID_RETURN; +} + + + +/* + Create a command from a set of lines SYNOPSIS - read_query() - q_ptr pointer where to return the new query + read_command() + command_ptr pointer where to return the new query DESCRIPTION - Converts lines returned by read_line into a query, this involves - parsing the first word in the read line to find the query type. + Converts lines returned by read_line into a command, this involves + parsing the first word in the read line to find the command type. - A -- comment may contain a valid query as the first word after the - comment start. Thus it's always checked to see if that is the case. - The advantage with this approach is to be able to execute commands - terminated by new line '\n' regardless how many "delimiter" it contain. + A -- comment may contain a valid query as the first word after the + comment start. Thus it's always checked to see if that is the case. + The advantage with this approach is to be able to execute commands + terminated by new line '\n' regardless how many "delimiter" it contain. */ -static char read_query_buf[MAX_QUERY]; +#define MAX_QUERY (256*1024) /* 256K -- a test in sp-big is >128K */ +static char read_command_buf[MAX_QUERY]; -int read_query(struct st_query** q_ptr) +int read_command(struct st_command** command_ptr) { - char *p= read_query_buf; - struct st_query* q; - DBUG_ENTER("read_query"); + char *p= read_command_buf; + struct st_command* command; + DBUG_ENTER("read_command"); if (parser.current_line < parser.read_lines) { - get_dynamic(&q_lines, (gptr) q_ptr, parser.current_line) ; + get_dynamic(&q_lines, (gptr) command_ptr, parser.current_line) ; DBUG_RETURN(0); } - if (!(*q_ptr= q= (struct st_query*) my_malloc(sizeof(*q), MYF(MY_WME))) || - insert_dynamic(&q_lines, (gptr) &q)) + if (!(*command_ptr= command= + (struct st_command*) my_malloc(sizeof(*command), MYF(MY_WME))) || + insert_dynamic(&q_lines, (gptr) &command)) die(NullS); - q->record_file[0]= 0; - q->require_file= 0; - q->first_word_len= 0; + command->require_file[0]= 0; + command->first_word_len= 0; + command->query_len= 0; - q->type= Q_UNKNOWN; - q->query_buf= q->query= 0; - read_query_buf[0]= 0; - if (read_line(read_query_buf, sizeof(read_query_buf))) + command->type= Q_UNKNOWN; + command->query_buf= command->query= 0; + read_command_buf[0]= 0; + if (read_line(read_command_buf, sizeof(read_command_buf))) { - check_eol_junk(read_query_buf); + check_eol_junk(read_command_buf); DBUG_RETURN(1); } - - DBUG_PRINT("info", ("query: %s", read_query_buf)); - if (*p == '#') - { - q->type= Q_COMMENT; - /* This goto is to avoid losing the "expected error" info. */ - goto end; - } - if (!parsing_disabled) - { - memcpy((gptr) q->expected_errno, (gptr) global_expected_errno, - sizeof(global_expected_errno)); - q->expected_errors= global_expected_errors; - q->abort_on_error= (global_expected_errors == 0 && abort_on_error); - } - if (p[0] == '-' && p[1] == '-') + convert_to_format_v1(read_command_buf); + + DBUG_PRINT("info", ("query: %s", read_command_buf)); + if (*p == '#') { - q->type= Q_COMMENT_WITH_COMMAND; - p+= 2; /* To calculate first word */ + command->type= Q_COMMENT; } - else if (!parsing_disabled) + else if (p[0] == '-' && p[1] == '-') { - while (*p && my_isspace(charset_info, *p)) - p++ ; + command->type= Q_COMMENT_WITH_COMMAND; + p+= 2; /* Skip past -- */ } -end: + /* Skip leading spaces */ while (*p && my_isspace(charset_info, *p)) p++; - if (!(q->query_buf= q->query= my_strdup(p, MYF(MY_WME)))) - die(NullS); + if (!(command->query_buf= command->query= my_strdup(p, MYF(MY_WME)))) + die("Out of memory"); /* Calculate first word and first argument */ - for (p= q->query; *p && !my_isspace(charset_info, *p) ; p++) ; - q->first_word_len= (uint) (p - q->query); + for (p= command->query; *p && !my_isspace(charset_info, *p) ; p++) ; + command->first_word_len= (uint) (p - command->query); + + /* Skip spaces between command and first argument */ while (*p && my_isspace(charset_info, *p)) p++; - q->first_argument= p; - q->end= strend(q->query); + command->first_argument= p; + + command->end= strend(command->query); + command->query_len= (command->end - command->query); parser.read_lines++; DBUG_RETURN(0); } @@ -3278,8 +3779,6 @@ static struct my_option my_long_options[] = 0, 0, 0, 0, 0, 0}, {"basedir", 'b', "Basedir for tests.", (gptr*) &opt_basedir, (gptr*) &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"big-test", 'B', "Define BIG_TEST to 1.", (gptr*) &opt_big_test, - (gptr*) &opt_big_test, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"compress", 'C', "Use the compressed server/client protocol.", (gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -3319,8 +3818,8 @@ static struct my_option my_long_options[] = {"record", 'r', "Record output of test_file into result file.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"result-file", 'R', "Read/Store result from/in this file.", - (gptr*) &result_file, (gptr*) &result_file, 0, GET_STR, REQUIRED_ARG, - 0, 0, 0, 0, 0, 0}, + (gptr*) &result_file_name, (gptr*) &result_file_name, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"server-arg", 'A', "Send option value to embedded server as a parameter.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"server-file", 'F', "Read embedded server arguments from file.", @@ -3348,8 +3847,6 @@ static struct my_option my_long_options[] = 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"user", 'u', "User for login.", (gptr*) &user, (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"valgrind", 'N', "Define VALGRIND_TEST to 1.", (gptr*) &opt_valgrind_test, - (gptr*) &opt_valgrind_test, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"verbose", 'v', "Write more.", (gptr*) &verbose, (gptr*) &verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit.", @@ -3363,7 +3860,7 @@ static struct my_option my_long_options[] = #include <help_start.h> -static void print_version(void) +void print_version(void) { printf("%s Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION, MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE); @@ -3384,6 +3881,52 @@ void usage() #include <help_end.h> +/* + Read arguments for embedded server and put them into + embedded_server_args[] +*/ + +void read_embedded_server_arguments(const char *name) +{ + char argument[1024],buff[FN_REFLEN], *str=0; + FILE *file; + + if (!test_if_hard_path(name)) + { + strxmov(buff, opt_basedir, name, NullS); + name=buff; + } + fn_format(buff, name, "", "", MY_UNPACK_FILENAME); + + if (!embedded_server_arg_count) + { + embedded_server_arg_count=1; + embedded_server_args[0]= (char*) ""; /* Progname */ + } + if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME)))) + die("Failed to open file %s", buff); + + while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS && + (str=fgets(argument,sizeof(argument), file))) + { + *(strend(str)-1)=0; /* Remove end newline */ + if (!(embedded_server_args[embedded_server_arg_count]= + (char*) my_strdup(str,MYF(MY_WME)))) + { + my_fclose(file,MYF(0)); + die("Out of memory"); + + } + embedded_server_arg_count++; + } + my_fclose(file,MYF(0)); + if (str) + die("Too many arguments in option file: %s",name); + + return; +} + + static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) @@ -3398,35 +3941,35 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), record = 1; break; case 'x': + { + char buff[FN_REFLEN]; + if (!test_if_hard_path(argument)) { - char buff[FN_REFLEN]; - if (!test_if_hard_path(argument)) - { - strxmov(buff, opt_basedir, argument, NullS); - argument= buff; - } - fn_format(buff, argument, "", "", MY_UNPACK_FILENAME); - DBUG_ASSERT(cur_file == file_stack && cur_file->file == 0); - if (!(cur_file->file= - my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0)))) - die("Could not open %s: errno = %d", buff, errno); - cur_file->file_name= my_strdup(buff, MYF(MY_FAE)); - cur_file->lineno= 1; - break; + strxmov(buff, opt_basedir, argument, NullS); + argument= buff; } + fn_format(buff, argument, "", "", MY_UNPACK_FILENAME); + DBUG_ASSERT(cur_file == file_stack && cur_file->file == 0); + if (!(cur_file->file= + my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0)))) + die("Could not open %s: errno = %d", buff, errno); + cur_file->file_name= my_strdup(buff, MYF(MY_FAE)); + cur_file->lineno= 1; + break; + } case 'm': + { + static char buff[FN_REFLEN]; + if (!test_if_hard_path(argument)) { - static char buff[FN_REFLEN]; - if (!test_if_hard_path(argument)) - { - strxmov(buff, opt_basedir, argument, NullS); - argument= buff; - } - fn_format(buff, argument, "", "", MY_UNPACK_FILENAME); - timer_file= buff; - unlink(timer_file); /* Ignore error, may not exist */ - break; + strxmov(buff, opt_basedir, argument, NullS); + argument= buff; } + fn_format(buff, argument, "", "", MY_UNPACK_FILENAME); + timer_file= buff; + unlink(timer_file); /* Ignore error, may not exist */ + break; + } case 'p': if (argument) { @@ -3448,7 +3991,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), embedded_server_arg_count=1; embedded_server_args[0]= (char*) ""; } - if (embedded_server_arg_count == MAX_SERVER_ARGS-1 || + if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 || !(embedded_server_args[embedded_server_arg_count++]= my_strdup(argument, MYF(MY_FAE)))) { @@ -3456,8 +3999,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), } break; case 'F': - if (read_server_arguments(argument)) - die(NullS); + read_embedded_server_arguments(argument); break; case OPT_SKIP_SAFEMALLOC: #ifdef SAFEMALLOC @@ -3498,16 +4040,16 @@ int parse_args(int argc, char **argv) /* - Write the content of str into file + Write the content of str into file - SYNOPSIS - str_to_file - fname - name of file to truncate/create and write to - str - content to write to file - size - size of content witten to file + SYNOPSIS + str_to_file + fname - name of file to truncate/create and write to + str - content to write to file + size - size of content witten to file */ -static void str_to_file(const char *fname, char *str, int size) +void str_to_file(const char *fname, char *str, int size) { int fd; char buff[FN_REFLEN]; @@ -3519,7 +4061,7 @@ static void str_to_file(const char *fname, char *str, int size) fn_format(buff, fname, "", "", MY_UNPACK_FILENAME); if ((fd= my_open(buff, O_WRONLY | O_CREAT | O_TRUNC, - MYF(MY_WME | MY_FFNF))) < 0) + MYF(MY_WME | MY_FFNF))) < 0) die("Could not open %s: errno = %d", buff, errno); if (my_write(fd, (byte*)str, size, MYF(MY_WME|MY_FNABP))) die("write failed"); @@ -3527,236 +4069,48 @@ static void str_to_file(const char *fname, char *str, int size) } -void dump_result_to_reject_file(const char *record_file, char *buf, int size) +void dump_result_to_reject_file(char *buf, int size) { char reject_file[FN_REFLEN]; - str_to_file(fn_format(reject_file, record_file, "", ".reject", + str_to_file(fn_format(reject_file, result_file_name, "", ".reject", MY_REPLACE_EXT), buf, size); } -void dump_result_to_log_file(const char *record_file, char *buf, int size) +void dump_result_to_log_file(char *buf, int size) { char log_file[FN_REFLEN]; - str_to_file(fn_format(log_file, record_file, "", ".log", + str_to_file(fn_format(log_file, result_file_name, "", ".log", MY_REPLACE_EXT), buf, size); } -void dump_progress(const char *record_file) +void dump_progress(void) { char log_file[FN_REFLEN]; - str_to_file(fn_format(log_file, record_file, "", ".progress", + str_to_file(fn_format(log_file, result_file_name, "", ".progress", MY_REPLACE_EXT), ds_progress.str, ds_progress.length); } -static void check_regerr(my_regex_t* r, int err) +void dump_warning_messages(void) { - char err_buf[1024]; + char warn_file[FN_REFLEN]; - if (err) - { - my_regerror(err,r,err_buf,sizeof(err_buf)); - die("Regex error: %s\n", err_buf); - } + str_to_file(fn_format(warn_file, result_file_name, "", ".warnings", + MY_REPLACE_EXT), + ds_warning_messages.str, ds_warning_messages.length); } -/* - auxiluary macro used by reg_replace - makes sure the result buffer has sufficient length -*/ -#define SECURE_REG_BUF if (buf_len < need_buf_len)\ - {\ - int off= res_p - buf;\ - buf= (char*)my_realloc(buf,need_buf_len,MYF(MY_WME+MY_FAE));\ - res_p= buf + off;\ - buf_len= need_buf_len;\ - }\ - -/* - Performs a regex substitution - - IN: - - buf_p - result buffer pointer. Will change if reallocated - buf_len_p - result buffer length. Will change if the buffer is reallocated - pattern - regexp pattern to match - replace - replacement expression - string - the string to perform substituions in - icase - flag, if set to 1 the match is case insensitive - */ -static int reg_replace(char** buf_p, int* buf_len_p, char *pattern, - char *replace, char *string, int icase) +void check_regerr(my_regex_t* r, int err) { - my_regex_t r; - my_regmatch_t* subs; - char* buf_end, *replace_end; - char* buf= *buf_p; - int len; - int buf_len,need_buf_len; - int cflags= REG_EXTENDED; - int err_code; - char* res_p,*str_p,*str_end; - - buf_len= *buf_len_p; - len= strlen(string); - str_end= string + len; - - /* start with a buffer of a reasonable size that hopefully will not - need to be reallocated - */ - need_buf_len= len * 2 + 1; - res_p= buf; + char err_buf[1024]; - SECURE_REG_BUF - - buf_end = buf + buf_len; - - if (icase) - cflags |= REG_ICASE; - - if ((err_code=my_regcomp(&r,pattern,cflags,&my_charset_latin1))) - { - check_regerr(&r,err_code); - return 1; - } - - subs= (my_regmatch_t*)my_malloc(sizeof(my_regmatch_t) * (r.re_nsub+1), - MYF(MY_WME+MY_FAE)); - - *res_p= 0; - str_p= string; - replace_end= replace + strlen(replace); - - /* for each pattern match instance perform a replacement */ - while (!err_code) + if (err) { - /* find the match */ - err_code= my_regexec(&r,str_p, r.re_nsub+1, subs, - (str_p == string) ? REG_NOTBOL : 0); - - /* if regular expression error (eg. bad syntax, or out of memory) */ - if (err_code && err_code != REG_NOMATCH) - { - check_regerr(&r,err_code); - my_regfree(&r); - return 1; - } - - /* if match found */ - if (!err_code) - { - char* expr_p= replace; - int c; - - /* - we need at least what we have so far in the buffer + the part - before this match - */ - need_buf_len= (res_p - buf) + subs[0].rm_so; - - /* on this pass, calculate the memory for the result buffer */ - while (expr_p < replace_end) - { - int back_ref_num= -1; - c= *expr_p; - - if (c == '\\' && expr_p + 1 < replace_end) - { - back_ref_num= expr_p[1] - '0'; - } - - /* found a valid back_ref (eg. \1)*/ - if (back_ref_num >= 0 && back_ref_num <= (int)r.re_nsub) - { - int start_off,end_off; - if ((start_off=subs[back_ref_num].rm_so) > -1 && - (end_off=subs[back_ref_num].rm_eo) > -1) - { - need_buf_len += (end_off - start_off); - } - expr_p += 2; - } - else - { - expr_p++; - need_buf_len++; - } - } - need_buf_len++; - /* - now that we know the size of the buffer, - make sure it is big enough - */ - SECURE_REG_BUF - - /* copy the pre-match part */ - if (subs[0].rm_so) - { - memcpy(res_p,str_p,subs[0].rm_so); - res_p += subs[0].rm_so; - } - - expr_p= replace; - - /* copy the match and expand back_refs */ - while (expr_p < replace_end) - { - int back_ref_num= -1; - c= *expr_p; - - if (c == '\\' && expr_p + 1 < replace_end) - { - back_ref_num= expr_p[1] - '0'; - } - - if (back_ref_num >= 0 && back_ref_num <= (int)r.re_nsub) - { - int start_off,end_off; - if ((start_off=subs[back_ref_num].rm_so) > -1 && - (end_off=subs[back_ref_num].rm_eo) > -1) - { - int block_len= end_off - start_off; - memcpy(res_p,str_p + start_off, block_len); - res_p += block_len; - } - expr_p += 2; - } - else - { - *res_p++ = *expr_p++; - } - } - - /* handle the post-match part */ - if (subs[0].rm_so == subs[0].rm_eo) - { - if (str_p + subs[0].rm_so >= str_end) - break; - str_p += subs[0].rm_eo ; - *res_p++ = *str_p++; - } - else - { - str_p += subs[0].rm_eo; - } - } - else /* no match this time, just copy the string as is */ - { - int left_in_str= str_end-str_p; - need_buf_len= (res_p-buf) + left_in_str; - SECURE_REG_BUF - memcpy(res_p,str_p,left_in_str); - res_p += left_in_str; - str_p= str_end; - } - } - my_regfree(&r); - *res_p= 0; - *buf_p= buf; - *buf_len_p= buf_len; - return 0; + my_regerror(err,r,err_buf,sizeof(err_buf)); + die("Regex error: %s\n", err_buf); + } } @@ -3768,12 +4122,12 @@ DYNAMIC_ARRAY patterns; init_win_path_patterns DESCRIPTION - Setup string patterns that will be used to detect filenames that - needs to be converted from Win to Unix format + Setup string patterns that will be used to detect filenames that + needs to be converted from Win to Unix format */ -static void init_win_path_patterns() +void init_win_path_patterns() { /* List of string patterns to match in order to find paths */ const char* paths[] = { "$MYSQL_TEST_DIR", @@ -3800,7 +4154,7 @@ static void init_win_path_patterns() p= my_strdup(paths[i], MYF(MY_FAE)); if (insert_dynamic(&patterns, (gptr) &p)) - die(NullS); + die(NullS); DBUG_PRINT("info", ("p: %s", p)); while (*p) @@ -3813,7 +4167,7 @@ static void init_win_path_patterns() DBUG_VOID_RETURN; } -static void free_win_path_patterns() +void free_win_path_patterns() { uint i= 0; for (i=0 ; i < patterns.elements ; i++) @@ -3828,17 +4182,17 @@ static void free_win_path_patterns() fix_win_paths DESCRIPTION - Search the string 'val' for the patterns that are known to be - strings that contain filenames. Convert all \ to / in the - filenames that are found. - - Ex: - val = 'Error "c:\mysql\mysql-test\var\test\t1.frm" didn't exist' - => $MYSQL_TEST_DIR is found by strstr - => all \ from c:\mysql\m... until next space is converted into / + Search the string 'val' for the patterns that are known to be + strings that contain filenames. Convert all \ to / in the + filenames that are found. + + Ex: + val = 'Error "c:\mysql\mysql-test\var\test\t1.frm" didn't exist' + => $MYSQL_TEST_DIR is found by strstr + => all \ from c:\mysql\m... until next space is converted into / */ -static void fix_win_paths(const char* val, int len) +void fix_win_paths(const char *val, int len) { uint i; char *p; @@ -3868,43 +4222,14 @@ static void fix_win_paths(const char* val, int len) } #endif -/* Append the string to ds, with optional replace */ -static void replace_dynstr_append_mem(DYNAMIC_STRING *ds, - const char *val, int len) -{ -#ifdef __WIN__ - fix_win_paths(val, len); -#endif - - if (glob_replace_regex) - { - if (!multi_reg_replace(glob_replace_regex, (char*)val)) - { - val= glob_replace_regex->buf; - len= strlen(val); - } - } - - if (glob_replace) - replace_strings_append(glob_replace, ds, val, len); - else - dynstr_append_mem(ds, val, len); -} - - -/* Append zero-terminated string to ds, with optional replace */ -static void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val) -{ - replace_dynstr_append_mem(ds, val, strlen(val)); -} /* Append the result for one field to the dynamic string ds */ -static void append_field(DYNAMIC_STRING *ds, uint col_idx, MYSQL_FIELD* field, - const char* val, ulonglong len, bool is_null) +void append_field(DYNAMIC_STRING *ds, uint col_idx, MYSQL_FIELD* field, + const char* val, ulonglong len, bool is_null) { if (col_idx < max_replace_column && replace_column[col_idx]) { @@ -3955,7 +4280,7 @@ static void append_field(DYNAMIC_STRING *ds, uint col_idx, MYSQL_FIELD* field, Values may be converted with 'replace_column' */ -static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) +void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) { MYSQL_ROW row; uint num_fields= mysql_num_fields(res); @@ -3972,7 +4297,6 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) if (!display_result_vertically) dynstr_append_mem(ds, "\n", 1); } - free_replace_column(); } @@ -3981,8 +4305,8 @@ static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res) with '\t'. Values may be converted with 'replace_column' */ -static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, - MYSQL_FIELD *fields, uint num_fields) +void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, + MYSQL_FIELD *fields, uint num_fields) { MYSQL_BIND *bind; my_bool *is_null; @@ -4007,7 +4331,7 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, bind[i].is_null= &is_null[i]; bind[i].length= &length[i]; - DBUG_PRINT("bind", ("col[%d]: buffer_type: %d, buffer_length: %d", + DBUG_PRINT("bind", ("col[%d]: buffer_type: %d, buffer_length: %lu", i, bind[i].buffer_type, bind[i].buffer_length)); } @@ -4028,8 +4352,6 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, die("fetch didn't end with MYSQL_NO_DATA from statement: %d %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); - free_replace_column(); - for (i= 0; i < num_fields; i++) { /* Free data for output */ @@ -4046,9 +4368,9 @@ static void append_stmt_result(DYNAMIC_STRING *ds, MYSQL_STMT *stmt, Append metadata for fields to output */ -static void append_metadata(DYNAMIC_STRING *ds, - MYSQL_FIELD *field, - uint num_fields) +void append_metadata(DYNAMIC_STRING *ds, + MYSQL_FIELD *field, + uint num_fields) { MYSQL_FIELD *field_end; dynstr_append(ds,"Catalog\tDatabase\tTable\tTable_alias\tColumn\t" @@ -4059,44 +4381,36 @@ static void append_metadata(DYNAMIC_STRING *ds, field < field_end ; field++) { - char buff[22]; dynstr_append_mem(ds, field->catalog, - field->catalog_length); + field->catalog_length); dynstr_append_mem(ds, "\t", 1); dynstr_append_mem(ds, field->db, field->db_length); dynstr_append_mem(ds, "\t", 1); dynstr_append_mem(ds, field->org_table, - field->org_table_length); + field->org_table_length); dynstr_append_mem(ds, "\t", 1); dynstr_append_mem(ds, field->table, - field->table_length); + field->table_length); dynstr_append_mem(ds, "\t", 1); dynstr_append_mem(ds, field->org_name, - field->org_name_length); + field->org_name_length); dynstr_append_mem(ds, "\t", 1); dynstr_append_mem(ds, field->name, field->name_length); dynstr_append_mem(ds, "\t", 1); - int10_to_str((int) field->type, buff, 10); - dynstr_append(ds, buff); + replace_dynstr_append_uint(ds, field->type); dynstr_append_mem(ds, "\t", 1); - longlong10_to_str((unsigned int) field->length, buff, 10); - dynstr_append(ds, buff); + replace_dynstr_append_uint(ds, field->length); dynstr_append_mem(ds, "\t", 1); - longlong10_to_str((unsigned int) field->max_length, buff, 10); - dynstr_append(ds, buff); + replace_dynstr_append_uint(ds, field->max_length); dynstr_append_mem(ds, "\t", 1); dynstr_append_mem(ds, (char*) (IS_NOT_NULL(field->flags) ? "N" : "Y"), 1); dynstr_append_mem(ds, "\t", 1); - - int10_to_str((int) field->flags, buff, 10); - dynstr_append(ds, buff); + replace_dynstr_append_uint(ds, field->flags); dynstr_append_mem(ds, "\t", 1); - int10_to_str((int) field->decimals, buff, 10); - dynstr_append(ds, buff); + replace_dynstr_append_uint(ds, field->decimals); dynstr_append_mem(ds, "\t", 1); - int10_to_str((int) field->charsetnr, buff, 10); - dynstr_append(ds, buff); + replace_dynstr_append_uint(ds, field->charsetnr); dynstr_append_mem(ds, "\n", 1); } } @@ -4106,8 +4420,8 @@ static void append_metadata(DYNAMIC_STRING *ds, Append affected row count and other info to output */ -static void append_info(DYNAMIC_STRING *ds, ulonglong affected_rows, - const char *info) +void append_info(DYNAMIC_STRING *ds, ulonglong affected_rows, + const char *info) { char buf[40], buff2[21]; sprintf(buf,"affected rows: %s\n", llstr(affected_rows, buff2)); @@ -4122,12 +4436,12 @@ static void append_info(DYNAMIC_STRING *ds, ulonglong affected_rows, /* - Display the table headings with the names tab separated + Display the table headings with the names tab separated */ -static void append_table_headings(DYNAMIC_STRING *ds, - MYSQL_FIELD *field, - uint num_fields) +void append_table_headings(DYNAMIC_STRING *ds, + MYSQL_FIELD *field, + uint num_fields) { uint col_idx; for (col_idx= 0; col_idx < num_fields; col_idx++) @@ -4143,10 +4457,10 @@ static void append_table_headings(DYNAMIC_STRING *ds, Fetch warnings from server and append to ds RETURN VALUE - Number of warnings appended to ds + Number of warnings appended to ds */ -static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) +int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) { uint count; MYSQL_RES *warn_res; @@ -4195,9 +4509,9 @@ static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql) error - function will not return */ -static void run_query_normal(MYSQL *mysql, struct st_query *command, - int flags, char *query, int query_len, - DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings) +void run_query_normal(MYSQL *mysql, struct st_command *command, + int flags, char *query, int query_len, + DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings) { MYSQL_RES *res= 0; int err= 0, counter= 0; @@ -4205,20 +4519,20 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, DBUG_PRINT("enter",("flags: %d", flags)); DBUG_PRINT("enter", ("query: '%-.60s'", query)); - if (flags & QUERY_SEND) + if (flags & QUERY_SEND_FLAG) { /* - Send the query - */ + Send the query + */ if (mysql_send_query(mysql, query, query_len)) { - handle_error(query, command, mysql_errno(mysql), mysql_error(mysql), + handle_error(command, mysql_errno(mysql), mysql_error(mysql), mysql_sqlstate(mysql), ds); goto end; } } - if (!(flags & QUERY_REAP)) + if (!(flags & QUERY_REAP_FLAG)) DBUG_VOID_RETURN; do @@ -4226,22 +4540,22 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, /* When on first result set, call mysql_read_query_result to retrieve answer to the query sent earlier - */ + */ if ((counter==0) && mysql_read_query_result(mysql)) { - handle_error(query, command, mysql_errno(mysql), mysql_error(mysql), + handle_error(command, mysql_errno(mysql), mysql_error(mysql), mysql_sqlstate(mysql), ds); goto end; } /* - Store the result. If res is NULL, use mysql_field_count to - determine if that was expected - */ + Store the result. If res is NULL, use mysql_field_count to + determine if that was expected + */ if (!(res= mysql_store_result(mysql)) && mysql_field_count(mysql)) { - handle_error(query, command, mysql_errno(mysql), mysql_error(mysql), + handle_error(command, mysql_errno(mysql), mysql_error(mysql), mysql_sqlstate(mysql), ds); goto end; } @@ -4297,7 +4611,7 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, if (err > 0) { /* We got an error from mysql_next_result, maybe expected */ - handle_error(query, command, mysql_errno(mysql), mysql_error(mysql), + handle_error(command, mysql_errno(mysql), mysql_error(mysql), mysql_sqlstate(mysql), ds); goto end; } @@ -4307,8 +4621,6 @@ static void run_query_normal(MYSQL *mysql, struct st_query *command, handle_no_error(command); end: - free_replace(); - free_replace_regex(); /* We save the return code (mysql_errno(mysql)) from the last call sent @@ -4324,58 +4636,62 @@ end: Handle errors which occurred during execution SYNOPSIS - handle_error() - query - query string - q - query context - err_errno - error number - err_error - error message - err_sqlstate - sql state - ds - dynamic string which is used for output buffer + handle_error() + q - query context + err_errno - error number + err_error - error message + err_sqlstate - sql state + ds - dynamic string which is used for output buffer NOTE - If there is an unexpected error this function will abort mysqltest - immediately. + If there is an unexpected error this function will abort mysqltest + immediately. RETURN VALUE - error - function will not return + error - function will not return */ -static void handle_error(const char *query, struct st_query *q, - unsigned int err_errno, const char *err_error, - const char *err_sqlstate, DYNAMIC_STRING *ds) +void handle_error(struct st_command *command, + unsigned int err_errno, const char *err_error, + const char *err_sqlstate, DYNAMIC_STRING *ds) { uint i; DBUG_ENTER("handle_error"); - if (q->require_file) + if (command->require_file[0]) { /* The query after a "--require" failed. This is fine as long the server returned a valid reponse. Don't allow 2013 or 2006 to trigger an abort_not_supported_test - */ + */ if (err_errno == CR_SERVER_LOST || err_errno == CR_SERVER_GONE_ERROR) - die("require query '%s' failed: %d: %s", query, err_errno, err_error); + die("require query '%s' failed: %d: %s", command->query, + err_errno, err_error); /* Abort the run of this test, pass the failed query as reason */ - abort_not_supported_test("Query '%s' failed, required functionality not supported", query); + abort_not_supported_test("Query '%s' failed, required functionality" \ + "not supported", command->query); } - if (q->abort_on_error) - die("query '%s' failed: %d: %s", query, err_errno, err_error); + if (command->abort_on_error) + die("query '%s' failed: %d: %s", command->query, err_errno, err_error); - for (i= 0 ; (uint) i < q->expected_errors ; i++) + DBUG_PRINT("info", ("expected_errors.count: %d", + command->expected_errors.count)); + for (i= 0 ; (uint) i < command->expected_errors.count ; i++) { - if (((q->expected_errno[i].type == ERR_ERRNO) && - (q->expected_errno[i].code.errnum == err_errno)) || - ((q->expected_errno[i].type == ERR_SQLSTATE) && - (strcmp(q->expected_errno[i].code.sqlstate, err_sqlstate) == 0))) + if (((command->expected_errors.err[i].type == ERR_ERRNO) && + (command->expected_errors.err[i].code.errnum == err_errno)) || + ((command->expected_errors.err[i].type == ERR_SQLSTATE) && + (strncmp(command->expected_errors.err[i].code.sqlstate, + err_sqlstate, SQLSTATE_LENGTH) == 0))) { if (!disable_result_log) { - if (q->expected_errors == 1) + if (command->expected_errors.count == 1) { /* Only log error if there is one possible error */ dynstr_append_mem(ds, "ERROR ", 6); @@ -4385,9 +4701,9 @@ static void handle_error(const char *query, struct st_query *q, dynstr_append_mem(ds,"\n",1); } /* Don't log error if we may not get an error */ - else if (q->expected_errno[0].type == ERR_SQLSTATE || - (q->expected_errno[0].type == ERR_ERRNO && - q->expected_errno[0].code.errnum != 0)) + else if (command->expected_errors.err[0].type == ERR_SQLSTATE || + (command->expected_errors.err[0].type == ERR_ERRNO && + command->expected_errors.err[0].code.errnum != 0)) dynstr_append(ds,"Got one of the listed errors\n"); } /* OK */ @@ -4395,7 +4711,8 @@ static void handle_error(const char *query, struct st_query *q, } } - DBUG_PRINT("info",("i: %d expected_errors: %d", i, q->expected_errors)); + DBUG_PRINT("info",("i: %d expected_errors: %d", i, + command->expected_errors.count)); if (!disable_result_log) { @@ -4408,13 +4725,14 @@ static void handle_error(const char *query, struct st_query *q, if (i) { - if (q->expected_errno[0].type == ERR_ERRNO) + if (command->expected_errors.err[0].type == ERR_ERRNO) die("query '%s' failed with wrong errno %d: '%s', instead of %d...", - q->query, err_errno, err_error, q->expected_errno[0].code.errnum); + command->query, err_errno, err_error, + command->expected_errors.err[0].code.errnum); else die("query '%s' failed with wrong sqlstate %s: '%s', instead of %s...", - q->query, err_sqlstate, err_error, - q->expected_errno[0].code.sqlstate); + command->query, err_sqlstate, err_error, + command->expected_errors.err[0].code.sqlstate); } DBUG_VOID_RETURN; @@ -4425,30 +4743,30 @@ static void handle_error(const char *query, struct st_query *q, Handle absence of errors after execution SYNOPSIS - handle_no_error() - q - context of query + handle_no_error() + q - context of query RETURN VALUE - error - function will not return + error - function will not return */ -static void handle_no_error(struct st_query *q) +void handle_no_error(struct st_command *command) { DBUG_ENTER("handle_no_error"); - if (q->expected_errno[0].type == ERR_ERRNO && - q->expected_errno[0].code.errnum != 0) + if (command->expected_errors.err[0].type == ERR_ERRNO && + command->expected_errors.err[0].code.errnum != 0) { /* Error code we wanted was != 0, i.e. not an expected success */ die("query '%s' succeeded - should have failed with errno %d...", - q->query, q->expected_errno[0].code.errnum); + command->query, command->expected_errors.err[0].code.errnum); } - else if (q->expected_errno[0].type == ERR_SQLSTATE && - strcmp(q->expected_errno[0].code.sqlstate,"00000") != 0) + else if (command->expected_errors.err[0].type == ERR_SQLSTATE && + strcmp(command->expected_errors.err[0].code.sqlstate,"00000") != 0) { /* SQLSTATE we wanted was != "00000", i.e. not an expected success */ die("query '%s' succeeded - should have failed with sqlstate %s...", - q->query, q->expected_errno[0].code.sqlstate); + command->query, command->expected_errors.err[0].code.sqlstate); } DBUG_VOID_RETURN; @@ -4470,9 +4788,9 @@ static void handle_no_error(struct st_query *q) error - function will not return */ -static void run_query_stmt(MYSQL *mysql, struct st_query *command, - char *query, int query_len, DYNAMIC_STRING *ds, - DYNAMIC_STRING *ds_warnings) +void run_query_stmt(MYSQL *mysql, struct st_command *command, + char *query, int query_len, DYNAMIC_STRING *ds, + DYNAMIC_STRING *ds_warnings) { MYSQL_RES *res= NULL; /* Note that here 'res' is meta data result set */ MYSQL_STMT *stmt; @@ -4503,7 +4821,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, */ if (mysql_stmt_prepare(stmt, query, query_len)) { - handle_error(query, command, mysql_stmt_errno(stmt), + handle_error(command, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); goto end; } @@ -4520,6 +4838,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, parameter markers. */ +#if MYSQL_VERSION_ID >= 50000 if (cursor_protocol_enabled) { /* @@ -4530,13 +4849,14 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, die("mysql_stmt_attr_set(STMT_ATTR_CURSOR_TYPE) failed': %d %s", mysql_stmt_errno(stmt), mysql_stmt_error(stmt)); } +#endif /* Execute the query */ if (mysql_stmt_execute(stmt)) { - handle_error(query, command, mysql_stmt_errno(stmt), + handle_error(command, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); goto end; } @@ -4550,8 +4870,8 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, /* We instruct that we want to update the "max_length" field in - mysql_stmt_store_result(), this is our only way to know how much - buffer to allocate for result data + mysql_stmt_store_result(), this is our only way to know how much + buffer to allocate for result data */ { my_bool one= 1; @@ -4566,7 +4886,7 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, */ if (mysql_stmt_store_result(stmt)) { - handle_error(query, command, mysql_stmt_errno(stmt), + handle_error(command, mysql_stmt_errno(stmt), mysql_stmt_error(stmt), mysql_stmt_sqlstate(stmt), ds); goto end; } @@ -4636,9 +4956,6 @@ static void run_query_stmt(MYSQL *mysql, struct st_query *command, } end: - free_replace(); - free_replace_regex(); - if (!disable_warnings) { dynstr_free(&ds_prepare_warnings); @@ -4650,7 +4967,7 @@ end: to the server into the mysqltest builtin variable $mysql_errno. This variable then can be used from the test case itself. */ - + var_set_errno(mysql_stmt_errno(stmt)); #ifndef BUG15518_FIXED mysql_stmt_close(stmt); @@ -4668,7 +4985,7 @@ end: as view, sp etc. */ -static int util_query(MYSQL* org_mysql, const char* query){ +int util_query(MYSQL* org_mysql, const char* query){ MYSQL* mysql; DBUG_ENTER("util_query"); @@ -4679,11 +4996,9 @@ static int util_query(MYSQL* org_mysql, const char* query){ if (!(mysql= mysql_init(mysql))) die("Failed in mysql_init()"); - if (safe_connect(mysql, org_mysql->host, org_mysql->user, - org_mysql->passwd, org_mysql->db, org_mysql->port, - org_mysql->unix_socket)) - die("Could not open util connection: %d %s", - mysql_errno(mysql), mysql_error(mysql)); + safe_connect(mysql, "util", org_mysql->host, org_mysql->user, + org_mysql->passwd, org_mysql->db, org_mysql->port, + org_mysql->unix_socket); cur_con->util_mysql= mysql; } @@ -4697,8 +5012,8 @@ static int util_query(MYSQL* org_mysql, const char* query){ Run query flags control the phased/stages of query execution to be performed - if QUERY_SEND bit is on, the query will be sent. If QUERY_REAP is on - the result will be read - for regular query, both bits must be on + if QUERY_SEND_FLAG bit is on, the query will be sent. If QUERY_REAP_FLAG + is on the result will be read - for regular query, both bits must be on SYNPOSIS run_query @@ -4707,7 +5022,7 @@ static int util_query(MYSQL* org_mysql, const char* query){ */ -static void run_query(MYSQL *mysql, struct st_query *command, int flags) +void run_query(MYSQL *mysql, struct st_command *command, int flags) { DYNAMIC_STRING *ds; DYNAMIC_STRING ds_result; @@ -4716,17 +5031,21 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) char *query; int query_len; my_bool view_created= 0, sp_created= 0; - my_bool complete_query= ((flags & QUERY_SEND) && (flags & QUERY_REAP)); + my_bool complete_query= ((flags & QUERY_SEND_FLAG) && + (flags & QUERY_REAP_FLAG)); init_dynamic_string(&ds_warnings, NULL, 0, 256); + /* Scan for warning before sendign to server */ + scan_command_for_warnings(command); + /* Evaluate query if this is an eval command - */ + */ if (command->type == Q_EVAL) { - init_dynamic_string(&eval_query, "", 16384, 65536); - do_eval(&eval_query, command->query, FALSE); + init_dynamic_string(&eval_query, "", command->query_len+256, 1024); + do_eval(&eval_query, command->query, command->end, FALSE); query = eval_query.str; query_len = eval_query.length; } @@ -4737,23 +5056,23 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) } /* - When command->record_file is set the output of _this_ query + When command->require_file is set the output of _this_ query should be compared with an already existing file Create a temporary dynamic string to contain the output from this query. - */ - if (command->record_file[0]) + */ + if (command->require_file[0]) { - init_dynamic_string(&ds_result, "", 16384, 65536); + init_dynamic_string(&ds_result, "", 1024, 1024); ds= &ds_result; } else ds= &ds_res; /* - Log the query into the output buffer + Log the query into the output buffer */ - if (!disable_query_log && (flags & QUERY_SEND)) + if (!disable_query_log && (flags & QUERY_SEND_FLAG)) { replace_dynstr_append_mem(ds, query, query_len); dynstr_append_mem(ds, delimiter, delimiter_length); @@ -4765,8 +5084,8 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) match_re(&view_re, query)) { /* - Create the query as a view. - Use replace since view can exist from a failed mysqltest run + Create the query as a view. + Use replace since view can exist from a failed mysqltest run */ DYNAMIC_STRING query_str; init_dynamic_string(&query_str, @@ -4778,7 +5097,7 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) /* Failed to create the view, this is not fatal just run the query the normal way - */ + */ DBUG_PRINT("view_create_error", ("Failed to create view '%s': %d: %s", query_str.str, mysql_errno(mysql), mysql_error(mysql))); @@ -4791,14 +5110,14 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) { /* Yes, it was possible to create this query as a view - */ + */ view_created= 1; query= (char*)"SELECT * FROM mysqltest_tmp_v"; query_len = strlen(query); /* - Collect warnings from create of the view that should otherwise - have been produced when the SELECT was executed + Collect warnings from create of the view that should otherwise + have been produced when the SELECT was executed */ append_warnings(&ds_warnings, cur_con->util_mysql); } @@ -4877,26 +5196,14 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) mysql_errno(mysql), mysql_error(mysql)); } - if (command->record_file[0]) + if (command->require_file[0]) { - /* A result file was specified for _this_ query */ - if (record) - { - /* - Recording in progress - Dump the output from _this_ query to the specified record_file - */ - str_to_file(command->record_file, ds->str, ds->length); - - } else { - - /* - The output from _this_ query should be checked against an already - existing file which has been specified using --require or --result - */ - check_result(ds, command->record_file, command->require_file); - } + /* A result file was specified for _this_ query + and the output should be checked against an already + existing file which has been specified using --require or --result + */ + check_require(ds, command->require_file); } dynstr_free(&ds_warnings); @@ -4906,12 +5213,12 @@ static void run_query(MYSQL *mysql, struct st_query *command, int flags) dynstr_free(&eval_query); } +/****************************************************************************/ +/* + Functions to detect different SQL statements +*/ -/****************************************************************************\ - * Functions to detect different SQL statements -\****************************************************************************/ - -static char *re_eprint(int err) +char *re_eprint(int err) { static char epbuf[100]; size_t len= my_regerror(REG_ITOA|err, (my_regex_t *)NULL, @@ -4920,7 +5227,7 @@ static char *re_eprint(int err) return(epbuf); } -static void init_re_comp(my_regex_t *re, const char* str) +void init_re_comp(my_regex_t *re, const char* str) { int err= my_regcomp(re, str, (REG_EXTENDED | REG_ICASE | REG_NOSUB), &my_charset_latin1); @@ -4933,11 +5240,11 @@ static void init_re_comp(my_regex_t *re, const char* str) } } -static void init_re(void) +void init_re(void) { /* - Filter for queries that can be run using the - MySQL Prepared Statements C API + Filter for queries that can be run using the + MySQL Prepared Statements C API */ const char *ps_re_str = "^(" @@ -4954,13 +5261,13 @@ static void init_re(void) "[[:space:]]*INSERT[[:space:]]+SELECT[[:space:]])"; /* - Filter for queries that can be run using the - Stored procedures + Filter for queries that can be run using the + Stored procedures */ const char *sp_re_str =ps_re_str; /* - Filter for queries that can be run as views + Filter for queries that can be run as views */ const char *view_re_str = "^(" @@ -4972,7 +5279,7 @@ static void init_re(void) } -static int match_re(my_regex_t *re, char *str) +int match_re(my_regex_t *re, char *str) { int err= my_regexec(re, str, (size_t)0, NULL, 0); @@ -4990,7 +5297,7 @@ static int match_re(my_regex_t *re, char *str) return 0; } -static void free_re(void) +void free_re(void) { my_regfree(&ps_re); my_regfree(&sp_re); @@ -5000,142 +5307,85 @@ static void free_re(void) /****************************************************************************/ -void get_query_type(struct st_query* q) +void get_command_type(struct st_command* command) { char save; uint type; - DBUG_ENTER("get_query_type"); + DBUG_ENTER("get_command_type"); - if (!parsing_disabled && *q->query == '}') + if (*command->query == '}') { - q->type = Q_END_BLOCK; + command->type = Q_END_BLOCK; DBUG_VOID_RETURN; } - if (q->type != Q_COMMENT_WITH_COMMAND) - q->type= parsing_disabled ? Q_COMMENT : Q_QUERY; - save=q->query[q->first_word_len]; - q->query[q->first_word_len]=0; - type=find_type(q->query, &command_typelib, 1+2); - q->query[q->first_word_len]=save; + save= command->query[command->first_word_len]; + command->query[command->first_word_len]= 0; + type= find_type(command->query, &command_typelib, 1+2); + command->query[command->first_word_len]= save; if (type > 0) { - q->type=(enum enum_commands) type; /* Found command */ + command->type=(enum enum_commands) type; /* Found command */ + /* - If queries are disabled, only recognize - --enable_parsing and --disable_parsing + Look for case where "query" was explicitly specified to + force command being sent to server */ - if (parsing_disabled && q->type != Q_ENABLE_PARSING && - q->type != Q_DISABLE_PARSING) - q->type= Q_COMMENT; + if (type == Q_QUERY) + { + /* Skip the "query" part */ + command->query= command->first_argument; + } } - else if (q->type == Q_COMMENT_WITH_COMMAND && - q->first_word_len && - q->query[q->first_word_len-1] == ';') + else { - /* - Detect comment with command using extra delimiter - Ex --disable_query_log; - ^ Extra delimiter causing the command - to be skipped - */ - save= q->query[q->first_word_len-1]; - q->query[q->first_word_len-1]= 0; - type= find_type(q->query, &command_typelib, 1+2); - q->query[q->first_word_len-1]= save; - if (type > 0) - die("Extra delimiter \";\" found"); - } - DBUG_VOID_RETURN; -} - - -static byte *get_var_key(const byte* var, uint* len, - my_bool __attribute__((unused)) t) -{ - register char* key; - key = ((VAR*)var)->name; - *len = ((VAR*)var)->name_len; - return (byte*)key; -} + /* No mysqltest command matched */ -static VAR *var_init(VAR *v, const char *name, int name_len, const char *val, - int val_len) -{ - int val_alloc_len; - VAR *tmp_var; - if (!name_len && name) - name_len = strlen(name); - if (!val_len && val) - val_len = strlen(val) ; - val_alloc_len = val_len + 16; /* room to grow */ - if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var) - + name_len+1, MYF(MY_WME)))) - die("Out of memory"); - - tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0; - tmp_var->alloced = (v == 0); - - if (!(tmp_var->str_val = my_malloc(val_alloc_len+1, MYF(MY_WME)))) - die("Out of memory"); + if (command->type != Q_COMMENT_WITH_COMMAND) + { + /* A query that will sent to mysqld */ + command->type= Q_QUERY; + } + else + { + /* -- comment that didn't contain a mysqltest command */ + command->type= Q_COMMENT; + warning_msg("Suspicious command '--%s' detected, was this intentional? "\ + "Use # instead of -- to avoid this warning", + command->query); + + if (command->first_word_len && + strcmp(command->query + command->first_word_len - 1, delimiter) == 0) + { + /* + Detect comment with command using extra delimiter + Ex --disable_query_log; + ^ Extra delimiter causing the command + to be skipped + */ + save= command->query[command->first_word_len-1]; + command->query[command->first_word_len-1]= 0; + if (find_type(command->query, &command_typelib, 1+2) > 0) + die("Extra delimiter \";\" found"); + command->query[command->first_word_len-1]= save; - memcpy(tmp_var->name, name, name_len); - if (val) - { - memcpy(tmp_var->str_val, val, val_len); - tmp_var->str_val[val_len]= 0; + } + } } - tmp_var->name_len = name_len; - tmp_var->str_val_len = val_len; - tmp_var->alloced_len = val_alloc_len; - tmp_var->int_val = (val) ? atoi(val) : 0; - tmp_var->int_dirty = 0; - tmp_var->env_s = 0; - return tmp_var; -} - -static void var_free(void *v) -{ - my_free(((VAR*) v)->str_val, MYF(MY_WME)); - if (((VAR*)v)->alloced) - my_free((char*) v, MYF(MY_WME)); -} - - -static VAR* var_from_env(const char *name, const char *def_val) -{ - const char *tmp; - VAR *v; - if (!(tmp = getenv(name))) - tmp = def_val; - - v = var_init(0, name, strlen(name), tmp, strlen(tmp)); - my_hash_insert(&var_hash, (byte*)v); - return v; -} + /* Set expected error on command */ + memcpy(&command->expected_errors, &saved_expected_errors, + sizeof(saved_expected_errors)); + DBUG_PRINT("info", ("There are %d expected errors", + command->expected_errors.count)); + command->abort_on_error= (command->expected_errors.count == 0 && + abort_on_error); -static void init_var_hash(MYSQL *mysql) -{ - VAR *v; - DBUG_ENTER("init_var_hash"); - if (hash_init(&var_hash, charset_info, - 1024, 0, 0, get_var_key, var_free, MYF(0))) - die("Variable hash initialization failed"); - my_hash_insert(&var_hash, (byte*) var_init(0,"BIG_TEST", 0, - (opt_big_test) ? "1" : "0", 0)); - my_hash_insert(&var_hash, (byte*) var_init(0,"VALGRIND_TEST", 0, - (opt_valgrind_test) ? "1" : "0", - 0)); - v= var_init(0,"MAX_TABLES", 0, (sizeof(ulong) == 4) ? "31" : "62",0); - my_hash_insert(&var_hash, (byte*) v); - v= var_init(0,"SERVER_VERSION", 0, mysql_get_server_info(mysql), 0); - my_hash_insert(&var_hash, (byte*) v); v= var_init(0,"DB", 2, db, 0); - my_hash_insert(&var_hash, (byte*) v); DBUG_VOID_RETURN; } + /* Record how many milliseconds it took to execute the test file up until the current line and save it in the dynamic string ds_progress. @@ -5144,7 +5394,9 @@ static void init_var_hash(MYSQL *mysql) test run completes */ -static void mark_progress(struct st_query* q __attribute__((unused)), int line) + +void mark_progress(struct st_command* command __attribute__((unused)), + int line) { char buf[32], *end; ulonglong timer= timer_now(); @@ -5178,47 +5430,63 @@ static void mark_progress(struct st_query* q __attribute__((unused)), int line) int main(int argc, char **argv) { - struct st_query *q; - my_bool require_file=0, q_send_flag=0, - query_executed= 0; + struct st_command *command; + my_bool q_send_flag= 0, abort_flag= 0; + uint command_executed= 0, last_command_executed= 0; char save_file[FN_REFLEN]; MY_STAT res_info; MY_INIT(argv[0]); - /* Use all time until exit if no explicit 'start_timer' */ - timer_start= timer_now(); + save_file[0]= 0; + TMPDIR[0]= 0; - save_file[0]=0; - TMPDIR[0]=0; + /* Init expected errors */ + memset(&saved_expected_errors, 0, sizeof(saved_expected_errors)); - /* Init cons */ - memset(cons, 0, sizeof(cons)); - cons_end = cons + MAX_CONS; - next_con = cons + 1; - cur_con = cons; + /* Init connections */ + memset(connections, 0, sizeof(connections)); + connections_end= connections + + (sizeof(connections)/sizeof(struct st_connection)) - 1; + next_con= connections + 1; + cur_con= connections; /* Init file stack */ memset(file_stack, 0, sizeof(file_stack)); - file_stack_end= file_stack + MAX_INCLUDE_DEPTH - 1; + file_stack_end= + file_stack + (sizeof(file_stack)/sizeof(struct st_test_file)) - 1; cur_file= file_stack; /* Init block stack */ memset(block_stack, 0, sizeof(block_stack)); - block_stack_end= block_stack + BLOCK_STACK_DEPTH - 1; + block_stack_end= + block_stack + (sizeof(block_stack)/sizeof(struct st_block)) - 1; cur_block= block_stack; cur_block->ok= TRUE; /* Outer block should always be executed */ cur_block->cmd= cmd_none; - my_init_dynamic_array(&q_lines, sizeof(struct st_query*), INIT_Q_LINES, - INIT_Q_LINES); + my_init_dynamic_array(&q_lines, sizeof(struct st_command*), 1024, 1024); + + if (hash_init(&var_hash, charset_info, + 1024, 0, 0, get_var_key, var_free, MYF(0))) + die("Variable hash initialization failed"); memset(&master_pos, 0, sizeof(master_pos)); - init_dynamic_string(&ds_res, "", 0, 65536); + parser.current_line= parser.read_lines= 0; + memset(&var_reg, 0, sizeof(var_reg)); + +#ifdef __WIN__ + init_tmp_sh_file(); + init_win_path_patterns(); +#endif + + init_dynamic_string(&ds_res, "", 65536, 65536); init_dynamic_string(&ds_progress, "", 0, 2048); + init_dynamic_string(&ds_warning_messages, "", 0, 2048); parse_args(argc, argv); - DBUG_PRINT("info",("result_file: '%s'", result_file ? result_file : "")); + DBUG_PRINT("info",("result_file: '%s'", + result_file_name ? result_file_name : "")); if (mysql_server_init(embedded_server_arg_count, embedded_server_args, (char**) embedded_server_groups)) @@ -5246,29 +5514,30 @@ int main(int argc, char **argv) mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_NAME, charset_name); #ifdef HAVE_OPENSSL + +#if MYSQL_VERSION_ID >= 50000 opt_ssl_verify_server_cert= TRUE; /* Always on in mysqltest */ +#endif + if (opt_use_ssl) { mysql_ssl_set(&cur_con->mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca, opt_ssl_capath, opt_ssl_cipher); +#if MYSQL_VERSION_ID >= 50000 mysql_options(&cur_con->mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &opt_ssl_verify_server_cert); +#endif } #endif if (!(cur_con->name = my_strdup("default", MYF(MY_WME)))) die("Out of memory"); - if (safe_connect(&cur_con->mysql, host, user, pass, db, port, unix_sock)) - die("Could not open connection '%s': %d %s", cur_con->name, - mysql_errno(&cur_con->mysql), mysql_error(&cur_con->mysql)); + safe_connect(&cur_con->mysql, cur_con->name, host, user, pass, + db, port, unix_sock); - init_var_hash(&cur_con->mysql); - -#ifdef __WIN__ - init_tmp_sh_file(); - init_win_path_patterns(); -#endif + /* Use all time until exit if no explicit 'start_timer' */ + timer_start= timer_now(); /* Initialize $mysql_errno with -1, so we can @@ -5282,26 +5551,35 @@ int main(int argc, char **argv) open_file(opt_include); } - while (!read_query(&q)) + while (!read_command(&command) && !abort_flag) { int current_line_inc = 1, processed = 0; - if (q->type == Q_UNKNOWN || q->type == Q_COMMENT_WITH_COMMAND) - get_query_type(q); + if (command->type == Q_UNKNOWN || command->type == Q_COMMENT_WITH_COMMAND) + get_command_type(command); + + if (parsing_disabled && + command->type != Q_ENABLE_PARSING && + command->type != Q_DISABLE_PARSING) + { + command->type= Q_COMMENT; + scan_command_for_warnings(command); + } + if (cur_block->ok) { - q->last_argument= q->first_argument; + command->last_argument= command->first_argument; processed = 1; - switch (q->type) { + switch (command->type) { case Q_CONNECT: - do_connect(q); + do_connect(command); break; - case Q_CONNECTION: select_connection(q); break; + case Q_CONNECTION: select_connection(command); break; case Q_DISCONNECT: case Q_DIRTY_CLOSE: - close_connection(q); break; - case Q_RPL_PROBE: do_rpl_probe(q); break; - case Q_ENABLE_RPL_PARSE: do_enable_rpl_parse(q); break; - case Q_DISABLE_RPL_PARSE: do_disable_rpl_parse(q); break; + do_close_connection(command); break; + case Q_RPL_PROBE: do_rpl_probe(command); break; + case Q_ENABLE_RPL_PARSE: do_enable_rpl_parse(command); break; + case Q_DISABLE_RPL_PARSE: do_disable_rpl_parse(command); break; case Q_ENABLE_QUERY_LOG: disable_query_log=0; break; case Q_DISABLE_QUERY_LOG: disable_query_log=1; break; case Q_ENABLE_ABORT_ON_ERROR: abort_on_error=1; break; @@ -5316,18 +5594,21 @@ int main(int argc, char **argv) case Q_DISABLE_INFO: disable_info=1; break; case Q_ENABLE_METADATA: display_metadata=1; break; case Q_DISABLE_METADATA: display_metadata=0; break; - case Q_SOURCE: do_source(q); break; - case Q_SLEEP: do_sleep(q, 0); break; - case Q_REAL_SLEEP: do_sleep(q, 1); break; - case Q_WAIT_FOR_SLAVE_TO_STOP: do_wait_for_slave_to_stop(q); break; - case Q_INC: do_modify_var(q, DO_INC); break; - case Q_DEC: do_modify_var(q, DO_DEC); break; - case Q_ECHO: do_echo(q); query_executed= 1; break; - case Q_SYSTEM: do_system(q); break; + case Q_SOURCE: do_source(command); break; + case Q_SLEEP: do_sleep(command, 0); break; + case Q_REAL_SLEEP: do_sleep(command, 1); break; + case Q_WAIT_FOR_SLAVE_TO_STOP: do_wait_for_slave_to_stop(command); break; + case Q_INC: do_modify_var(command, DO_INC); break; + case Q_DEC: do_modify_var(command, DO_DEC); break; + case Q_ECHO: do_echo(command); command_executed++; break; + case Q_SYSTEM: do_system(command); break; + case Q_REMOVE_FILE: do_remove_file(command); break; + case Q_FILE_EXIST: do_file_exist(command); break; + case Q_WRITE_FILE: do_write_file(command); break; + case Q_COPY_FILE: do_copy_file(command); break; + case Q_PERL: do_perl(command); break; case Q_DELIMITER: - strmake(delimiter, q->first_argument, sizeof(delimiter) - 1); - delimiter_length= strlen(delimiter); - q->last_argument= q->first_argument+delimiter_length; + do_delimiter(command); break; case Q_DISPLAY_VERTICAL_RESULTS: display_result_vertically= TRUE; @@ -5335,133 +5616,128 @@ int main(int argc, char **argv) case Q_DISPLAY_HORIZONTAL_RESULTS: display_result_vertically= FALSE; break; - case Q_LET: do_let(q); break; + case Q_LET: do_let(command); break; case Q_EVAL_RESULT: eval_result = 1; break; case Q_EVAL: - if (q->query == q->query_buf) + if (command->query == command->query_buf) { - q->query= q->first_argument; - q->first_word_len= 0; + command->query= command->first_argument; + command->first_word_len= 0; } /* fall through */ case Q_QUERY_VERTICAL: case Q_QUERY_HORIZONTAL: { my_bool old_display_result_vertically= display_result_vertically; - /* fix up query pointer if this is first iteration for this line */ - if (q->query == q->query_buf) - q->query += q->first_word_len + 1; - display_result_vertically= (q->type==Q_QUERY_VERTICAL); + + /* Remove "query_*" if this is first iteration */ + if (command->query == command->query_buf) + command->query= command->first_argument; + + display_result_vertically= (command->type == Q_QUERY_VERTICAL); if (save_file[0]) { - strmov(q->record_file,save_file); - q->require_file=require_file; - save_file[0]=0; + strmake(command->require_file, save_file, sizeof(save_file)); + save_file[0]= 0; } - run_query(&cur_con->mysql, q, QUERY_REAP|QUERY_SEND); + run_query(&cur_con->mysql, command, QUERY_REAP_FLAG|QUERY_SEND_FLAG); display_result_vertically= old_display_result_vertically; - q->last_argument= q->end; - query_executed= 1; + command->last_argument= command->end; + command_executed++; break; } case Q_QUERY: case Q_REAP: { - /* - We read the result always regardless of the mode for both full - query and read-result only (reap) - */ - int flags = QUERY_REAP; - if (q->type != Q_REAP) /* for a full query, enable the send stage */ - flags |= QUERY_SEND; - if (q_send_flag) - { - flags= QUERY_SEND; - q_send_flag=0; - } + int flags; + if (q_send_flag) + { + /* Last command was an empty 'send' */ + flags= QUERY_SEND_FLAG; + q_send_flag= 0; + } + else if (command->type == Q_REAP) + { + flags= QUERY_REAP_FLAG; + } + else + { + /* full query, both reap and send */ + flags= QUERY_REAP_FLAG | QUERY_SEND_FLAG; + } + if (save_file[0]) { - strmov(q->record_file,save_file); - q->require_file=require_file; - save_file[0]=0; + strmake(command->require_file, save_file, sizeof(save_file)); + save_file[0]= 0; } - /* - To force something being sent as a query to the mysqld one can - use the prefix "query". Remove "query" from string before executing - */ - if (strncmp(q->query, "query ", 6) == 0) - { - q->query= q->first_argument; - } - run_query(&cur_con->mysql, q, flags); - query_executed= 1; - q->last_argument= q->end; + run_query(&cur_con->mysql, command, flags); + command_executed++; + command->last_argument= command->end; break; } case Q_SEND: - if (!q->query[q->first_word_len]) - { - /* This happens when we use 'send' on its own line */ - q_send_flag=1; - break; - } - /* fix up query pointer if this is first iteration for this line */ - if (q->query == q->query_buf) - q->query += q->first_word_len; + if (!*command->first_argument) + { + /* + This is a send without arguments, it indicates that _next_ query + should be send only + */ + q_send_flag= 1; + break; + } + + /* Remove "send" if this is first iteration */ + if (command->query == command->query_buf) + command->query= command->first_argument; + /* run_query() can execute a query partially, depending on the flags. - QUERY_SEND flag without QUERY_REAP tells it to just send the - query and read the result some time later when reap instruction + QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send + the query and read the result some time later when reap instruction is given on this connection. - */ - run_query(&cur_con->mysql, q, QUERY_SEND); - query_executed= 1; - q->last_argument= q->end; + */ + run_query(&cur_con->mysql, command, QUERY_SEND_FLAG); + command_executed++; + command->last_argument= command->end; break; - case Q_RESULT: - get_file_name(save_file,q); - require_file=0; + case Q_REQUIRE: + do_get_file_name(command, save_file, sizeof(save_file)); break; case Q_ERROR: - global_expected_errors=get_errcodes(global_expected_errno,q); - break; - case Q_REQUIRE: - get_file_name(save_file,q); - require_file=1; + do_get_errcodes(command); break; case Q_REPLACE: - get_replace(q); + do_get_replace(command); break; case Q_REPLACE_REGEX: - get_replace_regex(q); + do_get_replace_regex(command); break; - case Q_REPLACE_COLUMN: - get_replace_column(q); + do_get_replace_column(command); break; case Q_SAVE_MASTER_POS: do_save_master_pos(); break; - case Q_SYNC_WITH_MASTER: do_sync_with_master(q); break; + case Q_SYNC_WITH_MASTER: do_sync_with_master(command); break; case Q_SYNC_SLAVE_WITH_MASTER: { do_save_master_pos(); - if (*q->first_argument) - select_connection(q); + if (*command->first_argument) + select_connection(command); else select_connection_name("slave"); do_sync_with_master2(0); break; } case Q_COMMENT: /* Ignore row */ - case Q_COMMENT_WITH_COMMAND: - q->last_argument= q->end; + command->last_argument= command->end; break; case Q_PING: (void) mysql_ping(&cur_con->mysql); break; case Q_EXEC: - do_exec(q); - query_executed= 1; + do_exec(command); + command_executed++; break; case Q_START_TIMER: /* Overwrite possible earlier start of timer */ @@ -5470,10 +5746,9 @@ int main(int argc, char **argv) case Q_END_TIMER: /* End timer before ending mysqltest */ timer_output(); - got_end_timer= TRUE; break; case Q_CHARACTER_SET: - set_charset(q); + do_set_charset(command); break; case Q_DISABLE_PS_PROTOCOL: ps_protocol_enabled= 0; @@ -5482,31 +5757,38 @@ int main(int argc, char **argv) ps_protocol_enabled= ps_protocol; break; case Q_DISABLE_RECONNECT: - { - my_bool reconnect= 0; - mysql_options(&cur_con->mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect); + set_reconnect(&cur_con->mysql, 0); break; - } case Q_ENABLE_RECONNECT: - { - my_bool reconnect= 1; - mysql_options(&cur_con->mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect); + set_reconnect(&cur_con->mysql, 1); break; - } case Q_DISABLE_PARSING: - parsing_disabled++; + if (parsing_disabled == 0) + parsing_disabled= 1; + else + die("Parsing is already disabled"); break; case Q_ENABLE_PARSING: /* Ensure we don't get parsing_disabled < 0 as this would accidentally disable code we don't want to have disabled */ - if (parsing_disabled > 0) - parsing_disabled--; + if (parsing_disabled == 1) + parsing_disabled= 0; + else + die("Parsing is already enabled"); break; - case Q_DIE: - die("%s", q->first_argument); + /* Abort test with error code and error message */ + die("%s", command->first_argument); + break; + case Q_EXIT: + /* Stop processing any more commands */ + abort_flag= 1; + break; + + case Q_RESULT: + die("result, deprecated command"); break; default: @@ -5518,33 +5800,46 @@ int main(int argc, char **argv) if (!processed) { current_line_inc= 0; - switch (q->type) { - case Q_WHILE: do_block(cmd_while, q); break; - case Q_IF: do_block(cmd_if, q); break; - case Q_END_BLOCK: do_done(q); break; + switch (command->type) { + case Q_WHILE: do_block(cmd_while, command); break; + case Q_IF: do_block(cmd_if, command); break; + case Q_END_BLOCK: do_done(command); break; default: current_line_inc = 1; break; } } else - check_eol_junk(q->last_argument); + check_eol_junk(command->last_argument); - if (q->type != Q_ERROR) + if (command->type != Q_ERROR && + command->type != Q_COMMENT) { /* - As soon as any non "error" command has been executed, + As soon as any non "error" command or comment has been executed, the array with expected errors should be cleared */ - global_expected_errors= 0; - bzero((gptr) global_expected_errno, sizeof(global_expected_errno)); + memset(&saved_expected_errors, 0, sizeof(saved_expected_errors)); + } + + if (command_executed != last_command_executed) + { + /* + As soon as any command has been executed, + the replace structures should be cleared + */ + free_all_replace(); } + last_command_executed= command_executed; parser.current_line += current_line_inc; if ( opt_mark_progress ) - mark_progress(q, parser.current_line); + mark_progress(command, parser.current_line); } start_lineno= 0; + if (parsing_disabled) + die("Test ended with parsing disabled"); + /* The whole test has been executed _sucessfully_. Time to compare result or save it to record file. @@ -5552,25 +5847,27 @@ int main(int argc, char **argv) */ if (ds_res.length) { - if (result_file) + if (result_file_name) { + /* A result file has been specified */ + if (record) { - /* Dump the output from test to result file */ - str_to_file(result_file, ds_res.str, ds_res.length); + /* Recording - dump the output from test to result file */ + str_to_file(result_file_name, ds_res.str, ds_res.length); } else { /* Check that the output from test is equal to result file - detect missing result file - detect zero size result file - */ - check_result(&ds_res, result_file, 0); + */ + check_result(&ds_res); } } else { - /* No result_file specified to compare with, print to stdout */ + /* No result_file_name specified to compare with, print to stdout */ printf("%s", ds_res.str); } } @@ -5579,7 +5876,8 @@ int main(int argc, char **argv) die("The test didn't produce any output"); } - if (!query_executed && result_file && my_stat(result_file, &res_info, 0)) + if (!command_executed && + result_file_name && my_stat(result_file_name, &res_info, 0)) { /* my_stat() successful on result file. Check if we have not run a @@ -5591,14 +5889,16 @@ int main(int argc, char **argv) die("No queries executed but result file found!"); } - if ( opt_mark_progress ) - dump_progress(result_file); - dynstr_free(&ds_progress); + if ( opt_mark_progress && result_file_name ) + dump_progress(); + + /* Dump warning messages */ + if (result_file_name && ds_warning_messages.length) + dump_warning_messages(); dynstr_free(&ds_res); - if (!got_end_timer) - timer_output(); /* No end_timer cmd, end it */ + timer_output(); free_used_memory(); my_end(MY_CHECK_ERROR); @@ -5611,101 +5911,188 @@ int main(int argc, char **argv) /* - Read arguments for embedded server and put them into - embedded_server_args_count and embedded_server_args[] -*/ + A primitive timer that give results in milliseconds if the + --timer-file=<filename> is given. The timer result is written + to that file when the result is available. To not confuse + mysql-test-run with an old obsolete result, we remove the file + before executing any commands. The time we measure is + - If no explicit 'start_timer' or 'end_timer' is given in the + test case, the timer measure how long we execute in mysqltest. -static int read_server_arguments(const char *name) -{ - char argument[1024],buff[FN_REFLEN], *str=0; - FILE *file; + - If only 'start_timer' is given we measure how long we execute + from that point until we terminate mysqltest. - if (!test_if_hard_path(name)) + - If only 'end_timer' is given we measure how long we execute + from that we enter mysqltest to the 'end_timer' is command is + executed. + + - If both 'start_timer' and 'end_timer' are given we measure + the time between executing the two commands. +*/ + +void timer_output(void) +{ + if (timer_file) { - strxmov(buff, opt_basedir, name, NullS); - name=buff; + char buf[32], *end; + ulonglong timer= timer_now() - timer_start; + end= longlong2str(timer, buf, 10); + str_to_file(timer_file,buf, (int) (end-buf)); + /* Timer has been written to the file, don't use it anymore */ + timer_file= 0; } - fn_format(buff, name, "", "", MY_UNPACK_FILENAME); +} - if (!embedded_server_arg_count) + +ulonglong timer_now(void) +{ + return my_getsystime() / 10000; +} + + +/* + Get arguments for replace_columns. The syntax is: + replace-column column_number to_string [column_number to_string ...] + Where each argument may be quoted with ' or " + A argument may also be a variable, in which case the value of the + variable is replaced. +*/ + +void do_get_replace_column(struct st_command *command) +{ + char *from= command->first_argument; + char *buff, *start; + DBUG_ENTER("get_replace_columns"); + + free_replace_column(); + if (!*from) + die("Missing argument in %s", command->query); + + /* Allocate a buffer for results */ + start= buff= my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE)); + while (*from) { - embedded_server_arg_count=1; - embedded_server_args[0]= (char*) ""; /* Progname */ + char *to; + uint column_number; + + to= get_string(&buff, &from, command); + if (!(column_number= atoi(to)) || column_number > MAX_COLUMNS) + die("Wrong column number to replace_column in '%s'", command->query); + if (!*from) + die("Wrong number of arguments to replace_column in '%s'", command->query); + to= get_string(&buff, &from, command); + my_free(replace_column[column_number-1], MY_ALLOW_ZERO_PTR); + replace_column[column_number-1]= my_strdup(to, MYF(MY_WME | MY_FAE)); + set_if_bigger(max_replace_column, column_number); } - if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME)))) - return 1; - while (embedded_server_arg_count < MAX_SERVER_ARGS && - (str=fgets(argument,sizeof(argument), file))) + my_free(start, MYF(0)); + command->last_argument= command->end; +} + + +void free_replace_column() +{ + uint i; + for (i=0 ; i < max_replace_column ; i++) { - *(strend(str)-1)=0; /* Remove end newline */ - if (!(embedded_server_args[embedded_server_arg_count]= - (char*) my_strdup(str,MYF(MY_WME)))) + if (replace_column[i]) { - my_fclose(file,MYF(0)); - return 1; + my_free(replace_column[i], 0); + replace_column[i]= 0; } - embedded_server_arg_count++; } - my_fclose(file,MYF(0)); - if (str) - { - fprintf(stderr,"Too many arguments in option file: %s\n",name); - return 1; - } - return 0; + max_replace_column= 0; } -/****************************************************************************\ - * - * A primitive timer that give results in milliseconds if the - * --timer-file=<filename> is given. The timer result is written - * to that file when the result is available. To not confuse - * mysql-test-run with an old obsolete result, we remove the file - * before executing any commands. The time we measure is - * - * - If no explicit 'start_timer' or 'end_timer' is given in the - * test case, the timer measure how long we execute in mysqltest. - * - * - If only 'start_timer' is given we measure how long we execute - * from that point until we terminate mysqltest. - * - * - If only 'end_timer' is given we measure how long we execute - * from that we enter mysqltest to the 'end_timer' is command is - * executed. - * - * - If both 'start_timer' and 'end_timer' are given we measure - * the time between executing the two commands. - * -\****************************************************************************/ - -static void timer_output(void) + +/****************************************************************************/ +/* + Replace functions +*/ + +/* Definitions for replace result */ + +typedef struct st_pointer_array { /* when using array-strings */ + TYPELIB typelib; /* Pointer to strings */ + byte *str; /* Strings is here */ + int7 *flag; /* Flag about each var. */ + uint array_allocs,max_count,length,max_length; +} POINTER_ARRAY; + +struct st_replace; +struct st_replace *init_replace(my_string *from, my_string *to, uint count, + my_string word_end_chars); +int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name); +void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds, + const char *from, int len); +void free_pointer_array(POINTER_ARRAY *pa); + +struct st_replace *glob_replace; + +/* + Get arguments for replace. The syntax is: + replace from to [from to ...] + Where each argument may be quoted with ' or " + A argument may also be a variable, in which case the value of the + variable is replaced. +*/ + +void do_get_replace(struct st_command *command) { - if (timer_file) + uint i; + char *from= command->first_argument; + char *buff, *start; + char word_end_chars[256], *pos; + POINTER_ARRAY to_array, from_array; + DBUG_ENTER("get_replace"); + + free_replace(); + + bzero((char*) &to_array,sizeof(to_array)); + bzero((char*) &from_array,sizeof(from_array)); + if (!*from) + die("Missing argument in %s", command->query); + start= buff= my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE)); + while (*from) { - char buf[32], *end; - ulonglong timer= timer_now() - timer_start; - end= longlong2str(timer, buf, 10); - str_to_file(timer_file,buf, (int) (end-buf)); + char *to= buff; + to= get_string(&buff, &from, command); + if (!*from) + die("Wrong number of arguments to replace_result in '%s'", + command->query); + insert_pointer_name(&from_array,to); + to= get_string(&buff, &from, command); + insert_pointer_name(&to_array,to); } + for (i= 1,pos= word_end_chars ; i < 256 ; i++) + if (my_isspace(charset_info,i)) + *pos++= i; + *pos=0; /* End pointer */ + if (!(glob_replace= init_replace((char**) from_array.typelib.type_names, + (char**) to_array.typelib.type_names, + (uint) from_array.typelib.count, + word_end_chars))) + die("Can't initialize replace from '%s'", command->query); + free_pointer_array(&from_array); + free_pointer_array(&to_array); + my_free(start, MYF(0)); + command->last_argument= command->end; + DBUG_VOID_RETURN; } -static ulonglong timer_now(void) + +void free_replace() { - return my_getsystime() / 10000; + DBUG_ENTER("free_replace"); + if (glob_replace) + { + my_free((char*) glob_replace,MYF(0)); + glob_replace=0; + } + DBUG_VOID_RETURN; } -/**************************************************************************** -* Handle replacement of strings -****************************************************************************/ - -#define PC_MALLOC 256 /* Bytes for pointers */ -#define PS_MALLOC 512 /* Bytes for data */ - -#define SPACE_CHAR 256 -#define START_OF_LINE 257 -#define END_OF_LINE 258 -#define LAST_CHAR_CODE 259 typedef struct st_replace { bool found; @@ -5719,99 +6106,514 @@ typedef struct st_replace_found { int from_offset; } REPLACE_STRING; -#ifndef WORD_BIT -#define WORD_BIT (8*sizeof(uint)) -#endif +void replace_strings_append(REPLACE *rep, DYNAMIC_STRING* ds, + const char *str, int len) +{ + reg1 REPLACE *rep_pos; + reg2 REPLACE_STRING *rep_str; + const char *start, *from; + DBUG_ENTER("replace_strings_append"); + + start= from= str; + rep_pos=rep+1; + for (;;) + { + /* Loop through states */ + DBUG_PRINT("info", ("Looping through states")); + while (!rep_pos->found) + rep_pos= rep_pos->next[(uchar) *from++]; + + /* Does this state contain a string to be replaced */ + if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string) + { + /* No match found */ + dynstr_append_mem(ds, start, from - start - 1); + DBUG_PRINT("exit", ("Found no more string to replace, appended: %s", start)); + DBUG_VOID_RETURN; + } -static int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name) + /* Found a string that needs to be replaced */ + DBUG_PRINT("info", ("found: %d, to_offset: %d, from_offset: %d, string: %s", + rep_str->found, rep_str->to_offset, + rep_str->from_offset, rep_str->replace_string)); + + /* Append part of original string before replace string */ + dynstr_append_mem(ds, start, (from - rep_str->to_offset) - start); + + /* Append replace string */ + dynstr_append_mem(ds, rep_str->replace_string, + strlen(rep_str->replace_string)); + + if (!*(from-=rep_str->from_offset) && rep_pos->found != 2) + { + /* End of from string */ + DBUG_PRINT("exit", ("Found end of from string")); + DBUG_VOID_RETURN; + } + DBUG_ASSERT(from <= str+len); + start= from; + rep_pos=rep; + } +} + + +/* + Regex replace functions +*/ + + +/* Stores regex substitutions */ + +struct st_regex { - uint i,length,old_count; - byte *new_pos; - const char **new_array; - DBUG_ENTER("insert_pointer_name"); + char* pattern; /* Pattern to be replaced */ + char* replace; /* String or expression to replace the pattern with */ + int icase; /* true if the match is case insensitive */ +}; - if (! pa->typelib.count) +struct st_replace_regex +{ + DYNAMIC_ARRAY regex_arr; /* stores a list of st_regex subsitutions */ + + /* + Temporary storage areas for substitutions. To reduce unnessary copying + and memory freeing/allocation, we pre-allocate two buffers, and alternate + their use, one for input/one for output, the roles changing on the next + st_regex substition. At the end of substitutions buf points to the + one containing the final result. + */ + char* buf; + char* even_buf; + char* odd_buf; + int even_buf_len; + int odd_buf_len; +}; + +struct st_replace_regex *glob_replace_regex= 0; + +int reg_replace(char** buf_p, int* buf_len_p, char *pattern, char *replace, + char *string, int icase); + + + +/* + Finds the next (non-escaped) '/' in the expression. + (If the character '/' is needed, it can be escaped using '\'.) +*/ + +#define PARSE_REGEX_ARG \ + while (p < expr_end) \ + { \ + char c= *p; \ + if (c == '/') \ + { \ + if (last_c == '\\') \ + { \ + buf_p[-1]= '/'; \ + } \ + else \ + { \ + *buf_p++ = 0; \ + break; \ + } \ + } \ + else \ + *buf_p++ = c; \ + \ + last_c= c; \ + p++; \ + } \ + \ +/* + Initializes the regular substitution expression to be used in the + result output of test. + + Returns: st_replace_regex struct with pairs of substitutions +*/ + +struct st_replace_regex* init_replace_regex(char* expr) +{ + struct st_replace_regex* res; + char* buf,*expr_end; + char* p; + char* buf_p; + uint expr_len= strlen(expr); + char last_c = 0; + struct st_regex reg; + + /* my_malloc() will die on fail with MY_FAE */ + res=(struct st_replace_regex*)my_malloc( + sizeof(*res)+expr_len ,MYF(MY_FAE+MY_WME)); + my_init_dynamic_array(&res->regex_arr,sizeof(struct st_regex),128,128); + + buf= (char*)res + sizeof(*res); + expr_end= expr + expr_len; + p= expr; + buf_p= buf; + + /* for each regexp substitution statement */ + while (p < expr_end) { - if (!(pa->typelib.type_names=(const char **) - my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/ - (sizeof(my_string)+sizeof(*pa->flag))* - (sizeof(my_string)+sizeof(*pa->flag))),MYF(MY_WME)))) - DBUG_RETURN(-1); - if (!(pa->str= (byte*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD), - MYF(MY_WME)))) + bzero(®,sizeof(reg)); + /* find the start of the statement */ + while (p < expr_end) { - my_free((gptr) pa->typelib.type_names,MYF(0)); - DBUG_RETURN (-1); + if (*p == '/') + break; + p++; } - pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(byte*)+ - sizeof(*pa->flag)); - pa->flag= (int7*) (pa->typelib.type_names+pa->max_count); - pa->length=0; - pa->max_length=PS_MALLOC-MALLOC_OVERHEAD; - pa->array_allocs=1; + + if (p == expr_end || ++p == expr_end) + { + if (res->regex_arr.elements) + break; + else + goto err; + } + /* we found the start */ + reg.pattern= buf_p; + + /* Find first argument -- pattern string to be removed */ + PARSE_REGEX_ARG + + if (p == expr_end || ++p == expr_end) + goto err; + + /* buf_p now points to the replacement pattern terminated with \0 */ + reg.replace= buf_p; + + /* Find second argument -- replace string to replace pattern */ + PARSE_REGEX_ARG + + if (p == expr_end) + goto err; + + /* skip the ending '/' in the statement */ + p++; + + /* Check if we should do matching case insensitive */ + if (p < expr_end && *p == 'i') + reg.icase= 1; + + /* done parsing the statement, now place it in regex_arr */ + if (insert_dynamic(&res->regex_arr,(gptr) ®)) + die("Out of memory"); } - length=(uint) strlen(name)+1; - if (pa->length+length >= pa->max_length) + res->odd_buf_len= res->even_buf_len= 8192; + res->even_buf= (char*)my_malloc(res->even_buf_len,MYF(MY_WME+MY_FAE)); + res->odd_buf= (char*)my_malloc(res->odd_buf_len,MYF(MY_WME+MY_FAE)); + res->buf= res->even_buf; + + return res; + +err: + my_free((gptr)res,0); + die("Error parsing replace_regex \"%s\"", expr); + return 0; +} + +/* + Execute all substitutions on val. + + Returns: true if substituition was made, false otherwise + Side-effect: Sets r->buf to be the buffer with all substitutions done. + + IN: + struct st_replace_regex* r + char* val + Out: + struct st_replace_regex* r + r->buf points at the resulting buffer + r->even_buf and r->odd_buf might have been reallocated + r->even_buf_len and r->odd_buf_len might have been changed + + TODO: at some point figure out if there is a way to do everything + in one pass +*/ + +int multi_reg_replace(struct st_replace_regex* r,char* val) +{ + uint i; + char* in_buf, *out_buf; + int* buf_len_p; + + in_buf= val; + out_buf= r->even_buf; + buf_len_p= &r->even_buf_len; + r->buf= 0; + + /* For each substitution, do the replace */ + for (i= 0; i < r->regex_arr.elements; i++) { - if (!(new_pos= (byte*) my_realloc((gptr) pa->str, - (uint) (pa->max_length+PS_MALLOC), - MYF(MY_WME)))) - DBUG_RETURN(1); - if (new_pos != pa->str) + struct st_regex re; + char* save_out_buf= out_buf; + + get_dynamic(&r->regex_arr,(gptr)&re,i); + + if (!reg_replace(&out_buf, buf_len_p, re.pattern, re.replace, + in_buf, re.icase)) { - my_ptrdiff_t diff=PTR_BYTE_DIFF(new_pos,pa->str); - for (i=0 ; i < pa->typelib.count ; i++) - pa->typelib.type_names[i]= ADD_TO_PTR(pa->typelib.type_names[i],diff, - char*); - pa->str=new_pos; + /* if the buffer has been reallocated, make adjustements */ + if (save_out_buf != out_buf) + { + if (save_out_buf == r->even_buf) + r->even_buf= out_buf; + else + r->odd_buf= out_buf; + } + + r->buf= out_buf; + if (in_buf == val) + in_buf= r->odd_buf; + + swap_variables(char*,in_buf,out_buf); + + buf_len_p= (out_buf == r->even_buf) ? &r->even_buf_len : + &r->odd_buf_len; } - pa->max_length+=PS_MALLOC; } - if (pa->typelib.count >= pa->max_count-1) + + return (r->buf == 0); +} + +/* + Parse the regular expression to be used in all result files + from now on. + + The syntax is --replace_regex /from/to/i /from/to/i ... + i means case-insensitive match. If omitted, the match is + case-sensitive + +*/ +void do_get_replace_regex(struct st_command *command) +{ + char *expr= command->first_argument; + free_replace_regex(); + if (!(glob_replace_regex=init_replace_regex(expr))) + die("Could not init replace_regex"); + command->last_argument= command->end; +} + +void free_replace_regex() +{ + if (glob_replace_regex) { - int len; - pa->array_allocs++; - len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD); - if (!(new_array=(const char **) my_realloc((gptr) pa->typelib.type_names, - (uint) len/ - (sizeof(byte*)+sizeof(*pa->flag))* - (sizeof(byte*)+sizeof(*pa->flag)), - MYF(MY_WME)))) - DBUG_RETURN(1); - pa->typelib.type_names=new_array; - old_count=pa->max_count; - pa->max_count=len/(sizeof(byte*) + sizeof(*pa->flag)); - pa->flag= (int7*) (pa->typelib.type_names+pa->max_count); - memcpy((byte*) pa->flag,(my_string) (pa->typelib.type_names+old_count), - old_count*sizeof(*pa->flag)); + delete_dynamic(&glob_replace_regex->regex_arr); + my_free(glob_replace_regex->even_buf,MYF(MY_ALLOW_ZERO_PTR)); + my_free(glob_replace_regex->odd_buf,MYF(MY_ALLOW_ZERO_PTR)); + my_free((char*) glob_replace_regex,MYF(0)); + glob_replace_regex=0; } - pa->flag[pa->typelib.count]=0; /* Reset flag */ - pa->typelib.type_names[pa->typelib.count++]= pa->str+pa->length; - pa->typelib.type_names[pa->typelib.count]= NullS; /* Put end-mark */ - VOID(strmov(pa->str+pa->length,name)); - pa->length+=length; - DBUG_RETURN(0); -} /* insert_pointer_name */ +} - /* free pointer array */ -void free_pointer_array(POINTER_ARRAY *pa) +/* + auxiluary macro used by reg_replace + makes sure the result buffer has sufficient length +*/ +#define SECURE_REG_BUF if (buf_len < need_buf_len) \ + { \ + int off= res_p - buf; \ + buf= (char*)my_realloc(buf,need_buf_len,MYF(MY_WME+MY_FAE)); \ + res_p= buf + off; \ + buf_len= need_buf_len; \ + } \ + \ +/* + Performs a regex substitution + + IN: + + buf_p - result buffer pointer. Will change if reallocated + buf_len_p - result buffer length. Will change if the buffer is reallocated + pattern - regexp pattern to match + replace - replacement expression + string - the string to perform substituions in + icase - flag, if set to 1 the match is case insensitive +*/ +int reg_replace(char** buf_p, int* buf_len_p, char *pattern, + char *replace, char *string, int icase) { - if (pa->typelib.count) + my_regex_t r; + my_regmatch_t *subs; + char *buf_end, *replace_end; + char *buf= *buf_p; + int len; + int buf_len, need_buf_len; + int cflags= REG_EXTENDED; + int err_code; + char *res_p,*str_p,*str_end; + + buf_len= *buf_len_p; + len= strlen(string); + str_end= string + len; + + /* start with a buffer of a reasonable size that hopefully will not + need to be reallocated + */ + need_buf_len= len * 2 + 1; + res_p= buf; + + SECURE_REG_BUF + + buf_end= buf + buf_len; + + if (icase) + cflags|= REG_ICASE; + + if ((err_code= my_regcomp(&r,pattern,cflags,&my_charset_latin1))) { - pa->typelib.count=0; - my_free((gptr) pa->typelib.type_names,MYF(0)); - pa->typelib.type_names=0; - my_free((gptr) pa->str,MYF(0)); + check_regerr(&r,err_code); + return 1; } -} /* free_pointer_array */ + subs= (my_regmatch_t*)my_malloc(sizeof(my_regmatch_t) * (r.re_nsub+1), + MYF(MY_WME+MY_FAE)); + + *res_p= 0; + str_p= string; + replace_end= replace + strlen(replace); + + /* for each pattern match instance perform a replacement */ + while (!err_code) + { + /* find the match */ + err_code= my_regexec(&r,str_p, r.re_nsub+1, subs, + (str_p == string) ? REG_NOTBOL : 0); + + /* if regular expression error (eg. bad syntax, or out of memory) */ + if (err_code && err_code != REG_NOMATCH) + { + check_regerr(&r,err_code); + my_regfree(&r); + return 1; + } + + /* if match found */ + if (!err_code) + { + char* expr_p= replace; + int c; + + /* + we need at least what we have so far in the buffer + the part + before this match + */ + need_buf_len= (res_p - buf) + subs[0].rm_so; + + /* on this pass, calculate the memory for the result buffer */ + while (expr_p < replace_end) + { + int back_ref_num= -1; + c= *expr_p; + + if (c == '\\' && expr_p + 1 < replace_end) + { + back_ref_num= expr_p[1] - '0'; + } + + /* found a valid back_ref (eg. \1)*/ + if (back_ref_num >= 0 && back_ref_num <= (int)r.re_nsub) + { + int start_off,end_off; + if ((start_off=subs[back_ref_num].rm_so) > -1 && + (end_off=subs[back_ref_num].rm_eo) > -1) + { + need_buf_len += (end_off - start_off); + } + expr_p += 2; + } + else + { + expr_p++; + need_buf_len++; + } + } + need_buf_len++; + /* + now that we know the size of the buffer, + make sure it is big enough + */ + SECURE_REG_BUF + + /* copy the pre-match part */ + if (subs[0].rm_so) + { + memcpy(res_p, str_p, subs[0].rm_so); + res_p+= subs[0].rm_so; + } + + expr_p= replace; + + /* copy the match and expand back_refs */ + while (expr_p < replace_end) + { + int back_ref_num= -1; + c= *expr_p; + + if (c == '\\' && expr_p + 1 < replace_end) + { + back_ref_num= expr_p[1] - '0'; + } - /* Code for replace rutines */ + if (back_ref_num >= 0 && back_ref_num <= (int)r.re_nsub) + { + int start_off,end_off; + if ((start_off=subs[back_ref_num].rm_so) > -1 && + (end_off=subs[back_ref_num].rm_eo) > -1) + { + int block_len= end_off - start_off; + memcpy(res_p,str_p + start_off, block_len); + res_p += block_len; + } + expr_p += 2; + } + else + { + *res_p++ = *expr_p++; + } + } + + /* handle the post-match part */ + if (subs[0].rm_so == subs[0].rm_eo) + { + if (str_p + subs[0].rm_so >= str_end) + break; + str_p += subs[0].rm_eo ; + *res_p++ = *str_p++; + } + else + { + str_p += subs[0].rm_eo; + } + } + else /* no match this time, just copy the string as is */ + { + int left_in_str= str_end-str_p; + need_buf_len= (res_p-buf) + left_in_str; + SECURE_REG_BUF + memcpy(res_p,str_p,left_in_str); + res_p += left_in_str; + str_p= str_end; + } + } + my_free((gptr)subs, MYF(0)); + my_regfree(&r); + *res_p= 0; + *buf_p= buf; + *buf_len_p= buf_len; + return 0; +} + + +#ifndef WORD_BIT +#define WORD_BIT (8*sizeof(uint)) +#endif #define SET_MALLOC_HUNC 64 +#define LAST_CHAR_CODE 259 typedef struct st_rep_set { uint *bits; /* Pointer to used sets */ @@ -5843,32 +6645,48 @@ typedef struct st_follow { } FOLLOWS; -static int init_sets(REP_SETS *sets,uint states); -static REP_SET *make_new_set(REP_SETS *sets); -static void make_sets_invisible(REP_SETS *sets); -static void free_last_set(REP_SETS *sets); -static void free_sets(REP_SETS *sets); -static void internal_set_bit(REP_SET *set, uint bit); -static void internal_clear_bit(REP_SET *set, uint bit); -static void or_bits(REP_SET *to,REP_SET *from); -static void copy_bits(REP_SET *to,REP_SET *from); -static int cmp_bits(REP_SET *set1,REP_SET *set2); -static int get_next_bit(REP_SET *set,uint lastpos); -static int find_set(REP_SETS *sets,REP_SET *find); -static int find_found(FOUND_SET *found_set,uint table_offset, - int found_offset); -static uint start_at_word(my_string pos); -static uint end_of_word(my_string pos); -static uint replace_len(my_string pos); +int init_sets(REP_SETS *sets,uint states); +REP_SET *make_new_set(REP_SETS *sets); +void make_sets_invisible(REP_SETS *sets); +void free_last_set(REP_SETS *sets); +void free_sets(REP_SETS *sets); +void internal_set_bit(REP_SET *set, uint bit); +void internal_clear_bit(REP_SET *set, uint bit); +void or_bits(REP_SET *to,REP_SET *from); +void copy_bits(REP_SET *to,REP_SET *from); +int cmp_bits(REP_SET *set1,REP_SET *set2); +int get_next_bit(REP_SET *set,uint lastpos); +int find_set(REP_SETS *sets,REP_SET *find); +int find_found(FOUND_SET *found_set,uint table_offset, + int found_offset); +uint start_at_word(my_string pos); +uint end_of_word(my_string pos); static uint found_sets=0; - /* Init a replace structure for further calls */ +uint replace_len(my_string str) +{ + uint len=0; + while (*str) + { + if (str[0] == '\\' && str[1]) + str++; + str++; + len++; + } + return len; +} + +/* Init a replace structure for further calls */ REPLACE *init_replace(my_string *from, my_string *to,uint count, my_string word_end_chars) { + static const int SPACE_CHAR= 256; + static const int START_OF_LINE= 257; + static const int END_OF_LINE= 258; + uint i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr; int used_sets,chr,default_state; char used_chars[LAST_CHAR_CODE],is_word_end[256]; @@ -5921,7 +6739,7 @@ REPLACE *init_replace(my_string *from, my_string *to,uint count, DBUG_RETURN(0); } - /* Init follow_ptr[] */ + /* Init follow_ptr[] */ for (i=0, states=1, follow_ptr=follow+1 ; i < count ; i++) { if (from[i][0] == '\\' && from[i][1] == '^') @@ -6104,7 +6922,7 @@ REPLACE *init_replace(my_string *from, my_string *to,uint count, } } - /* Alloc replace structure for the replace-state-machine */ + /* Alloc replace structure for the replace-state-machine */ if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+ sizeof(REPLACE_STRING)*(found_sets+1)+ @@ -6147,7 +6965,7 @@ REPLACE *init_replace(my_string *from, my_string *to,uint count, } -static int init_sets(REP_SETS *sets,uint states) +int init_sets(REP_SETS *sets,uint states) { bzero((char*) sets,sizeof(*sets)); sets->size_of_bits=((states+7)/8); @@ -6163,16 +6981,16 @@ static int init_sets(REP_SETS *sets,uint states) return 0; } - /* Make help sets invisible for nicer codeing */ +/* Make help sets invisible for nicer codeing */ -static void make_sets_invisible(REP_SETS *sets) +void make_sets_invisible(REP_SETS *sets) { sets->invisible=sets->count; sets->set+=sets->count; sets->count=0; } -static REP_SET *make_new_set(REP_SETS *sets) +REP_SET *make_new_set(REP_SETS *sets) { uint i,count,*bit_buffer; REP_SET *set; @@ -6190,7 +7008,7 @@ static REP_SET *make_new_set(REP_SETS *sets) } count=sets->count+sets->invisible+SET_MALLOC_HUNC; if (!(set=(REP_SET*) my_realloc((gptr) sets->set_buffer, - sizeof(REP_SET)*count, + sizeof(REP_SET)*count, MYF(MY_WME)))) return 0; sets->set_buffer=set; @@ -6209,34 +7027,34 @@ static REP_SET *make_new_set(REP_SETS *sets) return make_new_set(sets); } -static void free_last_set(REP_SETS *sets) +void free_last_set(REP_SETS *sets) { sets->count--; sets->extra++; return; } -static void free_sets(REP_SETS *sets) +void free_sets(REP_SETS *sets) { my_free((gptr)sets->set_buffer,MYF(0)); my_free((gptr)sets->bit_buffer,MYF(0)); return; } -static void internal_set_bit(REP_SET *set, uint bit) +void internal_set_bit(REP_SET *set, uint bit) { set->bits[bit / WORD_BIT] |= 1 << (bit % WORD_BIT); return; } -static void internal_clear_bit(REP_SET *set, uint bit) +void internal_clear_bit(REP_SET *set, uint bit) { set->bits[bit / WORD_BIT] &= ~ (1 << (bit % WORD_BIT)); return; } -static void or_bits(REP_SET *to,REP_SET *from) +void or_bits(REP_SET *to,REP_SET *from) { reg1 uint i; for (i=0 ; i < to->size_of_bits ; i++) @@ -6244,22 +7062,22 @@ static void or_bits(REP_SET *to,REP_SET *from) return; } -static void copy_bits(REP_SET *to,REP_SET *from) +void copy_bits(REP_SET *to,REP_SET *from) { memcpy((byte*) to->bits,(byte*) from->bits, (size_t) (sizeof(uint) * to->size_of_bits)); } -static int cmp_bits(REP_SET *set1,REP_SET *set2) +int cmp_bits(REP_SET *set1,REP_SET *set2) { return bcmp((byte*) set1->bits,(byte*) set2->bits, sizeof(uint) * set1->size_of_bits); } - /* Get next set bit from set. */ +/* Get next set bit from set. */ -static int get_next_bit(REP_SET *set,uint lastpos) +int get_next_bit(REP_SET *set,uint lastpos) { uint pos,*start,*end,bits; @@ -6280,11 +7098,11 @@ static int get_next_bit(REP_SET *set,uint lastpos) return pos; } - /* find if there is a same set in sets. If there is, use it and - free given set, else put in given set in sets and return its - position */ +/* find if there is a same set in sets. If there is, use it and + free given set, else put in given set in sets and return its + position */ -static int find_set(REP_SETS *sets,REP_SET *find) +int find_set(REP_SETS *sets,REP_SET *find) { uint i; for (i=0 ; i < sets->count-1 ; i++) @@ -6298,14 +7116,14 @@ static int find_set(REP_SETS *sets,REP_SET *find) return i; /* return new postion */ } - /* find if there is a found_set with same table_offset & found_offset - If there is return offset to it, else add new offset and return pos. - Pos returned is -offset-2 in found_set_structure because it is - saved in set->next and set->next[] >= 0 points to next set and - set->next[] == -1 is reserved for end without replaces. - */ +/* find if there is a found_set with same table_offset & found_offset + If there is return offset to it, else add new offset and return pos. + Pos returned is -offset-2 in found_set_structure because it is + saved in set->next and set->next[] >= 0 points to next set and + set->next[] == -1 is reserved for end without replaces. +*/ -static int find_found(FOUND_SET *found_set,uint table_offset, int found_offset) +int find_found(FOUND_SET *found_set,uint table_offset, int found_offset) { int i; for (i=0 ; (uint) i < found_sets ; i++) @@ -6318,145 +7136,153 @@ static int find_found(FOUND_SET *found_set,uint table_offset, int found_offset) return -i-2; /* return new postion */ } - /* Return 1 if regexp starts with \b or ends with \b*/ +/* Return 1 if regexp starts with \b or ends with \b*/ -static uint start_at_word(my_string pos) +uint start_at_word(my_string pos) { return (((!bcmp(pos,"\\b",2) && pos[2]) || !bcmp(pos,"\\^",2)) ? 1 : 0); } -static uint end_of_word(my_string pos) +uint end_of_word(my_string pos) { my_string end=strend(pos); return ((end > pos+2 && !bcmp(end-2,"\\b",2)) || (end >= pos+2 && !bcmp(end-2,"\\$",2))) ? - 1 : 0; + 1 : 0; } +/**************************************************************************** + * Handle replacement of strings + ****************************************************************************/ -static uint replace_len(my_string str) -{ - uint len=0; - while (*str) - { - if (str[0] == '\\' && str[1]) - str++; - str++; - len++; - } - return len; -} - +#define PC_MALLOC 256 /* Bytes for pointers */ +#define PS_MALLOC 512 /* Bytes for data */ -/* Replace strings while appending to ds */ -void replace_strings_append(REPLACE *rep, DYNAMIC_STRING* ds, - const char *str, int len) +int insert_pointer_name(reg1 POINTER_ARRAY *pa,my_string name) { - reg1 REPLACE *rep_pos; - reg2 REPLACE_STRING *rep_str; - const char *start, *from; - DBUG_ENTER("replace_strings_append"); + uint i,length,old_count; + byte *new_pos; + const char **new_array; + DBUG_ENTER("insert_pointer_name"); - start= from= str; - rep_pos=rep+1; - for (;;) + if (! pa->typelib.count) { - /* Loop through states */ - DBUG_PRINT("info", ("Looping through states")); - while (!rep_pos->found) - rep_pos= rep_pos->next[(uchar) *from++]; - - /* Does this state contain a string to be replaced */ - if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string) + if (!(pa->typelib.type_names=(const char **) + my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/ + (sizeof(my_string)+sizeof(*pa->flag))* + (sizeof(my_string)+sizeof(*pa->flag))),MYF(MY_WME)))) + DBUG_RETURN(-1); + if (!(pa->str= (byte*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD), + MYF(MY_WME)))) { - /* No match found */ - dynstr_append_mem(ds, start, from - start - 1); - DBUG_PRINT("exit", ("Found no more string to replace, appended: %s", start)); - DBUG_VOID_RETURN; + my_free((gptr) pa->typelib.type_names,MYF(0)); + DBUG_RETURN (-1); } - - /* Found a string that needs to be replaced */ - DBUG_PRINT("info", ("found: %d, to_offset: %d, from_offset: %d, string: %s", - rep_str->found, rep_str->to_offset, - rep_str->from_offset, rep_str->replace_string)); - - /* Append part of original string before replace string */ - dynstr_append_mem(ds, start, (from - rep_str->to_offset) - start); - - /* Append replace string */ - dynstr_append_mem(ds, rep_str->replace_string, - strlen(rep_str->replace_string)); - - if (!*(from-=rep_str->from_offset) && rep_pos->found != 2) + pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(byte*)+ + sizeof(*pa->flag)); + pa->flag= (int7*) (pa->typelib.type_names+pa->max_count); + pa->length=0; + pa->max_length=PS_MALLOC-MALLOC_OVERHEAD; + pa->array_allocs=1; + } + length=(uint) strlen(name)+1; + if (pa->length+length >= pa->max_length) + { + if (!(new_pos= (byte*) my_realloc((gptr) pa->str, + (uint) (pa->max_length+PS_MALLOC), + MYF(MY_WME)))) + DBUG_RETURN(1); + if (new_pos != pa->str) { - /* End of from string */ - DBUG_PRINT("exit", ("Found end of from string")); - DBUG_VOID_RETURN; + my_ptrdiff_t diff=PTR_BYTE_DIFF(new_pos,pa->str); + for (i=0 ; i < pa->typelib.count ; i++) + pa->typelib.type_names[i]= ADD_TO_PTR(pa->typelib.type_names[i],diff, + char*); + pa->str=new_pos; } - DBUG_ASSERT(from <= str+len); - start= from; - rep_pos=rep; + pa->max_length+=PS_MALLOC; } -} + if (pa->typelib.count >= pa->max_count-1) + { + int len; + pa->array_allocs++; + len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD); + if (!(new_array=(const char **) my_realloc((gptr) pa->typelib.type_names, + (uint) len/ + (sizeof(byte*)+sizeof(*pa->flag))* + (sizeof(byte*)+sizeof(*pa->flag)), + MYF(MY_WME)))) + DBUG_RETURN(1); + pa->typelib.type_names=new_array; + old_count=pa->max_count; + pa->max_count=len/(sizeof(byte*) + sizeof(*pa->flag)); + pa->flag= (int7*) (pa->typelib.type_names+pa->max_count); + memcpy((byte*) pa->flag,(my_string) (pa->typelib.type_names+old_count), + old_count*sizeof(*pa->flag)); + } + pa->flag[pa->typelib.count]=0; /* Reset flag */ + pa->typelib.type_names[pa->typelib.count++]= pa->str+pa->length; + pa->typelib.type_names[pa->typelib.count]= NullS; /* Put end-mark */ + VOID(strmov(pa->str+pa->length,name)); + pa->length+=length; + DBUG_RETURN(0); +} /* insert_pointer_name */ -/**************************************************************************** - Replace results for a column -*****************************************************************************/ +/* free pointer array */ -static void free_replace_column() +void free_pointer_array(POINTER_ARRAY *pa) { - uint i; - for (i=0 ; i < max_replace_column ; i++) + if (pa->typelib.count) { - if (replace_column[i]) - { - my_free(replace_column[i], 0); - replace_column[i]= 0; - } + pa->typelib.count=0; + my_free((gptr) pa->typelib.type_names,MYF(0)); + pa->typelib.type_names=0; + my_free((gptr) pa->str,MYF(0)); } - max_replace_column= 0; -} +} /* free_pointer_array */ -/* - Get arguments for replace_columns. The syntax is: - replace-column column_number to_string [column_number to_string ...] - Where each argument may be quoted with ' or " - A argument may also be a variable, in which case the value of the - variable is replaced. -*/ -static void get_replace_column(struct st_query *q) -{ - char *from=q->first_argument; - char *buff,*start; - DBUG_ENTER("get_replace_columns"); +/* Functions that uses replace and replace_regex */ - free_replace_column(); - if (!*from) - die("Missing argument in %s", q->query); +/* Append the string to ds, with optional replace */ +void replace_dynstr_append_mem(DYNAMIC_STRING *ds, + const char *val, int len) +{ +#ifdef __WIN__ + fix_win_paths(val, len); +#endif - /* Allocate a buffer for results */ - start=buff=my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE)); - while (*from) + if (glob_replace_regex) { - char *to; - uint column_number; + /* Regex replace */ + if (!multi_reg_replace(glob_replace_regex, (char*)val)) + { + val= glob_replace_regex->buf; + len= strlen(val); + } + } - to= get_string(&buff, &from, q); - if (!(column_number= atoi(to)) || column_number > MAX_COLUMNS) - die("Wrong column number to replace_column in '%s'", q->query); - if (!*from) - die("Wrong number of arguments to replace_column in '%s'", q->query); - to= get_string(&buff, &from, q); - my_free(replace_column[column_number-1], MY_ALLOW_ZERO_PTR); - replace_column[column_number-1]= my_strdup(to, MYF(MY_WME | MY_FAE)); - set_if_bigger(max_replace_column, column_number); + if (glob_replace) + { + /* Normal replace */ + replace_strings_append(glob_replace, ds, val, len); } - my_free(start, MYF(0)); - q->last_argument= q->end; + else + dynstr_append_mem(ds, val, len); } +/* Append zero-terminated string to ds, with optional replace */ +void replace_dynstr_append(DYNAMIC_STRING *ds, const char *val) +{ + replace_dynstr_append_mem(ds, val, strlen(val)); +} - +/* Append uint to ds, with optional replace */ +void replace_dynstr_append_uint(DYNAMIC_STRING *ds, uint val) +{ + char buff[22]; /* This should be enough for any int */ + char *end= longlong10_to_str(val, buff, 10); + replace_dynstr_append_mem(ds, buff, end - buff); +} diff --git a/config/ac-macros/ha_ndbcluster.m4 b/config/ac-macros/ha_ndbcluster.m4 index ee31fa9fca2..a722f8f1d7d 100644 --- a/config/ac-macros/ha_ndbcluster.m4 +++ b/config/ac-macros/ha_ndbcluster.m4 @@ -308,6 +308,19 @@ AC_DEFUN([MYSQL_SETUP_NDBCLUSTER], [ AC_SUBST(NDB_DEFS) AC_SUBST(ndb_cxxflags_fix) + NDB_SIZEOF_CHARP="$ac_cv_sizeof_charp" + NDB_SIZEOF_CHAR="$ac_cv_sizeof_char" + NDB_SIZEOF_SHORT="$ac_cv_sizeof_short" + NDB_SIZEOF_INT="$ac_cv_sizeof_int" + NDB_SIZEOF_LONG="$ac_cv_sizeof_long" + NDB_SIZEOF_LONG_LONG="$ac_cv_sizeof_long_long" + AC_SUBST([NDB_SIZEOF_CHARP]) + AC_SUBST([NDB_SIZEOF_CHAR]) + AC_SUBST([NDB_SIZEOF_SHORT]) + AC_SUBST([NDB_SIZEOF_INT]) + AC_SUBST([NDB_SIZEOF_LONG]) + AC_SUBST([NDB_SIZEOF_LONG_LONG]) + AC_CONFIG_FILES(storage/ndb/include/Makefile dnl storage/ndb/src/Makefile storage/ndb/src/common/Makefile dnl storage/ndb/docs/Makefile dnl diff --git a/config/ac-macros/plugins.m4 b/config/ac-macros/plugins.m4 index 87f057e696a..b022ab67045 100644 --- a/config/ac-macros/plugins.m4 +++ b/config/ac-macros/plugins.m4 @@ -254,6 +254,29 @@ AC_DEFUN([MYSQL_PLUGIN_ACTIONS],[ ]) dnl --------------------------------------------------------------------------- +dnl Macro: MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS +dnl +dnl SYNOPSIS +dnl MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS([name],[file name]) +dnl +dnl DESCRIPTION +dnl Some modules in plugins keep dependance on structures +dnl declared in sql/ (THD class usually) +dnl That has to be fixed in the future, but until then +dnl we have to recompile these modules when we want to +dnl to compile server parts with the different #defines +dnl Normally it happens when we compile the embedded server +dnl Thus one should mark such files in his handler using this macro +dnl (currently only one such a file per plugin is supported) +dnl +dnl --------------------------------------------------------------------------- + +AC_DEFUN([MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS],[ + MYSQL_REQUIRE_PLUGIN([$1]) + m4_define([MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS_]AS_TR_CPP([$1]), [$2]) +]) + +dnl --------------------------------------------------------------------------- dnl Macro: MYSQL_CONFIGURE_PLUGINS dnl dnl SYNOPSIS @@ -282,6 +305,9 @@ AC_DEFUN([MYSQL_CONFIGURE_PLUGINS],[ AC_SUBST([mysql_pg_dirs]) AC_SUBST([mysql_se_unittest_dirs]) AC_SUBST([mysql_pg_unittest_dirs]) + AC_SUBST([condition_dependent_plugin_modules]) + AC_SUBST([condition_dependent_plugin_links]) + AC_SUBST([condition_dependent_plugin_includes]) ]) ]) ]) @@ -307,6 +333,7 @@ AC_DEFUN([_MYSQL_EMIT_CHECK_PLUGIN],[ [MYSQL_PLUGIN_DYNAMIC_]AS_TR_CPP([$1]), [MYSQL_PLUGIN_MANDATORY_]AS_TR_CPP([$1]), [MYSQL_PLUGIN_DISABLED_]AS_TR_CPP([$1]), + [MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS_]AS_TR_CPP([$1]), [MYSQL_PLUGIN_ACTIONS_]AS_TR_CPP([$1]) ) ]) @@ -402,6 +429,11 @@ dnl Although this is "pretty", it breaks libmysqld build mysql_plugin_defs="$mysql_plugin_defs, [builtin_]$2[_plugin]" [with_plugin_]$2=yes AC_MSG_RESULT([yes]) + m4_ifdef([$11],[ + condition_dependent_plugin_modules="$condition_dependent_plugin_modules m4_bregexp($11, [[^/]+$], [\&])" + condition_dependent_plugin_links="$condition_dependent_plugin_links $6/$11" + condition_dependent_plugin_includes="$condition_dependent_plugin_includes -I[\$(top_srcdir)]/$6/m4_bregexp($11, [^.+[/$]], [\&])" + ]) fi m4_ifdef([$6],[ if test -n "$mysql_use_plugin_dir" ; then diff --git a/configure.in b/configure.in index 22de4f2ff17..8fd60b966d6 100644 --- a/configure.in +++ b/configure.in @@ -415,6 +415,10 @@ AC_SUBST(HOSTNAME) AC_SUBST(PERL) AC_SUBST(PERL5) +# icheck, used for ABI check +AC_PATH_PROG(ICHECK, icheck, no) +AC_SUBST(ICHECK) + # Lock for PS AC_PATH_PROG(PS, ps, ps) AC_MSG_CHECKING("how to check if pid exists") @@ -1060,6 +1064,18 @@ EOF s,\(extra/comp_err\)\$(EXEEXT),\1.linux, EOF ;; + libmysql/Makefile.in) + cat > $filesed << EOF +s,libyassl.la,.libs/libyassl.a, +s,libtaocrypt.la,.libs/libtaocrypt.a, +EOF + ;; + libmysql_r/Makefile.in) + cat > $filesed << EOF +s,libyassl.la,.libs/libyassl.a, +s,libtaocrypt.la,.libs/libtaocrypt.a, +EOF + ;; client/Makefile.in) # cat > $filesed << EOF @@ -1441,9 +1457,9 @@ fi # dlopen, dlerror case "$with_mysqld_ldflags " in - *"-static "*) + *"-all-static "*) # No need to check for dlopen when mysqld is linked with - # -all-static or -static as it won't be able to load any functions. + # -all-static as it won't be able to load any functions. # NOTE! It would be better if it was possible to test if dlopen # can be used, but a good way to test it couldn't be found diff --git a/extra/yassl/include/yassl_int.hpp b/extra/yassl/include/yassl_int.hpp index 28e9d237622..0edff289b61 100644 --- a/extra/yassl/include/yassl_int.hpp +++ b/extra/yassl/include/yassl_int.hpp @@ -40,6 +40,13 @@ #include "lock.hpp" #include "openssl/ssl.h" // ASN1_STRING and DH +// Check if _POSIX_THREADS should be forced +#if !defined(_POSIX_THREADS) && (defined(__NETWARE__) || defined(__hpux)) +// HPUX does not define _POSIX_THREADS as it's not _fully_ implemented +// Netware supports pthreads but does not announce it +#define _POSIX_THREADS +#endif + #ifdef _POSIX_THREADS #include <pthread.h> #endif diff --git a/extra/yassl/taocrypt/include/hmac.hpp b/extra/yassl/taocrypt/include/hmac.hpp index d46a6d4e7c3..b710c3aa499 100644 --- a/extra/yassl/taocrypt/include/hmac.hpp +++ b/extra/yassl/taocrypt/include/hmac.hpp @@ -60,12 +60,12 @@ private: T mac_; // MSVC 6 HACK, gives compiler error if calculated in array - enum { BSIZE = T::BLOCK_SIZE / sizeof(word32), - DSIZE = T::DIGEST_SIZE / sizeof(word32) }; + enum { HMAC_BSIZE = T::BLOCK_SIZE / sizeof(word32), + HMAC_DSIZE = T::DIGEST_SIZE / sizeof(word32) }; - word32 ip_[BSIZE]; // align ipad_ on word32 - word32 op_[BSIZE]; // align opad_ on word32 - word32 innerH_[DSIZE]; // align innerHash_ on word32 + word32 ip_[HMAC_BSIZE]; // align ipad_ on word32 + word32 op_[HMAC_BSIZE]; // align opad_ on word32 + word32 innerH_[HMAC_DSIZE]; // align innerHash_ on word32 void KeyInnerHash(); diff --git a/extra/yassl/testsuite/test.hpp b/extra/yassl/testsuite/test.hpp index 0266c802657..b23b36f0ba2 100644 --- a/extra/yassl/testsuite/test.hpp +++ b/extra/yassl/testsuite/test.hpp @@ -27,9 +27,12 @@ #endif /* _WIN32 */ -#if !defined(_SOCKLEN_T) && (defined(_WIN32) || defined(__NETWARE__)) +#if !defined(_SOCKLEN_T) && defined(_WIN32) typedef int socklen_t; #endif +#if !defined(_SOCKLEN_T) && defined(__NETWARE__) + typedef size_t socklen_t; +#endif // Check type of third arg to accept diff --git a/include/Makefile.am b/include/Makefile.am index 26161b36ab8..af061f80ff2 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -15,14 +15,14 @@ # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, # MA 02111-1307, USA -BUILT_SOURCES = mysql_version.h m_ctype.h my_config.h +BUILT_SOURCES = mysql_version.h my_config.h pkginclude_HEADERS = my_dbug.h m_string.h my_sys.h my_list.h my_xml.h \ mysql.h mysql_com.h mysql_embed.h \ my_semaphore.h my_pthread.h my_no_pthread.h \ errmsg.h my_global.h my_net.h my_alloc.h \ my_getopt.h sslopt-longopts.h my_dir.h typelib.h \ sslopt-vars.h sslopt-case.h sql_common.h keycache.h \ - mysql_time.h mysql/plugin.h $(BUILT_SOURCES) + mysql_time.h m_ctype.h mysql/plugin.h $(BUILT_SOURCES) noinst_HEADERS = config-win.h config-netware.h \ heap.h my_bitmap.h my_uctype.h \ myisam.h myisampack.h myisammrg.h ft_global.h\ @@ -35,8 +35,10 @@ noinst_HEADERS = config-win.h config-netware.h \ atomic/rwlock.h atomic/x86-gcc.h atomic/x86-msvc.h \ my_libwrap.h -# mysql_version.h are generated -CLEANFILES = mysql_version.h my_config.h readline openssl +# Remove built files and the symlinked directories +CLEANFILES = $(BUILT_SOURCES) readline openssl + +EXTRA_DIST = mysql_h.ic # Some include files that may be moved and patched by configure DISTCLEANFILES = sched.h $(CLEANFILES) @@ -54,5 +56,22 @@ my_config.h: ../config.h dist-hook: $(RM) -f $(distdir)/mysql_version.h $(distdir)/my_config.h +# +# Rules for checking that ABI has not changed +# + +# Create a icheck file and compare it to the reference +abi_check: mysql.h mysql_version.h mysql_com.h mysql_time.h my_list.h \ + my_alloc.h typelib.h mysql_h.ic + @set -ex; \ + if [ @ICHECK@ != no ] ; then \ + @ICHECK@ --canonify --skip-from-re /usr/ -o $@.ic mysql.h; \ + @ICHECK@ --compare mysql_h.ic $@.ic; \ + fi; \ + touch abi_check; + +#all: abi_check + + # Don't update the files from bitkeeper %::SCCS/s.% diff --git a/include/hash.h b/include/hash.h index 8f5ff21ae5e..4d6ee77fa0c 100644 --- a/include/hash.h +++ b/include/hash.h @@ -65,6 +65,8 @@ my_bool hash_check(HASH *hash); /* Only in debug library */ #define hash_clear(H) bzero((char*) (H),sizeof(*(H))) #define hash_inited(H) ((H)->array.buffer != 0) +#define hash_init_opt(A,B,C,D,E,F,G,H) \ + (!hash_inited(A) && _hash_init(A,B,C,D,E,F,G, H CALLER_INFO)) #ifdef __cplusplus } diff --git a/include/my_dbug.h b/include/my_dbug.h index a397861c1af..f4aaa41b201 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -39,7 +39,8 @@ extern void _db_enter_(const char *_func_,const char *_file_,uint _line_, extern void _db_return_(uint _line_,const char **_sfunc_,const char **_sfile_, uint *_slevel_); extern void _db_pargs_(uint _line_,const char *keyword); -extern void _db_doprnt_ _VARARGS((const char *format,...)); +extern void _db_doprnt_ _VARARGS((const char *format,...)) + ATTRIBUTE_FORMAT(printf, 1, 2); extern void _db_dump_(uint _line_,const char *keyword,const char *memory, uint length); extern void _db_end_(void); diff --git a/include/my_global.h b/include/my_global.h index 39947735f3c..a7ec41068b3 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -614,12 +614,17 @@ C_MODE_END #define _STATIC_VARARGS(X) X #define _PC(X) X +/* The DBUG_ON flag always takes precedence over default DBUG_OFF */ #if defined(DBUG_ON) && defined(DBUG_OFF) #undef DBUG_OFF #endif -#if defined(_lint) && !defined(DBUG_OFF) -#define DBUG_OFF +/* We might be forced to turn debug off, if not turned off already */ +#if (defined(FORCE_DBUG_OFF) || defined(_lint)) && !defined(DBUG_OFF) +# define DBUG_OFF +# ifdef DBUG_ON +# undef DBUG_ON +# endif #endif #include <my_dbug.h> diff --git a/include/my_time.h b/include/my_time.h index d0f2fc323d8..069cecc7b14 100644 --- a/include/my_time.h +++ b/include/my_time.h @@ -57,6 +57,16 @@ typedef long my_time_t; #define TIME_NO_ZERO_DATE (TIME_NO_ZERO_IN_DATE*2) #define TIME_INVALID_DATES (TIME_NO_ZERO_DATE*2) +#define MYSQL_TIME_WARN_TRUNCATED 1 +#define MYSQL_TIME_WARN_OUT_OF_RANGE 2 + +/* Limits for the TIME data type */ +#define TIME_MAX_HOUR 838 +#define TIME_MAX_MINUTE 59 +#define TIME_MAX_SECOND 59 +#define TIME_MAX_VALUE (TIME_MAX_HOUR*10000 + TIME_MAX_MINUTE*100 + \ + TIME_MAX_SECOND) + enum enum_mysql_timestamp_type str_to_datetime(const char *str, uint length, MYSQL_TIME *l_time, uint flags, int *was_cut); @@ -69,7 +79,9 @@ ulonglong TIME_to_ulonglong(const MYSQL_TIME *time); my_bool str_to_time(const char *str,uint length, MYSQL_TIME *l_time, - int *was_cut); + int *warning); + +int check_time_range(struct st_mysql_time *time, int *warning); long calc_daynr(uint year,uint month,uint day); uint calc_days_in_year(uint year); @@ -97,15 +109,25 @@ int my_date_to_str(const MYSQL_TIME *l_time, char *to); int my_datetime_to_str(const MYSQL_TIME *l_time, char *to); int my_TIME_to_str(const MYSQL_TIME *l_time, char *to); -/* - The following must be sorted so that simple intervals comes first. - (get_interval_value() depends on this) +/* + Available interval types used in any statement. + + 'interval_type' must be sorted so that simple intervals comes first, + ie year, quarter, month, week, day, hour, etc. The order based on + interval size is also important and the intervals should be kept in a + large to smaller order. (get_interval_value() depends on this) + + Note: If you change the order of elements in this enum you should fix + order of elements in 'interval_type_to_name' and 'interval_names' + arrays + + See also interval_type_to_name, get_interval_value, interval_names */ enum interval_type { - INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_DAY, INTERVAL_HOUR, - INTERVAL_MINUTE, INTERVAL_WEEK, INTERVAL_SECOND, INTERVAL_MICROSECOND , + INTERVAL_YEAR, INTERVAL_QUARTER, INTERVAL_MONTH, INTERVAL_WEEK, INTERVAL_DAY, + INTERVAL_HOUR, INTERVAL_MINUTE, INTERVAL_SECOND, INTERVAL_MICROSECOND, INTERVAL_YEAR_MONTH, INTERVAL_DAY_HOUR, INTERVAL_DAY_MINUTE, INTERVAL_DAY_SECOND, INTERVAL_HOUR_MINUTE, INTERVAL_HOUR_SECOND, INTERVAL_MINUTE_SECOND, INTERVAL_DAY_MICROSECOND, INTERVAL_HOUR_MICROSECOND, diff --git a/include/mysql.h b/include/mysql.h index ae4a8222c5b..f2a82c99fc3 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -14,6 +14,17 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/* + This file defines the client API to MySQL and also the ABI of the + dynamically linked libmysqlclient. + + The ABI should never be changed in a released product of MySQL + thus you need to take great care when changing the file. In case + the file is changed so the ABI is broken, you must also + update the SHAREDLIB_MAJOR_VERSION in configure.in . + +*/ + #ifndef _mysql_h #define _mysql_h @@ -293,12 +304,6 @@ typedef struct st_mysql /* needed for embedded server - no net buffer to store the 'info' */ char *info_buffer; #endif - /* - In embedded server it points to the statement that is processed - in the current query. We store some results directly in statement - fields then. - */ - struct st_mysql_stmt *current_stmt; } MYSQL; typedef struct st_mysql_res { diff --git a/include/mysql_h.ic b/include/mysql_h.ic new file mode 100644 index 00000000000..51cbb1fb7eb --- /dev/null +++ b/include/mysql_h.ic @@ -0,0 +1,961 @@ +struct character_set; +struct rand_struct; +struct st_list; +struct st_mem_root; +struct st_mysql; +struct st_mysql_bind; +struct st_mysql_data; +struct st_mysql_field; +struct st_mysql_manager; +struct st_mysql_methods; +struct st_mysql_options; +struct st_mysql_parameters; +struct st_mysql_res; +struct st_mysql_rows; +struct st_mysql_stmt; +struct st_mysql_time; +struct st_net; +struct st_typelib; +struct st_udf_args; +struct st_udf_init; +struct st_used_mem; +enum Item_result; +enum enum_cursor_type; +enum enum_field_types; +enum enum_mysql_set_option; +enum enum_mysql_stmt_state; +enum enum_mysql_timestamp_type; +enum enum_server_command; +enum enum_stmt_attr_type; +enum mysql_enum_shutdown_level; +enum mysql_option; +enum mysql_protocol_type; +enum mysql_rpl_type; +enum mysql_status; +# 134 "mysql.h" +typedef struct st_mysql_rows MYSQL_ROWS; +# 24 "my_list.h" +typedef struct st_list LIST; +# 251 "mysql.h" +typedef struct st_mysql MYSQL; +# 653 "mysql.h" +typedef struct st_mysql_bind MYSQL_BIND; +# 93 "mysql.h" +typedef struct st_mysql_field MYSQL_FIELD; +# 117 "mysql.h" +typedef unsigned int MYSQL_FIELD_OFFSET; +# 340 "mysql.h" +typedef struct st_mysql_manager MYSQL_MANAGER; +# 354 "mysql.h" +typedef struct st_mysql_parameters MYSQL_PARAMETERS; +# 309 "mysql.h" +typedef struct st_mysql_res MYSQL_RES; +# 116 "mysql.h" +typedef char * * MYSQL_ROW; +# 140 "mysql.h" +typedef MYSQL_ROWS * MYSQL_ROW_OFFSET; +# 681 "mysql.h" +typedef struct st_mysql_stmt MYSQL_STMT; +# 236 "mysql.h" +typedef struct character_set MY_CHARSET_INFO; +# 184 "mysql_com.h" +typedef struct st_net NET; +# 21 "typelib.h" +typedef struct st_typelib TYPELIB; +# 174 "mysql_com.h" +typedef struct st_vio Vio; +# 57 "mysql.h" +typedef char * gptr; +# 29 "my_list.h" +typedef int (* list_walk_action)(void *, void *); +# 48 "mysql.h" +typedef char my_bool; +# 63 "mysql.h" +typedef int my_socket; +# 125 "mysql.h" +typedef unsigned long long int my_ulonglong; +# 144 "mysql.h" +typedef struct embedded_query_result EMBEDDED_QUERY_RESULT; +# 35 "my_alloc.h" +typedef struct st_mem_root MEM_ROOT; +# 145 "mysql.h" +typedef struct st_mysql_data MYSQL_DATA; +# 750 "mysql.h" +typedef struct st_mysql_methods MYSQL_METHODS; +# 48 "mysql_time.h" +typedef struct st_mysql_time MYSQL_TIME; +# 375 "mysql_com.h" +typedef struct st_udf_args UDF_ARGS; +# 388 "mysql_com.h" +typedef struct st_udf_init UDF_INIT; +# 27 "my_alloc.h" +typedef struct st_used_mem USED_MEM; +# 236 "mysql.h" +struct __attribute__((aligned(__alignof__(unsigned int)), aligned(__alignof__(void *)))) character_set + { + unsigned int number; + unsigned int state; + char const * csname; + char const * name; + char const * comment; + char const * dir; + unsigned int mbminlen; + unsigned int mbmaxlen; + }; +# 361 "mysql_com.h" +struct __attribute__((aligned(__alignof__(unsigned long int)), aligned(__alignof__(double)))) rand_struct + { + unsigned long int seed1; + unsigned long int seed2; + unsigned long int max_value; + double max_value_dbl; + }; +# 24 "my_list.h" +struct __attribute__((aligned(__alignof__(void *)))) st_list + { + struct st_list * prev; + struct st_list * next; + void * data; + }; +# 35 "my_alloc.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned int)))) st_mem_root + { + USED_MEM * free; + USED_MEM * used; + USED_MEM * pre_alloc; + unsigned int min_malloc; + unsigned int block_size; + unsigned int block_num; + unsigned int first_block_usage; + void (* error_handler)(void); + }; +# 251 "mysql.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned long long int)))) st_mysql + { + NET net; + gptr connector_fd; + char * host; + char * user; + char * passwd; + char * unix_socket; + char * server_version; + char * host_info; + char * info; + char * db; + struct charset_info_st * charset; + MYSQL_FIELD * fields; + MEM_ROOT field_alloc; + my_ulonglong affected_rows; + my_ulonglong insert_id; + my_ulonglong extra_info; + unsigned long int thread_id; + unsigned long int packet_length; + unsigned int port; + unsigned long int client_flag; + unsigned long int server_capabilities; + unsigned int protocol_version; + unsigned int field_count; + unsigned int server_status; + unsigned int server_language; + unsigned int warning_count; + struct st_mysql_options options; + enum mysql_status status; + my_bool free_me; + my_bool reconnect; + char scramble[(20 + 1)]; + my_bool rpl_pivot; + struct st_mysql * master; + struct st_mysql * next_slave; + struct st_mysql * last_used_slave; + struct st_mysql * last_used_con; + LIST * stmts; + struct st_mysql_methods const * methods; + void * thd; + my_bool * unbuffered_fetch_owner; + }; +# 653 "mysql.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned long int)))) st_mysql_bind + { + unsigned long int * length; + my_bool * is_null; + void * buffer; + my_bool * error; + enum enum_field_types buffer_type; + unsigned long int buffer_length; + unsigned char * row_ptr; + unsigned long int offset; + unsigned long int length_value; + unsigned int param_number; + unsigned int pack_length; + my_bool error_value; + my_bool is_unsigned; + my_bool long_data_used; + my_bool is_null_value; + void (* store_param_func)(NET * net, struct st_mysql_bind * param); + void (* fetch_result)(struct st_mysql_bind *, MYSQL_FIELD *, unsigned char * * row); + void (* skip_result)(struct st_mysql_bind *, MYSQL_FIELD *, unsigned char * * row); + }; +# 145 "mysql.h" +struct __attribute__((aligned(__alignof__(unsigned long long int)), aligned(__alignof__(void *)))) st_mysql_data + { + my_ulonglong rows; + unsigned int fields; + MYSQL_ROWS * data; + MEM_ROOT alloc; + struct embedded_query_result * embedded_info; + }; +# 93 "mysql.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned long int)))) st_mysql_field + { + char * name; + char * org_name; + char * table; + char * org_table; + char * db; + char * catalog; + char * def; + unsigned long int length; + unsigned long int max_length; + unsigned int name_length; + unsigned int org_name_length; + unsigned int table_length; + unsigned int org_table_length; + unsigned int db_length; + unsigned int catalog_length; + unsigned int def_length; + unsigned int flags; + unsigned int decimals; + unsigned int charsetnr; + enum enum_field_types type; + }; +# 340 "mysql.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned long int)))) st_mysql_manager + { + NET net; + char * host; + char * user; + char * passwd; + unsigned int port; + my_bool free_me; + my_bool eof; + int cmd_status; + int last_errno; + char * net_buf; + char * net_buf_pos; + char * net_data_end; + int net_buf_size; + char last_error[256]; + }; +# 750 "mysql.h" +struct __attribute__((aligned(__alignof__(void *)))) st_mysql_methods + { + my_bool (* read_query_result)(MYSQL * mysql); + my_bool (* advanced_command)(MYSQL * mysql, enum enum_server_command, char const * header, unsigned long int, char const * arg, unsigned long int, my_bool, MYSQL_STMT * stmt); + MYSQL_DATA * (* read_rows)(MYSQL * mysql, MYSQL_FIELD * mysql_fields, unsigned int); + MYSQL_RES * (* use_result)(MYSQL * mysql); + void (* fetch_lengths)(unsigned long int * to, MYSQL_ROW, unsigned int); + void (* flush_use_result)(MYSQL * mysql); + MYSQL_FIELD * (* list_fields)(MYSQL * mysql); + my_bool (* read_prepare_result)(MYSQL * mysql, MYSQL_STMT * stmt); + int (* stmt_execute)(MYSQL_STMT * stmt); + int (* read_binary_rows)(MYSQL_STMT * stmt); + int (* unbuffered_fetch)(MYSQL * mysql, char * * row); + void (* free_embedded_thd)(MYSQL * mysql); + char const * (* read_statistics)(MYSQL * mysql); + my_bool (* next_result)(MYSQL * mysql); + int (* read_change_user_result)(MYSQL * mysql, char * buff, char const * passwd); + int (* read_rows_from_cursor)(MYSQL_STMT * stmt); + }; +# 167 "mysql.h" +struct __attribute__((aligned(__alignof__(unsigned long int)), aligned(__alignof__(void *)))) st_mysql_options + { + unsigned int connect_timeout; + unsigned int read_timeout; + unsigned int write_timeout; + unsigned int port; + unsigned int protocol; + unsigned long int client_flag; + char * host; + char * user; + char * password; + char * unix_socket; + char * db; + struct st_dynamic_array * init_commands; + char * my_cnf_file; + char * my_cnf_group; + char * charset_dir; + char * charset_name; + char * ssl_key; + char * ssl_cert; + char * ssl_ca; + char * ssl_capath; + char * ssl_cipher; + char * shared_memory_base_name; + unsigned long int max_allowed_packet; + my_bool use_ssl; + my_bool compress; + my_bool named_pipe; + my_bool rpl_probe; + my_bool rpl_parse; + my_bool no_master_reads; + my_bool separate_thread; + enum mysql_option methods_to_use; + char * client_ip; + my_bool secure_auth; + my_bool report_data_truncation; + int (* local_infile_init)(void * *, char const *, void *); + int (* local_infile_read)(void *, char *, unsigned int); + void (* local_infile_end)(void); + int (* local_infile_error)(void *, char *, unsigned int); + void * local_infile_userdata; + }; +# 354 "mysql.h" +struct __attribute__((aligned(__alignof__(void *)))) st_mysql_parameters + { + unsigned long int * p_max_allowed_packet; + unsigned long int * p_net_buffer_length; + }; +# 309 "mysql.h" +struct __attribute__((aligned(__alignof__(unsigned long long int)), aligned(__alignof__(void *)))) st_mysql_res + { + my_ulonglong row_count; + MYSQL_FIELD * fields; + MYSQL_DATA * data; + MYSQL_ROWS * data_cursor; + unsigned long int * lengths; + MYSQL * handle; + MEM_ROOT field_alloc; + unsigned int field_count; + unsigned int current_field; + MYSQL_ROW row; + MYSQL_ROW current_row; + my_bool eof; + my_bool unbuffered_fetch_cancelled; + struct st_mysql_methods const * methods; + }; +# 134 "mysql.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned long int)))) st_mysql_rows + { + struct st_mysql_rows * next; + MYSQL_ROW data; + unsigned long int length; + }; +# 681 "mysql.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned long long int)))) st_mysql_stmt + { + MEM_ROOT mem_root; + LIST list; + MYSQL * mysql; + MYSQL_BIND * params; + MYSQL_BIND * bind; + MYSQL_FIELD * fields; + MYSQL_DATA result; + MYSQL_ROWS * data_cursor; + my_ulonglong affected_rows; + my_ulonglong insert_id; + int (* read_row_func)(struct st_mysql_stmt * stmt, unsigned char * * row); + unsigned long int stmt_id; + unsigned long int flags; + unsigned long int prefetch_rows; + unsigned int server_status; + unsigned int last_errno; + unsigned int param_count; + unsigned int field_count; + enum enum_mysql_stmt_state state; + char last_error[512]; + char sqlstate[(5 + 1)]; + my_bool send_types_to_server; + my_bool bind_param_done; + unsigned char bind_result_done; + my_bool unbuffered_fetch_cancelled; + my_bool update_max_length; + }; +# 48 "mysql_time.h" +struct __attribute__((aligned(__alignof__(unsigned long int)))) st_mysql_time + { + unsigned int year; + unsigned int month; + unsigned int day; + unsigned int hour; + unsigned int minute; + unsigned int second; + unsigned long int second_part; + my_bool neg; + enum enum_mysql_timestamp_type time_type; + }; +# 184 "mysql_com.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned long int)))) st_net + { + Vio * vio; + unsigned char * buff; + unsigned char * buff_end; + unsigned char * write_pos; + unsigned char * read_pos; + my_socket fd; + unsigned long int max_packet; + unsigned long int max_packet_size; + unsigned int pkt_nr; + unsigned int compress_pkt_nr; + unsigned int write_timeout; + unsigned int read_timeout; + unsigned int retry_count; + int fcntl; + my_bool compress; + unsigned long int remain_in_buf; + unsigned long int length; + unsigned long int buf_length; + unsigned long int where_b; + unsigned int * return_status; + unsigned char reading_or_writing; + char save_char; + my_bool no_send_ok; + my_bool no_send_eof; + my_bool no_send_error; + char last_error[512]; + char sqlstate[(5 + 1)]; + unsigned int last_errno; + unsigned char error; + gptr query_cache_query; + my_bool report_error; + my_bool return_errno; + }; +# 21 "typelib.h" +struct __attribute__((aligned(__alignof__(unsigned int)), aligned(__alignof__(void *)))) st_typelib + { + unsigned int count; + char const * name; + char const * * type_names; + unsigned int * type_lengths; + }; +# 375 "mysql_com.h" +struct __attribute__((aligned(__alignof__(unsigned int)), aligned(__alignof__(void *)))) st_udf_args + { + unsigned int arg_count; + enum Item_result * arg_type; + char * * args; + unsigned long int * lengths; + char * maybe_null; + char * * attributes; + unsigned long int * attribute_lengths; + }; +# 388 "mysql_com.h" +struct __attribute__((aligned(__alignof__(unsigned long int)), aligned(__alignof__(void *)))) st_udf_init + { + my_bool maybe_null; + unsigned int decimals; + unsigned long int max_length; + char * ptr; + my_bool const_item; + }; +# 27 "my_alloc.h" +struct __attribute__((aligned(__alignof__(void *)), aligned(__alignof__(unsigned int)))) st_used_mem + { + struct st_used_mem * next; + unsigned int left; + unsigned int size; + }; +# 372 "mysql_com.h" +enum Item_result + { + STRING_RESULT = 0, + REAL_RESULT = 1, + INT_RESULT = 2, + ROW_RESULT = 3, + DECIMAL_RESULT = 4, + }; +# 318 "mysql_com.h" +enum enum_cursor_type + { + CURSOR_TYPE_NO_CURSOR = 0, + CURSOR_TYPE_READ_ONLY = 1, + CURSOR_TYPE_FOR_UPDATE = 2, + CURSOR_TYPE_SCROLLABLE = 4, + }; +# 231 "mysql_com.h" +enum enum_field_types + { + MYSQL_TYPE_DECIMAL = 0, + MYSQL_TYPE_TINY = 1, + MYSQL_TYPE_SHORT = 2, + MYSQL_TYPE_LONG = 3, + MYSQL_TYPE_FLOAT = 4, + MYSQL_TYPE_DOUBLE = 5, + MYSQL_TYPE_NULL = 6, + MYSQL_TYPE_TIMESTAMP = 7, + MYSQL_TYPE_LONGLONG = 8, + MYSQL_TYPE_INT24 = 9, + MYSQL_TYPE_DATE = 10, + MYSQL_TYPE_TIME = 11, + MYSQL_TYPE_DATETIME = 12, + MYSQL_TYPE_YEAR = 13, + MYSQL_TYPE_NEWDATE = 14, + MYSQL_TYPE_VARCHAR = 15, + MYSQL_TYPE_BIT = 16, + MYSQL_TYPE_NEWDECIMAL = 246, + MYSQL_TYPE_ENUM = 247, + MYSQL_TYPE_SET = 248, + MYSQL_TYPE_TINY_BLOB = 249, + MYSQL_TYPE_MEDIUM_BLOB = 250, + MYSQL_TYPE_LONG_BLOB = 251, + MYSQL_TYPE_BLOB = 252, + MYSQL_TYPE_VAR_STRING = 253, + MYSQL_TYPE_STRING = 254, + MYSQL_TYPE_GEOMETRY = 255, + }; +# 328 "mysql_com.h" +enum enum_mysql_set_option + { + MYSQL_OPTION_MULTI_STATEMENTS_ON = 0, + MYSQL_OPTION_MULTI_STATEMENTS_OFF = 1, + }; +# 583 "mysql.h" +enum enum_mysql_stmt_state + { + MYSQL_STMT_INIT_DONE = 1, + MYSQL_STMT_PREPARE_DONE = 2, + MYSQL_STMT_EXECUTE_DONE = 3, + MYSQL_STMT_FETCH_DONE = 4, + }; +# 29 "mysql_time.h" +enum enum_mysql_timestamp_type + { + MYSQL_TIMESTAMP_NONE = -(2), + MYSQL_TIMESTAMP_ERROR = -(1), + MYSQL_TIMESTAMP_DATE = 0, + MYSQL_TIMESTAMP_DATETIME = 1, + MYSQL_TIMESTAMP_TIME = 2, + }; +# 52 "mysql_com.h" +enum enum_server_command + { + COM_SLEEP = 0, + COM_QUIT = 1, + COM_INIT_DB = 2, + COM_QUERY = 3, + COM_FIELD_LIST = 4, + COM_CREATE_DB = 5, + COM_DROP_DB = 6, + COM_REFRESH = 7, + COM_SHUTDOWN = 8, + COM_STATISTICS = 9, + COM_PROCESS_INFO = 10, + COM_CONNECT = 11, + COM_PROCESS_KILL = 12, + COM_DEBUG = 13, + COM_PING = 14, + COM_TIME = 15, + COM_DELAYED_INSERT = 16, + COM_CHANGE_USER = 17, + COM_BINLOG_DUMP = 18, + COM_TABLE_DUMP = 19, + COM_CONNECT_OUT = 20, + COM_REGISTER_SLAVE = 21, + COM_STMT_PREPARE = 22, + COM_STMT_EXECUTE = 23, + COM_STMT_SEND_LONG_DATA = 24, + COM_STMT_CLOSE = 25, + COM_STMT_RESET = 26, + COM_SET_OPTION = 27, + COM_STMT_FETCH = 28, + COM_DAEMON = 29, + COM_END = 30, + }; +# 727 "mysql.h" +enum enum_stmt_attr_type + { + STMT_ATTR_UPDATE_MAX_LENGTH = 0, + STMT_ATTR_CURSOR_TYPE = 1, + STMT_ATTR_PREFETCH_ROWS = 2, + }; +# 293 "mysql_com.h" +enum mysql_enum_shutdown_level + { + SHUTDOWN_DEFAULT = 0, + SHUTDOWN_WAIT_CONNECTIONS = (unsigned char)((1 << 0)), + SHUTDOWN_WAIT_TRANSACTIONS = (unsigned char)((1 << 1)), + SHUTDOWN_WAIT_UPDATES = (unsigned char)((1 << 3)), + SHUTDOWN_WAIT_ALL_BUFFERS = ((unsigned char)((1 << 3)) << 1), + SHUTDOWN_WAIT_CRITICAL_BUFFERS = (((unsigned char)((1 << 3)) << 1) + 1), + KILL_CONNECTION = 255, + }; +# 154 "mysql.h" +enum mysql_option + { + MYSQL_OPT_CONNECT_TIMEOUT = 0, + MYSQL_OPT_COMPRESS = 1, + MYSQL_OPT_NAMED_PIPE = 2, + MYSQL_INIT_COMMAND = 3, + MYSQL_READ_DEFAULT_FILE = 4, + MYSQL_READ_DEFAULT_GROUP = 5, + MYSQL_SET_CHARSET_DIR = 6, + MYSQL_SET_CHARSET_NAME = 7, + MYSQL_OPT_LOCAL_INFILE = 8, + MYSQL_OPT_PROTOCOL = 9, + MYSQL_SHARED_MEMORY_BASE_NAME = 10, + MYSQL_OPT_READ_TIMEOUT = 11, + MYSQL_OPT_WRITE_TIMEOUT = 12, + MYSQL_OPT_USE_RESULT = 13, + MYSQL_OPT_USE_REMOTE_CONNECTION = 14, + MYSQL_OPT_USE_EMBEDDED_CONNECTION = 15, + MYSQL_OPT_GUESS_CONNECTION = 16, + MYSQL_SET_CLIENT_IP = 17, + MYSQL_SECURE_AUTH = 18, + MYSQL_REPORT_DATA_TRUNCATION = 19, + MYSQL_OPT_RECONNECT = 20, + MYSQL_OPT_SSL_VERIFY_SERVER_CERT = 21, + }; +# 221 "mysql.h" +enum mysql_protocol_type + { + MYSQL_PROTOCOL_DEFAULT = 0, + MYSQL_PROTOCOL_TCP = 1, + MYSQL_PROTOCOL_SOCKET = 2, + MYSQL_PROTOCOL_PIPE = 3, + MYSQL_PROTOCOL_MEMORY = 4, + }; +# 231 "mysql.h" +enum mysql_rpl_type + { + MYSQL_RPL_MASTER = 0, + MYSQL_RPL_SLAVE = 1, + MYSQL_RPL_ADMIN = 2, + }; +# 216 "mysql.h" +enum mysql_status + { + MYSQL_STATUS_READY = 0, + MYSQL_STATUS_GET_RESULT = 1, + MYSQL_STATUS_USE_RESULT = 2, + }; +# 427 "mysql_com.h" +extern my_bool check_scramble(char const * reply, char const * message, unsigned char const * hash_stage2); +# 420 "mysql_com.h" +extern my_bool check_scramble_323(char const *, char const * message, unsigned long int * salt); +# 415 "mysql_com.h" +extern void create_random_string(char * to, unsigned int, struct rand_struct * rand_st); +# 28 "typelib.h" +extern int find_type(char * x, TYPELIB * typelib, unsigned int); +# 429 "mysql_com.h" +extern void get_salt_from_password(unsigned char * res, char const * password); +# 422 "mysql_com.h" +extern void get_salt_from_password_323(unsigned long int * res, char const * password); +# 435 "mysql_com.h" +extern char * get_tty_password(char const * opt_message); +# 30 "typelib.h" +extern char const * get_type(TYPELIB * typelib, unsigned int); +# 417 "mysql_com.h" +extern void hash_password(unsigned long int * to, char const * password, unsigned int); +# 31 "my_list.h" +extern LIST * list_add(LIST * root, LIST * element); +# 33 "my_list.h" +extern LIST * list_cons(void * data, LIST * root); +# 32 "my_list.h" +extern LIST * list_delete(LIST * root, LIST * element); +# 35 "my_list.h" +extern void list_free(LIST * root, unsigned int); +# 36 "my_list.h" +extern unsigned int list_length(LIST *); +# 34 "my_list.h" +extern LIST * list_reverse(LIST * root); +# 37 "my_list.h" +extern int list_walk(LIST *, list_walk_action, gptr); +# 430 "mysql_com.h" +extern void make_password_from_salt(char * to, unsigned char const * hash_stage2); +# 423 "mysql_com.h" +extern void make_password_from_salt_323(char * to, unsigned long int const * salt); +# 425 "mysql_com.h" +extern void make_scrambled_password(char * to, char const * password); +# 418 "mysql_com.h" +extern void make_scrambled_password_323(char * to, char const * password); +# 29 "typelib.h" +extern void make_type(char * to, unsigned int, TYPELIB * typelib); +# 358 "mysql_com.h" +extern int my_connect(my_socket, struct sockaddr const * name, unsigned int, unsigned int); +# 340 "mysql_com.h" +extern my_bool my_net_init(NET * net, Vio * vio); +# 341 "mysql_com.h" +extern void my_net_local_init(NET * net); +# 351 "mysql_com.h" +extern unsigned long int my_net_read(NET * net); +# 346 "mysql_com.h" +extern my_bool my_net_write(NET * net, char const * packet, unsigned long int); +# 414 "mysql_com.h" +extern double my_rnd(struct rand_struct *); +# 441 "mysql_com.h" +extern void my_thread_end(void); +# 440 "mysql_com.h" +extern my_bool my_thread_init(void); +# 559 "mysql.h" +extern void myodbc_remove_escape(MYSQL * mysql, char * name); +# 501 "mysql.h" +extern int mysql_add_slave(MYSQL * mysql, char const * host, unsigned int, char const * user, char const * passwd); +# 410 "mysql.h" +extern my_ulonglong mysql_affected_rows(MYSQL * mysql); +# 823 "mysql.h" +extern my_bool mysql_autocommit(MYSQL * mysql, my_bool); +# 426 "mysql.h" +extern my_bool mysql_change_user(MYSQL * mysql, char const * user, char const * passwd, char const * db); +# 418 "mysql.h" +extern char const * mysql_character_set_name(MYSQL * mysql); +# 826 "mysql.h" +extern void mysql_close(MYSQL * sock); +# 821 "mysql.h" +extern my_bool mysql_commit(MYSQL * mysql); +# 530 "mysql.h" +extern void mysql_data_seek(MYSQL_RES * result, my_ulonglong); +# 548 "mysql.h" +extern void mysql_debug(char const * debug); +# 487 "mysql.h" +extern void mysql_disable_reads_from_master(MYSQL * mysql); +# 481 "mysql.h" +extern void mysql_disable_rpl_parse(MYSQL * mysql); +# 509 "mysql.h" +extern int mysql_dump_debug_info(MYSQL * mysql); +# 561 "mysql.h" +extern my_bool mysql_embedded(void); +# 486 "mysql.h" +extern void mysql_enable_reads_from_master(MYSQL * mysql); +# 480 "mysql.h" +extern void mysql_enable_rpl_parse(MYSQL * mysql); +# 402 "mysql.h" +extern my_bool mysql_eof(MYSQL_RES * res); +# 412 "mysql.h" +extern unsigned int mysql_errno(MYSQL * mysql); +# 436 "mysql_com.h" +extern char const * mysql_errno_to_sqlstate(unsigned int); +# 413 "mysql.h" +extern char const * mysql_error(MYSQL * mysql); +# 541 "mysql.h" +extern unsigned long int mysql_escape_string(char * to, char const * from, unsigned long int); +# 538 "mysql.h" +extern MYSQL_FIELD * mysql_fetch_field(MYSQL_RES * result); +# 403 "mysql.h" +extern MYSQL_FIELD * mysql_fetch_field_direct(MYSQL_RES * res, unsigned int); +# 405 "mysql.h" +extern MYSQL_FIELD * mysql_fetch_fields(MYSQL_RES * res); +# 537 "mysql.h" +extern unsigned long int * mysql_fetch_lengths(MYSQL_RES * result); +# 536 "mysql.h" +extern MYSQL_ROW mysql_fetch_row(MYSQL_RES * result); +# 409 "mysql.h" +extern unsigned int mysql_field_count(MYSQL * mysql); +# 534 "mysql.h" +extern MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES * result, MYSQL_FIELD_OFFSET); +# 407 "mysql.h" +extern MYSQL_FIELD_OFFSET mysql_field_tell(MYSQL_RES * res); +# 529 "mysql.h" +extern void mysql_free_result(MYSQL_RES * result); +# 454 "mysql.h" +extern void mysql_get_character_set_info(MYSQL * mysql, MY_CHARSET_INFO * charset); +# 519 "mysql.h" +extern char const * mysql_get_client_info(void); +# 520 "mysql.h" +extern unsigned long int mysql_get_client_version(void); +# 521 "mysql.h" +extern char const * mysql_get_host_info(MYSQL * mysql); +# 384 "mysql.h" +extern MYSQL_PARAMETERS * mysql_get_parameters(void); +# 523 "mysql.h" +extern unsigned int mysql_get_proto_info(MYSQL * mysql); +# 518 "mysql.h" +extern char const * mysql_get_server_info(MYSQL * mysql); +# 522 "mysql.h" +extern unsigned long int mysql_get_server_version(MYSQL * mysql); +# 425 "mysql.h" +extern char const * mysql_get_ssl_cipher(MYSQL * mysql); +# 543 "mysql.h" +extern unsigned long int mysql_hex_string(char * to, char const * from, unsigned long int); +# 416 "mysql.h" +extern char const * mysql_info(MYSQL * mysql); +# 421 "mysql.h" +extern MYSQL * mysql_init(MYSQL * mysql); +# 411 "mysql.h" +extern my_ulonglong mysql_insert_id(MYSQL * mysql); +# 512 "mysql.h" +extern int mysql_kill(MYSQL * mysql, unsigned long int); +# 524 "mysql.h" +extern MYSQL_RES * mysql_list_dbs(MYSQL * mysql, char const * wild); +# 539 "mysql.h" +extern MYSQL_RES * mysql_list_fields(MYSQL * mysql, char const * table, char const * wild); +# 526 "mysql.h" +extern MYSQL_RES * mysql_list_processes(MYSQL * mysql); +# 525 "mysql.h" +extern MYSQL_RES * mysql_list_tables(MYSQL * mysql, char const * wild); +# 568 "mysql.h" +extern void mysql_manager_close(MYSQL_MANAGER * con); +# 569 "mysql.h" +extern int mysql_manager_command(MYSQL_MANAGER * con, char const * cmd, int); +# 563 "mysql.h" +extern MYSQL_MANAGER * mysql_manager_connect(MYSQL_MANAGER * con, char const * host, char const * user, char const * passwd, unsigned int); +# 571 "mysql.h" +extern int mysql_manager_fetch_line(MYSQL_MANAGER * con, char * res_buf, int); +# 562 "mysql.h" +extern MYSQL_MANAGER * mysql_manager_init(MYSQL_MANAGER * con); +# 445 "mysql.h" +extern my_bool mysql_master_query(MYSQL * mysql, char const * q, unsigned long int); +# 447 "mysql.h" +extern my_bool mysql_master_send_query(MYSQL * mysql, char const * q, unsigned long int); +# 824 "mysql.h" +extern my_bool mysql_more_results(MYSQL * mysql); +# 825 "mysql.h" +extern int mysql_next_result(MYSQL * mysql); +# 401 "mysql.h" +extern unsigned int mysql_num_fields(MYSQL_RES * res); +# 400 "mysql.h" +extern my_ulonglong mysql_num_rows(MYSQL_RES * res); +# 549 "mysql.h" +extern char * mysql_odbc_escape_string(MYSQL * mysql, char * to, unsigned long int, char const * from, unsigned long int, void * param, char * (* extend_buffer)(void *, char * to, unsigned long int * length)); +# 527 "mysql.h" +extern int mysql_options(MYSQL * mysql, enum mysql_option, char const * arg); +# 516 "mysql.h" +extern int mysql_ping(MYSQL * mysql); +# 75 "mysql.h" +extern unsigned int mysql_port; +# 436 "mysql.h" +extern int mysql_query(MYSQL * mysql, char const * q); +# 574 "mysql.h" +extern my_bool mysql_read_query_result(MYSQL * mysql); +# 489 "mysql.h" +extern my_bool mysql_reads_from_master_enabled(MYSQL * mysql); +# 428 "mysql.h" +extern MYSQL * mysql_real_connect(MYSQL * mysql, char const * host, char const * user, char const * passwd, char const * db, unsigned int, char const * unix_socket, unsigned long int); +# 545 "mysql.h" +extern unsigned long int mysql_real_escape_string(MYSQL * mysql, char * to, char const * from, unsigned long int); +# 439 "mysql.h" +extern int mysql_real_query(MYSQL * mysql, char const * q, unsigned long int); +# 510 "mysql.h" +extern int mysql_refresh(MYSQL * mysql, unsigned int); +# 822 "mysql.h" +extern my_bool mysql_rollback(MYSQL * mysql); +# 532 "mysql.h" +extern MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES * result, MYSQL_ROW_OFFSET); +# 406 "mysql.h" +extern MYSQL_ROW_OFFSET mysql_row_tell(MYSQL_RES * res); +# 483 "mysql.h" +extern int mysql_rpl_parse_enabled(MYSQL * mysql); +# 494 "mysql.h" +extern my_bool mysql_rpl_probe(MYSQL * mysql); +# 491 "mysql.h" +extern enum mysql_rpl_type mysql_rpl_query_type(char const * q, int); +# 435 "mysql.h" +extern int mysql_select_db(MYSQL * mysql, char const * db); +# 437 "mysql.h" +extern int mysql_send_query(MYSQL * mysql, char const * q, unsigned long int); +# 371 "mysql.h" +extern void mysql_server_end(void); +# 370 "mysql.h" +extern int mysql_server_init(int, char * * argv, char * * groups); +# 419 "mysql.h" +extern int mysql_set_character_set(MYSQL * mysql, char const * csname); +# 472 "mysql.h" +extern void mysql_set_local_infile_default(MYSQL * mysql); +# 461 "mysql.h" +extern void mysql_set_local_infile_handler(MYSQL * mysql, int (* local_infile_init)(void * *, char const *, void *), int (* local_infile_read)(void *, char *, unsigned int), void (* local_infile_end)(void), int (* local_infile_error)(void *, char *, unsigned int), void *); +# 497 "mysql.h" +extern int mysql_set_master(MYSQL * mysql, char const * host, unsigned int, char const * user, char const * passwd); +# 513 "mysql.h" +extern int mysql_set_server_option(MYSQL * mysql, enum enum_mysql_set_option); +# 506 "mysql.h" +extern int mysql_shutdown(MYSQL * mysql, enum mysql_enum_shutdown_level); +# 450 "mysql.h" +extern my_bool mysql_slave_query(MYSQL * mysql, char const * q, unsigned long int); +# 452 "mysql.h" +extern my_bool mysql_slave_send_query(MYSQL * mysql, char const * q, unsigned long int); +# 414 "mysql.h" +extern char const * mysql_sqlstate(MYSQL * mysql); +# 422 "mysql.h" +extern my_bool mysql_ssl_set(MYSQL * mysql, char const * key, char const * cert, char const * ca, char const * capath, char const * cipher); +# 517 "mysql.h" +extern char const * mysql_stat(MYSQL * mysql); +# 817 "mysql.h" +extern my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT * stmt); +# 795 "mysql.h" +extern my_bool mysql_stmt_attr_get(MYSQL_STMT * stmt, enum enum_stmt_attr_type, void * attr); +# 792 "mysql.h" +extern my_bool mysql_stmt_attr_set(MYSQL_STMT * stmt, enum enum_stmt_attr_type, void const * attr); +# 798 "mysql.h" +extern my_bool mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); +# 799 "mysql.h" +extern my_bool mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); +# 800 "mysql.h" +extern my_bool mysql_stmt_close(MYSQL_STMT * stmt); +# 815 "mysql.h" +extern void mysql_stmt_data_seek(MYSQL_STMT * stmt, my_ulonglong); +# 809 "mysql.h" +extern unsigned int mysql_stmt_errno(MYSQL_STMT * stmt); +# 810 "mysql.h" +extern char const * mysql_stmt_error(MYSQL_STMT * stmt); +# 785 "mysql.h" +extern int mysql_stmt_execute(MYSQL_STMT * stmt); +# 786 "mysql.h" +extern int mysql_stmt_fetch(MYSQL_STMT * stmt); +# 787 "mysql.h" +extern int mysql_stmt_fetch_column(MYSQL_STMT * stmt, MYSQL_BIND * bind, unsigned int, unsigned long int); +# 819 "mysql.h" +extern unsigned int mysql_stmt_field_count(MYSQL_STMT * stmt); +# 802 "mysql.h" +extern my_bool mysql_stmt_free_result(MYSQL_STMT * stmt); +# 782 "mysql.h" +extern MYSQL_STMT * mysql_stmt_init(MYSQL * mysql); +# 818 "mysql.h" +extern my_ulonglong mysql_stmt_insert_id(MYSQL_STMT * stmt); +# 816 "mysql.h" +extern my_ulonglong mysql_stmt_num_rows(MYSQL_STMT * stmt); +# 791 "mysql.h" +extern unsigned long int mysql_stmt_param_count(MYSQL_STMT * stmt); +# 808 "mysql.h" +extern MYSQL_RES * mysql_stmt_param_metadata(MYSQL_STMT * stmt); +# 783 "mysql.h" +extern int mysql_stmt_prepare(MYSQL_STMT * stmt, char const * query, unsigned long int); +# 801 "mysql.h" +extern my_bool mysql_stmt_reset(MYSQL_STMT * stmt); +# 807 "mysql.h" +extern MYSQL_RES * mysql_stmt_result_metadata(MYSQL_STMT * stmt); +# 812 "mysql.h" +extern MYSQL_ROW_OFFSET mysql_stmt_row_seek(MYSQL_STMT * stmt, MYSQL_ROW_OFFSET); +# 814 "mysql.h" +extern MYSQL_ROW_OFFSET mysql_stmt_row_tell(MYSQL_STMT * stmt); +# 803 "mysql.h" +extern my_bool mysql_stmt_send_long_data(MYSQL_STMT * stmt, unsigned int, char const * data, unsigned long int); +# 811 "mysql.h" +extern char const * mysql_stmt_sqlstate(MYSQL_STMT * stmt); +# 790 "mysql.h" +extern int mysql_stmt_store_result(MYSQL_STMT * stmt); +# 441 "mysql.h" +extern MYSQL_RES * mysql_store_result(MYSQL * mysql); +# 393 "mysql.h" +extern void mysql_thread_end(void); +# 417 "mysql.h" +extern unsigned long int mysql_thread_id(MYSQL * mysql); +# 392 "mysql.h" +extern my_bool mysql_thread_init(void); +# 560 "mysql.h" +extern unsigned int mysql_thread_safe(void); +# 76 "mysql.h" +extern char * mysql_unix_port; +# 442 "mysql.h" +extern MYSQL_RES * mysql_use_result(MYSQL * mysql); +# 415 "mysql.h" +extern unsigned int mysql_warning_count(MYSQL * mysql); +# 343 "mysql_com.h" +extern void net_clear(NET * net); +# 342 "mysql_com.h" +extern void net_end(NET * net); +# 345 "mysql_com.h" +extern my_bool net_flush(NET * net); +# 350 "mysql_com.h" +extern int net_real_write(NET * net, char const * packet, unsigned long int); +# 344 "mysql_com.h" +extern my_bool net_realloc(NET * net, unsigned long int); +# 347 "mysql_com.h" +extern my_bool net_write_command(NET * net, unsigned char, char const * header, unsigned long int, char const * packet, unsigned long int); +# 431 "mysql_com.h" +extern char * octet2hex(char * to, char const * str, unsigned int); +# 412 "mysql_com.h" +extern void randominit(struct rand_struct *, unsigned long int, unsigned long int); +# 426 "mysql_com.h" +extern void scramble(char * to, char const * message, char const * password); +# 419 "mysql_com.h" +extern void scramble_323(char * to, char const * message, char const * password); +# 32 "typelib.h" +extern TYPELIB sql_protocol_typelib; diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am index fe19e08328d..0de37db63e2 100644 --- a/libmysqld/Makefile.am +++ b/libmysqld/Makefile.am @@ -32,7 +32,8 @@ INCLUDES= -I$(top_builddir)/include -I$(top_srcdir)/include \ -I$(top_builddir)/include -I$(top_srcdir)/include \ -I$(top_srcdir)/sql -I$(top_srcdir)/sql/examples \ -I$(top_srcdir)/regex \ - $(openssl_includes) @ZLIB_INCLUDES@ + $(openssl_includes) @ZLIB_INCLUDES@ \ + @condition_dependent_plugin_includes@ noinst_LIBRARIES = libmysqld_int.a pkglib_LIBRARIES = libmysqld.a @@ -77,6 +78,8 @@ libmysqld_int_a_SOURCES= $(libmysqld_sources) $(libmysqlsources) $(sqlsources) libmysqld_a_SOURCES= sqlstoragesources = $(EXTRA_libmysqld_a_SOURCES) +storagesources = @condition_dependent_plugin_modules@ +storagesourceslinks = @condition_dependent_plugin_links@ # automake misses these sql_yacc.cc sql_yacc.h: $(top_srcdir)/sql/sql_yacc.yy @@ -170,12 +173,19 @@ link_sources: @LN_CP_F@ `find $(srcdir)/../sql -name "$$f"` "$$f"; \ done; \ fi; \ + if test -n "$(storagesources)" ; \ + then \ + rm -f $(storagesources); \ + for f in $(storagesourceslinks); do \ + @LN_CP_F@ $(top_srcdir)/$$f . ; \ + done; \ + fi; \ rm -f client_settings.h; \ @LN_CP_F@ $(top_srcdir)/libmysql/client_settings.h client_settings.h clean-local: - rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlstoragesources) | sed "s;\.lo;.c;g"` \ + rm -f `echo $(sqlsources) $(libmysqlsources) $(sqlstoragesources) $(storagesources) | sed "s;\.lo;.c;g"` \ $(top_srcdir)/linked_libmysqld_sources; \ rm -f client_settings.h diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 5ac2c163c4e..b5efd4a82af 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -100,7 +100,6 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command, mysql->affected_rows= ~(my_ulonglong) 0; mysql->field_count= 0; net->last_errno= 0; - mysql->current_stmt= stmt; thd->store_globals(); // Fix if more than one connect /* diff --git a/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test b/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test index 7a097fd1eae..ee6b0ed1426 100644 --- a/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test +++ b/mysql-test/extra/rpl_tests/rpl_flsh_tbls.test @@ -7,6 +7,8 @@ -- source include/master-slave.inc +let $SERVER_VERSION=`select version()`; + create table t1 (a int); insert into t1 values (10); create table t2 (a int); diff --git a/mysql-test/extra/rpl_tests/rpl_truncate_helper.test b/mysql-test/extra/rpl_tests/rpl_truncate_helper.test index 1e485baca36..7f1506c4010 100644 --- a/mysql-test/extra/rpl_tests/rpl_truncate_helper.test +++ b/mysql-test/extra/rpl_tests/rpl_truncate_helper.test @@ -36,6 +36,7 @@ SELECT * FROM t1; --echo **** On Master **** connection master; DROP TABLE t1; +let $SERVER_VERSION=`select version()`; --replace_result $SERVER_VERSION SERVER_VERSION --replace_regex /\/\* xid=[0-9]+ \*\//\/* xid= *\// /table_id: [0-9]+/table_id: #/ SHOW BINLOG EVENTS; diff --git a/mysql-test/include/analyze_failure_sync_with_master.test b/mysql-test/include/analyze_failure_sync_with_master.test new file mode 100644 index 00000000000..e6fd32d2f46 --- /dev/null +++ b/mysql-test/include/analyze_failure_sync_with_master.test @@ -0,0 +1,15 @@ +# Connect to both master and slave +connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,); +connect (slave,127.0.0.1,root,,test,$SLAVE_MYPORT,); + +vertical_results; + +echo == MASTER ===========================================================; +connection master; +show master status; +show slave status; + +echo == SLAVE ===========================================================; +connection slave; +show master status; +show slave status; diff --git a/mysql-test/include/ctype_like_escape.inc b/mysql-test/include/ctype_like_escape.inc index ac97fbaa1a0..d4abc33c178 100644 --- a/mysql-test/include/ctype_like_escape.inc +++ b/mysql-test/include/ctype_like_escape.inc @@ -11,8 +11,8 @@ insert into t1 values('ab_def'); insert into t1 values('abc_ef'); insert into t1 values('abcd_f'); insert into t1 values('abcde_'); --- should return ab_def +# should return ab_def select c1 as c1u from t1 where c1 like 'ab\_def'; --- should return ab_def +# should return ab_def select c1 as c2h from t1 where c1 like 'ab#_def' escape '#'; drop table t1; diff --git a/mysql-test/include/mix1.inc b/mysql-test/include/mix1.inc index 57070d40c5c..7fe369cfb1e 100644 --- a/mysql-test/include/mix1.inc +++ b/mysql-test/include/mix1.inc @@ -31,13 +31,6 @@ eval SET SESSION STORAGE_ENGINE = $engine_type; drop table if exists t1,t2,t1m,t1i,t2m,t2i,t4; --enable_warnings -# -# Bug#17530: Incorrect key truncation on table creation caused server crash. -# -create table t1(f1 varchar(800) binary not null, key(f1)) - character set utf8 collate utf8_general_ci; -insert into t1 values('aaa'); -drop table t1; # BUG#16798: Uninitialized row buffer reads in ref-or-null optimizer # (repeatable only w/innodb). @@ -154,6 +147,31 @@ SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = DROP TABLE t1, t2; # +# Bug #22728 - Handler_rollback value is growing +# + +let $before= `show /*!50002 GLOBAL */ status like 'Handler_rollback'`; +create table t1 (c1 int) engine=innodb; +connect (con1,localhost,root,,); +connect (con2,localhost,root,,); +connection con2; +handler t1 open; +handler t1 read first; +disconnect con2; +connection con1; +let $after= `show /*!50002 GLOBAL */ status like 'Handler_rollback'`; +# Compare the before and after value, it should be equal +--disable_query_log +eval select STRCMP("$before", "$after") as "Before and after comparison"; +--enable_query_log +connection default; +drop table t1; +disconnect con1; + +--echo End of 4.1 tests + + +# # Bug #12882 min/max inconsistent on empty table # @@ -259,6 +277,36 @@ select distinct a1 from t4 where pk_col not in (1,2,3,4); drop table t1,t4; + +# +# BUG#18819: DELETE IGNORE hangs on foreign key parent delete +# +# The bug itself does not relate to InnoDB, but we have to use foreign +# keys to reproduce it. +# +--disable_warnings +DROP TABLE IF EXISTS t2, t1; +--enable_warnings + +CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE= InnoDB; +CREATE TABLE t2 ( + i INT NOT NULL, + FOREIGN KEY (i) REFERENCES t1 (i) ON DELETE NO ACTION +) ENGINE= InnoDB; + +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (1); + +DELETE IGNORE FROM t1 WHERE i = 1; + +SELECT * FROM t1, t2; + +DROP TABLE t2, t1; + + +--echo End of 4.1 tests. + + # # Bug #6142: a problem with the empty innodb table # (was part of group_min_max.test) @@ -395,6 +443,28 @@ create table t1(f1 varchar(800) binary not null, key(f1)) insert into t1 values('aaa'); drop table t1; + +# +# Bug#22781: SQL_BIG_RESULT fails to influence sort plan +# +CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB; + +INSERT INTO t1 VALUES ( 1 , 1 , 1); +INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1; + +EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b; +EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b; +DROP TABLE t1; + +--echo End of 5.0 tests + + # Fix for BUG#19243 "wrong LAST_INSERT_ID() after ON DUPLICATE KEY # UPDATE": if the row is updated, it's like a regular UPDATE: # LAST_INSERT_ID() is not affected. @@ -446,3 +516,5 @@ select last_insert_id(); select * from t2; drop table t2; + +--echo End of 5.1 tests diff --git a/mysql-test/include/mysqltest_while.inc b/mysql-test/include/mysqltest_while.inc deleted file mode 100644 index 90b05ee2695..00000000000 --- a/mysql-test/include/mysqltest_while.inc +++ /dev/null @@ -1,137 +0,0 @@ -let $1 = 10; -while ($1) -{ -while ($1) -{ -while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - while ($1) -{ - echo $1; - dec $1; -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} -} diff --git a/mysql-test/include/sourced.inc b/mysql-test/include/sourced.inc deleted file mode 100644 index be1a270641a..00000000000 --- a/mysql-test/include/sourced.inc +++ /dev/null @@ -1 +0,0 @@ -echo here is the sourced script; diff --git a/mysql-test/include/sourced1.inc b/mysql-test/include/sourced1.inc deleted file mode 100644 index 920561e5de2..00000000000 --- a/mysql-test/include/sourced1.inc +++ /dev/null @@ -1 +0,0 @@ ---source include/sourced.inc diff --git a/mysql-test/include/sp-vars.inc b/mysql-test/include/sp-vars.inc index 3e02c9d1709..4bac883ee0e 100644 --- a/mysql-test/include/sp-vars.inc +++ b/mysql-test/include/sp-vars.inc @@ -119,4 +119,13 @@ END| --------------------------------------------------------------------------- +CREATE FUNCTION sp_vars_div_zero() RETURNS INTEGER +BEGIN + DECLARE div_zero INTEGER; + SELECT 1/0 INTO div_zero; + RETURN div_zero; +END| + +--------------------------------------------------------------------------- + delimiter ;| diff --git a/mysql-test/include/wait_for_query_to_suceed.inc b/mysql-test/include/wait_for_query_to_suceed.inc new file mode 100644 index 00000000000..6ac1144620e --- /dev/null +++ b/mysql-test/include/wait_for_query_to_suceed.inc @@ -0,0 +1,25 @@ +# +# Run a query over and over until it suceeds ot timeout occurs +# + + +let $counter= 100; + +disable_abort_on_error; +disable_query_log; +disable_result_log; +eval $query; +while ($mysql_errno) +{ + eval $query; + sleep 0.1; + dec $counter; + + if (!$counter) + { + die("Waited too long for query to suceed"); + } +} +enable_abort_on_error; +enable_query_log; +enable_result_log; diff --git a/mysql-test/lib/mtr_cases.pl b/mysql-test/lib/mtr_cases.pl index bb92730444c..d270d72d526 100644 --- a/mysql-test/lib/mtr_cases.pl +++ b/mysql-test/lib/mtr_cases.pl @@ -59,7 +59,9 @@ sub collect_test_cases ($) { if ( @::opt_cases ) { - foreach my $tname ( @::opt_cases ) { # Run in specified order, no sort + foreach my $tname ( @::opt_cases ) + { + # Run in specified order, no sort my $elem= undef; my $component_id= undef; @@ -85,7 +87,7 @@ sub collect_test_cases ($) { # If target component is known, check that the specified test case # exists. - # + # # Otherwise, try to guess the target component. if ( $component_id ) @@ -127,7 +129,8 @@ sub collect_test_cases ($) { } else { - foreach my $elem ( sort readdir(TESTDIR) ) { + foreach my $elem ( sort readdir(TESTDIR) ) + { my $component_id= undef; my $tname= undef; @@ -143,8 +146,10 @@ sub collect_test_cases ($) { { next; } - - next if $::opt_do_test and ! defined mtr_match_prefix($elem,$::opt_do_test); + + # Skip tests that does not match the --do-test= filter + next if $::opt_do_test and + ! defined mtr_match_prefix($elem,$::opt_do_test); collect_one_test_case($testdir,$resdir,$tname,$elem,$cases,\%disabled, $component_id); @@ -152,43 +157,79 @@ sub collect_test_cases ($) { closedir TESTDIR; } - # To speed things up, we sort first in if the test require a restart - # or not, second in alphanumeric order. - + # Reorder the test cases in an order that will make them faster to run if ( $::opt_reorder ) { my %sort_criteria; - my $tinfo; # Make a mapping of test name to a string that represents how that test # should be sorted among the other tests. Put the most important criterion # first, then a sub-criterion, then sub-sub-criterion, et c. - foreach $tinfo (@$cases) + foreach my $tinfo (@$cases) { - my @this_criteria = (); - - # Append the criteria for sorting, in order of importance. - push(@this_criteria, join("!", sort @{$tinfo->{'master_opt'}}) . "~"); # Ending with "~" makes empty sort later than filled - push(@this_criteria, "ndb=" . ($tinfo->{'ndb_test'} ? "1" : "0")); - push(@this_criteria, "restart=" . ($tinfo->{'master_restart'} ? "1" : "0")); - push(@this_criteria, "big_test=" . ($tinfo->{'big_test'} ? "1" : "0")); - push(@this_criteria, join("|", sort keys %{$tinfo})); # Group similar things together. The values may differ substantially. FIXME? - push(@this_criteria, $tinfo->{'name'}); # Finally, order by the name - - $sort_criteria{$tinfo->{"name"}} = join(" ", @this_criteria); + my @criteria = (); + + # Look for tests that muct be in run in a defined order + # that is defined by test having the same name except for + # the ending digit + + # Put variables into hash + my $test_name= $tinfo->{'name'}; + my $depend_on_test_name; + if ( $test_name =~ /^([\D]+)([0-9]{1})$/ ) + { + my $base_name= $1; + my $idx= $2; + mtr_verbose("$test_name => $base_name idx=$idx"); + if ( $idx > 1 ) + { + $idx-= 1; + $base_name= "$base_name$idx"; + mtr_verbose("New basename $base_name"); + } + + foreach my $tinfo2 (@$cases) + { + if ( $tinfo2->{'name'} eq $base_name ) + { + mtr_verbose("found dependent test $tinfo2->{'name'}"); + $depend_on_test_name=$base_name; + } + } + } + + if ( defined $depend_on_test_name ) + { + mtr_verbose("Giving $test_name same critera as $depend_on_test_name"); + $sort_criteria{$test_name} = $sort_criteria{$depend_on_test_name}; + } + else + { + # + # Append the criteria for sorting, in order of importance. + # + push(@criteria, "ndb=" . ($tinfo->{'ndb_test'} ? "1" : "0")); + # Group test with equal options together. + # Ending with "~" makes empty sort later than filled + push(@criteria, join("!", sort @{$tinfo->{'master_opt'}}) . "~"); + + $sort_criteria{$test_name} = join(" ", @criteria); + } } - @$cases = sort { $sort_criteria{$a->{"name"}} cmp $sort_criteria{$b->{"name"}}; } @$cases; + @$cases = sort { + $sort_criteria{$a->{'name'}} . $a->{'name'} cmp + $sort_criteria{$b->{'name'}} . $b->{'name'}; } @$cases; -### For debugging the sort-order -# foreach $tinfo (@$cases) -# { -# print $sort_criteria{$tinfo->{"name"}}; -# print " -> \t"; -# print $tinfo->{"name"}; -# print "\n"; -# } + if ( $::opt_script_debug ) + { + # For debugging the sort-order + foreach my $tinfo (@$cases) + { + print("$sort_criteria{$tinfo->{'name'}} -> \t$tinfo->{'name'}\n"); + } + } } return $cases; @@ -222,9 +263,6 @@ sub collect_one_test_case($$$$$$$) { return; } - # ---------------------------------------------------------------------- - # Skip some tests but include in list, just mark them to skip - # ---------------------------------------------------------------------- my $tinfo= {}; $tinfo->{'name'}= $tname; @@ -232,6 +270,10 @@ sub collect_one_test_case($$$$$$$) { $tinfo->{'component_id'} = $component_id; push(@$cases, $tinfo); + # ---------------------------------------------------------------------- + # Skip some tests but include in list, just mark them to skip + # ---------------------------------------------------------------------- + if ( $::opt_skip_test and defined mtr_match_prefix($tname,$::opt_skip_test) ) { $tinfo->{'skip'}= 1; @@ -245,6 +287,7 @@ sub collect_one_test_case($$$$$$$) { $tinfo->{'path'}= $path; $tinfo->{'timezone'}= "GMT-3"; # for UNIX_TIMESTAMP tests to work + $tinfo->{'slave_num'}= 0; # Default, no slave if ( defined mtr_match_prefix($tname,"rpl") ) { if ( $::opt_skip_rpl ) @@ -254,7 +297,8 @@ sub collect_one_test_case($$$$$$$) { return; } - $tinfo->{'slave_num'}= 1; # Default, use one slave + + $tinfo->{'slave_num'}= 1; # Default for rpl* tests, use one slave if ( $tname eq 'rpl_failsafe' or $tname eq 'rpl_chain_temp_table' ) { @@ -268,40 +312,6 @@ sub collect_one_test_case($$$$$$$) { $tinfo->{'slave_num'}= 1; } - if ( $::opt_with_ndbcluster or defined mtr_match_substring($tname,"ndb") ) - { - # This is an ndb test or all tests should be run with ndb cluster started - $tinfo->{'ndb_test'}= 1; - if ( $::opt_skip_ndbcluster ) - { - # All ndb test's should be skipped - $tinfo->{'skip'}= 1; - $tinfo->{'comment'}= "No ndbcluster test(--skip-ndbcluster)"; - return; - } - if ( ! $::opt_ndbcluster_supported ) - { - # Ndb is not supported, skip them - $tinfo->{'skip'}= 1; - $tinfo->{'comment'}= "No ndbcluster support"; - return; - } - } - else - { - # This is not a ndb test - $tinfo->{'ndb_test'}= 0; - if ( $::opt_with_ndbcluster_only ) - { - # Only the ndb test should be run, all other should be skipped - $tinfo->{'skip'}= 1; - $tinfo->{'comment'}= "Only ndbcluster tests(--with-ndbcluster-only)"; - return; - } - } - - # FIXME what about embedded_server + ndbcluster, skip ?! - my $master_opt_file= "$testdir/$tname-master.opt"; my $slave_opt_file= "$testdir/$tname-slave.opt"; my $slave_mi_file= "$testdir/$tname.slave-mi"; @@ -316,57 +326,59 @@ sub collect_one_test_case($$$$$$$) { if ( -f $master_opt_file ) { - $tinfo->{'master_restart'}= 1; # We think so for now - MASTER_OPT: - { - my $master_opt= mtr_get_opts_from_file($master_opt_file); + my $master_opt= mtr_get_opts_from_file($master_opt_file); - foreach my $opt ( @$master_opt ) - { - my $value; + foreach my $opt ( @$master_opt ) + { + my $value; - # This is a dirty hack from old mysql-test-run, we use the opt - # file to flag other things as well, it is not a opt list at - # all + # The opt file is used both to send special options to the mysqld + # as well as pass special test case specific options to this + # script - $value= mtr_match_prefix($opt, "--timezone="); - if ( defined $value ) - { - $tinfo->{'timezone'}= $value; - last MASTER_OPT; - } + $value= mtr_match_prefix($opt, "--timezone="); + if ( defined $value ) + { + $tinfo->{'timezone'}= $value; + next; + } - $value= mtr_match_prefix($opt, "--result-file="); - if ( defined $value ) - { - $tinfo->{'result_file'}= "r/$value.result"; - if ( $::opt_result_ext and $::opt_record or - -f "$tinfo->{'result_file'}$::opt_result_ext") - { - $tinfo->{'result_file'}.= $::opt_result_ext; - } - $tinfo->{'master_restart'}= 0; - last MASTER_OPT; - } + $value= mtr_match_prefix($opt, "--result-file="); + if ( defined $value ) + { + # Specifies the file mysqltest should compare + # output against + $tinfo->{'result_file'}= "r/$value.result"; + next; + } - # If we set default time zone, remove the one we have - $value= mtr_match_prefix($opt, "--default-time-zone="); - if ( defined $value ) - { - $tinfo->{'master_opt'}= []; - } + # If we set default time zone, remove the one we have + $value= mtr_match_prefix($opt, "--default-time-zone="); + if ( defined $value ) + { + # Set timezone for this test case to something different + $tinfo->{'timezone'}= "GMT-8"; + # Fallthrough, add the --default-time-zone option + } + # The --restart option forces a restart even if no special + # option is set. If the options are the same as next testcase + # there is no need to restart after the testcase + # has completed + if ( $opt eq "--force-restart" ) + { + $tinfo->{'force_restart'}= 1; + next; } - # Ok, this was a real option list, add it - push(@{$tinfo->{'master_opt'}}, @$master_opt); + # Ok, this was a real option, add it + push(@{$tinfo->{'master_opt'}}, $opt); } } if ( -f $slave_opt_file ) { - $tinfo->{'slave_restart'}= 1; my $slave_opt= mtr_get_opts_from_file($slave_opt_file); foreach my $opt ( @$slave_opt ) @@ -381,7 +393,6 @@ sub collect_one_test_case($$$$$$$) { if ( -f $slave_mi_file ) { $tinfo->{'slave_mi'}= mtr_get_opts_from_file($slave_mi_file); - $tinfo->{'slave_restart'}= 1; } if ( -f $master_sh ) @@ -395,7 +406,6 @@ sub collect_one_test_case($$$$$$$) { else { $tinfo->{'master_sh'}= $master_sh; - $tinfo->{'master_restart'}= 1; } } @@ -410,7 +420,6 @@ sub collect_one_test_case($$$$$$$) { else { $tinfo->{'slave_sh'}= $slave_sh; - $tinfo->{'slave_restart'}= 1; } } @@ -514,18 +523,50 @@ sub collect_one_test_case($$$$$$$) { $tinfo->{'comment'}= "Test need debug binaries"; return; } - } - # We can't restart a running server that may be in use + if ( $tinfo->{'ndb_test'} ) + { + # This is a NDB test + if ( ! $::glob_ndbcluster_supported ) + { + # Ndb is not supported, skip it + $tinfo->{'skip'}= 1; + $tinfo->{'comment'}= "No ndbcluster support"; + return; + } + elsif ( $::opt_skip_ndbcluster ) + { + # All ndb test's should be skipped + $tinfo->{'skip'}= 1; + $tinfo->{'comment'}= "No ndbcluster tests(--skip-ndbcluster)"; + return; + } + } + else + { + # This is not a ndb test + if ( $::opt_with_ndbcluster_only ) + { + # Only the ndb test should be run, all other should be skipped + $tinfo->{'skip'}= 1; + $tinfo->{'comment'}= "Only ndbcluster tests(--with-ndbcluster-only)"; + return; + } + } + + if ( $tinfo->{'innodb_test'} ) + { + # This is a test that need inndob + if ( $::mysqld_variables{'innodb'} eq "FALSE" ) + { + # innodb is not supported, skip it + $tinfo->{'skip'}= 1; + $tinfo->{'comment'}= "No innodb support"; + return; + } + } - if ( $::glob_use_running_server and - ( $tinfo->{'master_restart'} or $tinfo->{'slave_restart'} ) ) - { - $tinfo->{'skip'}= 1; - $tinfo->{'comment'}= "Can't restart a running server"; - return; } - } @@ -536,8 +577,10 @@ our @tags= ["include/have_innodb.inc", "innodb_test", 1], ["include/have_binlog_format_row.inc", "binlog_format", "row"], ["include/have_binlog_format_statement.inc", "binlog_format", "stmt"], + ["include/have_binlog_format_mixed.inc", "binlog_format", "mixed"], ["include/big_test.inc", "big_test", 1], ["include/have_debug.inc", "need_debug", 1], + ["include/have_ndb.inc", "ndb_test", 1], ["include/have_ndb_extra.inc", "ndb_extra", 1], ["require_manager", "require_manager", 1], ); @@ -550,8 +593,6 @@ sub mtr_options_from_test_file($$) { while ( my $line= <$F> ) { - next if ( $line !~ /^--/ ); - # Match this line against tag in "tags" array foreach my $tag (@tags) { @@ -563,14 +604,21 @@ sub mtr_options_from_test_file($$) { } # If test sources another file, open it as well - if ( $line =~ /^\-\-([[:space:]]*)source(.*)$/ ) + if ( $line =~ /^\-\-([[:space:]]*)source(.*)$/ or + $line =~ /^([[:space:]]*)source(.*);$/ ) { my $value= $2; $value =~ s/^\s+//; # Remove leading space $value =~ s/[[:space:]]+$//; # Remove ending space my $sourced_file= "$::glob_mysql_test_dir/$value"; - mtr_options_from_test_file($tinfo, $sourced_file); + if ( -f $sourced_file ) + { + # Only source the file if it exists, we may get + # false positives in the regexes above if someone + # writes "source nnnn;" in a test case(such as mysqltest.test) + mtr_options_from_test_file($tinfo, $sourced_file); + } } } diff --git a/mysql-test/lib/mtr_gcov.pl b/mysql-test/lib/mtr_gcov.pl index 07aac1d2017..71d3d6a2a43 100644 --- a/mysql-test/lib/mtr_gcov.pl +++ b/mysql-test/lib/mtr_gcov.pl @@ -23,12 +23,28 @@ sub gcov_prepare () { -or -name \*.da | xargs rm`; } +# Used by gcov +our @mysqld_src_dirs= + ( + "strings", + "mysys", + "include", + "extra", + "regex", + "isam", + "merge", + "myisam", + "myisammrg", + "heap", + "sql", + ); + sub gcov_collect () { print "Collecting source coverage info...\n"; -f $::opt_gcov_msg and unlink($::opt_gcov_msg); -f $::opt_gcov_err and unlink($::opt_gcov_err); - foreach my $d ( @::mysqld_src_dirs ) + foreach my $d ( @mysqld_src_dirs ) { chdir("$::glob_basedir/$d"); foreach my $f ( (glob("*.h"), glob("*.cc"), glob("*.c")) ) diff --git a/mysql-test/lib/mtr_io.pl b/mysql-test/lib/mtr_io.pl index e8dcb0262c9..984d834486c 100644 --- a/mysql-test/lib/mtr_io.pl +++ b/mysql-test/lib/mtr_io.pl @@ -12,6 +12,7 @@ sub mtr_fromfile ($); sub mtr_tofile ($@); sub mtr_tonewfile($@); sub mtr_lastlinefromfile($); +sub mtr_appendfile_to_file ($$); ############################################################################## # @@ -36,18 +37,16 @@ sub mtr_get_pid_from_file ($) { open(FILE, '<', $pid_file_path) or mtr_error("can't open file \"$pid_file_path\": $!"); + # Read pid number from file my $pid= <FILE>; - - chomp($pid) if defined $pid; - close FILE; - return $pid if defined $pid && $pid ne ''; + return $pid if $pid=~ /^(\d+)/; - mtr_debug("Pid file '$pid_file_path' is empty. " . - "Sleeping $timeout second(s)..."); + mtr_debug("Pid file '$pid_file_path' does not yet contain pid number.\n" . + "Sleeping $timeout second(s) more..."); - sleep(1); + sleep($timeout); } mtr_error("Pid file '$pid_file_path' is corrupted. " . @@ -170,4 +169,17 @@ sub mtr_tonewfile ($@) { close FILE; } +sub mtr_appendfile_to_file ($$) { + my $from_file= shift; + my $to_file= shift; + + open(TOFILE,">>",$to_file) or mtr_error("can't open file \"$to_file\": $!"); + open(FROMFILE,"<",$from_file) + or mtr_error("can't open file \"$from_file\": $!"); + print TOFILE while (<FROMFILE>); + close FROMFILE; + close TOFILE; +} + + 1; diff --git a/mysql-test/lib/mtr_misc.pl b/mysql-test/lib/mtr_misc.pl index dd9d24ebc8e..846ca25b725 100644 --- a/mysql-test/lib/mtr_misc.pl +++ b/mysql-test/lib/mtr_misc.pl @@ -14,6 +14,7 @@ sub mtr_path_exists(@); sub mtr_script_exists(@); sub mtr_file_exists(@); sub mtr_exe_exists(@); +sub mtr_exe_maybe_exists(@); sub mtr_copy_dir($$); sub mtr_same_opts($$); sub mtr_cmp_opts($$); @@ -65,6 +66,10 @@ sub mtr_add_arg ($$@) { ############################################################################## +# +# NOTE! More specific paths should be given before less specific. +# For example /client/debug should be listed before /client +# sub mtr_path_exists (@) { foreach my $path ( @_ ) { @@ -80,6 +85,11 @@ sub mtr_path_exists (@) { } } + +# +# NOTE! More specific paths should be given before less specific. +# For example /client/debug should be listed before /client +# sub mtr_script_exists (@) { foreach my $path ( @_ ) { @@ -102,6 +112,11 @@ sub mtr_script_exists (@) { } } + +# +# NOTE! More specific paths should be given before less specific. +# For example /client/debug should be listed before /client +# sub mtr_file_exists (@) { foreach my $path ( @_ ) { @@ -110,8 +125,14 @@ sub mtr_file_exists (@) { return ""; } -sub mtr_exe_exists (@) { + +# +# NOTE! More specific paths should be given before less specific. +# For example /client/debug should be listed before /client +# +sub mtr_exe_maybe_exists (@) { my @path= @_; + map {$_.= ".exe"} @path if $::glob_win32; foreach my $path ( @path ) { @@ -124,6 +145,21 @@ sub mtr_exe_exists (@) { return $path if -x $path; } } + return ""; +} + + +# +# NOTE! More specific paths should be given before less specific. +# For example /client/debug should be listed before /client +# +sub mtr_exe_exists (@) { + my @path= @_; + if (my $path= mtr_exe_maybe_exists(@path)) + { + return $path; + } + # Could not find exe, show error if ( @path == 1 ) { mtr_error("Could not find $path[0]"); @@ -139,7 +175,7 @@ sub mtr_copy_dir($$) { my $from_dir= shift; my $to_dir= shift; -# mtr_verbose("Copying from $from_dir to $to_dir"); + # mtr_verbose("Copying from $from_dir to $to_dir"); mkpath("$to_dir"); opendir(DIR, "$from_dir") diff --git a/mysql-test/lib/mtr_process.pl b/mysql-test/lib/mtr_process.pl index 868b6d4f1ec..9d0c1f601ba 100644 --- a/mysql-test/lib/mtr_process.pl +++ b/mysql-test/lib/mtr_process.pl @@ -4,12 +4,10 @@ # and is part of the translation of the Bourne shell script with the # same name. -#use Carp qw(cluck); use Socket; use Errno; use strict; -#use POSIX ":sys_wait_h"; use POSIX 'WNOHANG'; sub mtr_run ($$$$$$;$); @@ -93,8 +91,6 @@ sub spawn_impl ($$$$$$$$) { my $pid_file= shift; # FIXME my $spawn_opts= shift; - mtr_error("Can't spawn with empty \"path\"") unless defined $path; - if ( $::opt_script_debug ) { print STDERR "\n"; @@ -118,6 +114,9 @@ sub spawn_impl ($$$$$$$$) { print STDERR "#### ", "-" x 78, "\n"; } + mtr_error("Can't spawn with empty \"path\"") unless defined $path; + + FORK: { my $pid= fork(); @@ -339,19 +338,6 @@ sub mtr_kill_leftovers () { mtr_report("Killing Possible Leftover Processes"); mtr_debug("mtr_kill_leftovers(): started."); - mkpath("$::opt_vardir/log"); # Needed for mysqladmin log - - # Stop or kill Instance Manager and all its children. If we failed to do - # that, we can only abort -- there is nothing left to do. - - mtr_error("Failed to stop Instance Manager.") - unless mtr_im_stop($::instance_manager); - - # Start shutdown of masters and slaves. Don't touch IM-managed mysqld - # instances -- they should be stopped by mtr_im_stop(). - - mtr_debug("Shutting down mysqld-instances..."); - my @kill_pids; my %admin_pids; @@ -377,40 +363,41 @@ sub mtr_kill_leftovers () { $srv->{'pid'}= 0; # Assume we are done with it } - # Start shutdown of clusters. - - mtr_debug("Shutting down cluster..."); - - foreach my $cluster (@{$::clusters}) + if ( ! $::opt_skip_ndbcluster ) { - mtr_debug(" - cluster " . - "(pid: $cluster->{pid}; " . - "pid file: '$cluster->{path_pid})"); - - my $pid= mtr_ndbmgm_start($cluster, "shutdown"); - - # Save the pid of the ndb_mgm process - $admin_pids{$pid}= 1; - - push(@kill_pids,{ - pid => $cluster->{'pid'}, - pidfile => $cluster->{'path_pid'} - }); + # Start shutdown of clusters. + mtr_debug("Shutting down cluster..."); - $cluster->{'pid'}= 0; # Assume we are done with it + foreach my $cluster (@{$::clusters}) + { + mtr_debug(" - cluster " . + "(pid: $cluster->{pid}; " . + "pid file: '$cluster->{path_pid})"); + my $pid= mtr_ndbmgm_start($cluster, "shutdown"); - foreach my $ndbd (@{$cluster->{'ndbds'}}) - { - mtr_debug(" - ndbd " . - "(pid: $ndbd->{pid}; " . - "pid file: '$ndbd->{path_pid})"); + # Save the pid of the ndb_mgm process + $admin_pids{$pid}= 1; push(@kill_pids,{ - pid => $ndbd->{'pid'}, - pidfile => $ndbd->{'path_pid'}, + pid => $cluster->{'pid'}, + pidfile => $cluster->{'path_pid'} }); - $ndbd->{'pid'}= 0; # Assume we are done with it + + $cluster->{'pid'}= 0; # Assume we are done with it + + foreach my $ndbd (@{$cluster->{'ndbds'}}) + { + mtr_debug(" - ndbd " . + "(pid: $ndbd->{pid}; " . + "pid file: '$ndbd->{path_pid})"); + + push(@kill_pids,{ + pid => $ndbd->{'pid'}, + pidfile => $ndbd->{'path_pid'}, + }); + $ndbd->{'pid'}= 0; # Assume we are done with it + } } } @@ -451,25 +438,35 @@ sub mtr_kill_leftovers () { while ( my $elem= readdir(RUNDIR) ) { - my $pidfile= "$rundir/$elem"; - - if ( -f $pidfile ) + # Only read pid from files that end with .pid + if ( $elem =~ /.*[.]pid$/) { - mtr_debug("Processing PID file: '$pidfile'..."); + my $pidfile= "$rundir/$elem"; - my $pid= mtr_get_pid_from_file($pidfile); + if ( -f $pidfile ) + { + mtr_debug("Processing PID file: '$pidfile'..."); - mtr_debug("Got pid: $pid from file '$pidfile'"); + my $pid= mtr_get_pid_from_file($pidfile); - if ( $::glob_cygwin_perl or kill(0, $pid) ) - { - mtr_debug("There is process with pid $pid -- scheduling for kill."); - push(@pids, $pid); # We know (cygwin guess) it exists - } - else - { - mtr_debug("There is no process with pid $pid -- skipping."); - } + mtr_debug("Got pid: $pid from file '$pidfile'"); + + if ( $::glob_cygwin_perl or kill(0, $pid) ) + { + mtr_debug("There is process with pid $pid -- scheduling for kill."); + push(@pids, $pid); # We know (cygwin guess) it exists + } + else + { + mtr_debug("There is no process with pid $pid -- skipping."); + } + } + } + else + { + mtr_warning("Found non pid file $elem in $rundir") + if -f "$rundir/$elem"; + next; } } closedir(RUNDIR); @@ -1100,7 +1097,6 @@ sub mtr_kill_processes ($) { sub mtr_exit ($) { my $code= shift; -# cluck("Called mtr_exit()"); mtr_timer_stop_all($::glob_timers); local $SIG{HUP} = 'IGNORE'; # ToDo: Signalling -$$ will only work if we are the process group diff --git a/mysql-test/lib/mtr_report.pl b/mysql-test/lib/mtr_report.pl index 6e3796133f2..8d7de9d1a4b 100644 --- a/mysql-test/lib/mtr_report.pl +++ b/mysql-test/lib/mtr_report.pl @@ -53,13 +53,6 @@ sub mtr_show_failed_diff ($) { { $result_file= $eval_file; } - elsif ( $::opt_result_ext and - ( $::opt_record or -f "$result_file$::opt_result_ext" )) - { - # If we have an special externsion for result files we use it if we are - # recording or a result file with that extension exists. - $result_file= "$result_file$::opt_result_ext"; - } my $diffopts= $::opt_udiff ? "-u" : "-c"; @@ -137,13 +130,9 @@ sub mtr_report_test_failed ($) { my $tinfo= shift; $tinfo->{'result'}= 'MTR_RES_FAILED'; - if ( $tinfo->{'timeout'} ) + if ( defined $tinfo->{'timeout'} ) { print "[ fail ] timeout\n"; - } - elsif ( $tinfo->{'ndb_test'} and $::cluster->[0]->{'installed_ok'} eq "NO") - { - print "[ fail ] ndbcluster start failure\n"; return; } else @@ -151,9 +140,11 @@ sub mtr_report_test_failed ($) { print "[ fail ]\n"; } - # FIXME Instead of this test, and meaningless error message in 'else' - # we should write out into $::path_timefile when the error occurs. - if ( -f $::path_timefile ) + if ( $tinfo->{'comment'} ) + { + print "\nERROR: $tinfo->{'comment'}\n"; + } + elsif ( -f $::path_timefile ) { print "\nErrors are (from $::path_timefile) :\n"; print mtr_fromfile($::path_timefile); # FIXME print_file() instead @@ -177,7 +168,7 @@ sub mtr_report_stats ($) { my $tot_failed= 0; my $tot_tests= 0; my $tot_restarts= 0; - my $found_problems= 0; # Some warnings are errors... + my $found_problems= 0; # Some warnings in the logfiles are errors... foreach my $tinfo (@$tests) { @@ -212,8 +203,9 @@ sub mtr_report_stats ($) { else { my $ratio= $tot_passed * 100 / $tot_tests; - printf "Failed $tot_failed/$tot_tests tests, " . - "%.2f\% were successful.\n\n", $ratio; + print "Failed $tot_failed/$tot_tests tests, "; + printf("%.2f", $ratio); + print "\% were successful.\n\n"; print "The log files in var/log may give you some hint\n", "of what went wrong.\n", @@ -288,6 +280,7 @@ sub mtr_report_stats ($) { print "\n"; + # Print a list of testcases that failed if ( $tot_failed != 0 ) { my $test_mode= join(" ", @::glob_test_mode) || "default"; @@ -301,7 +294,30 @@ sub mtr_report_stats ($) { } } print "\n"; + + } + + # Print a list of check_testcases that failed(if any) + if ( $::opt_check_testcases ) + { + my @check_testcases= (); + + foreach my $tinfo (@$tests) + { + if ( defined $tinfo->{'check_testcase_failed'} ) + { + push(@check_testcases, $tinfo->{'name'}); + } + } + + if ( @check_testcases ) + { + print "Check of testcase failed for: "; + print join(" ", @check_testcases); + print "\n\n"; + } } + if ( $tot_failed != 0 || $found_problems) { mtr_error("there where failing test cases"); diff --git a/mysql-test/lib/mtr_stress.pl b/mysql-test/lib/mtr_stress.pl index a7d4b68b69d..1371eaa44c6 100644 --- a/mysql-test/lib/mtr_stress.pl +++ b/mysql-test/lib/mtr_stress.pl @@ -122,7 +122,7 @@ sub run_stress_test () mtr_init_args(\$args); - mtr_add_arg($args, "--server-socket=%s", $::master->[0]->{'path_mysock'}); + mtr_add_arg($args, "--server-socket=%s", $::master->[0]->{'path_sock'}); mtr_add_arg($args, "--server-user=%s", $::opt_user); mtr_add_arg($args, "--server-database=%s", "test"); mtr_add_arg($args, "--stress-suite-basedir=%s", $::glob_mysql_test_dir); @@ -140,7 +140,7 @@ sub run_stress_test () if ( $::opt_stress_init_file ) { - mtr_add_arg($args, "--stress-init-file=%", $::opt_stress_init_file); + mtr_add_arg($args, "--stress-init-file=%s", $::opt_stress_init_file); } if ( !$::opt_stress_loop_count && !$::opt_stress_test_count && @@ -168,10 +168,9 @@ sub run_stress_test () #Run stress test mtr_run("$::glob_mysql_test_dir/mysql-stress-test.pl", $args, "", "", "", ""); - if ( ! $::glob_use_embedded_server ) { - stop_masters(); + stop_all_servers(); } } diff --git a/mysql-test/lib/mtr_timer.pl b/mysql-test/lib/mtr_timer.pl index a85ab8c6122..06374716c62 100644 --- a/mysql-test/lib/mtr_timer.pl +++ b/mysql-test/lib/mtr_timer.pl @@ -4,23 +4,19 @@ # and is part of the translation of the Bourne shell script with the # same name. -use Carp qw(cluck); use Socket; use Errno; use strict; -#use POSIX ":sys_wait_h"; -use POSIX 'WNOHANG'; - sub mtr_init_timers (); sub mtr_timer_start($$$); sub mtr_timer_stop($$); sub mtr_timer_stop_all($); -sub mtr_timer_waitpid($$$); + ############################################################################## # -# Initiate a structure shared by all timers +# Initiate the structure shared by all timers # ############################################################################## @@ -35,17 +31,19 @@ sub mtr_init_timers () { # Start, stop and poll a timer # # As alarm() isn't portable to Windows, we use separate processes to -# implement timers. That is why there is a mtr_timer_waitpid(), as this -# is where we catch a timeout. +# implement timers. # ############################################################################## sub mtr_timer_start($$$) { my ($timers,$name,$duration)= @_; + mtr_verbose("mtr_timer_start: $name, $duration"); + if ( exists $timers->{'timers'}->{$name} ) { # We have an old running timer, kill it + mtr_verbose("There is an old timer running"); mtr_timer_stop($timers,$name); } @@ -57,7 +55,7 @@ sub mtr_timer_start($$$) { { if ( $! == $!{EAGAIN} ) # See "perldoc Errno" { - mtr_debug("Got EAGAIN from fork(), sleep 1 second and redo"); + mtr_warning("Got EAGAIN from fork(), sleep 1 second and redo"); sleep(1); redo FORK; } @@ -70,6 +68,7 @@ sub mtr_timer_start($$$) { if ( $tpid ) { # Parent, record the information + mtr_verbose("timer parent, record info($name, $tpid, $duration)"); $timers->{'timers'}->{$name}->{'pid'}= $tpid; $timers->{'timers'}->{$name}->{'duration'}= $duration; $timers->{'pids'}->{$tpid}= $name; @@ -85,6 +84,7 @@ sub mtr_timer_start($$$) { $SIG{INT}= 'DEFAULT'; $0= "mtr_timer(timers,$name,$duration)"; + mtr_verbose("timer child $name, sleep $duration"); sleep($duration); exit(0); } @@ -95,9 +95,12 @@ sub mtr_timer_start($$$) { sub mtr_timer_stop ($$) { my ($timers,$name)= @_; + mtr_verbose("mtr_timer_stop: $name"); + if ( exists $timers->{'timers'}->{$name} ) { my $tpid= $timers->{'timers'}->{$name}->{'pid'}; + mtr_verbose("Stopping timer with pid $tpid"); # FIXME as Cygwin reuses pids fast, maybe check that is # the expected process somehow?! @@ -114,7 +117,7 @@ sub mtr_timer_stop ($$) { } else { - mtr_debug("Asked to stop timer \"$name\" not started"); + mtr_error("Asked to stop timer \"$name\" not started"); return 0; } } @@ -136,10 +139,8 @@ sub mtr_timer_timeout ($$) { return "" unless exists $timers->{'pids'}->{$pid}; - # We got a timeout - my $name= $timers->{'pids'}->{$pid}; - mtr_timer_stop($timers, $timers->{'timers'}->{$name}); - return $name; + # We got a timeout, return the name ot the timer + return $timers->{'pids'}->{$pid}; } 1; diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index e5ed8a99304..3aeca32f2e8 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1,30 +1,24 @@ #!/usr/bin/perl # -*- cperl -*- -# This is a transformation of the "mysql-test-run" Bourne shell script -# to Perl. There are reasons this rewrite is not the prettiest Perl -# you have seen # -# - The original script is huge and for most part uncommented, -# not even a usage description of the flags. +############################################################################## +# +# mysql-test-run.pl +# +# Tool used for executing a suite of .test file # -# - There has been an attempt to write a replacement in C for the -# original Bourne shell script. It was kind of working but lacked -# lot of functionality to really be a replacement. Not to redo -# that mistake and catch all the obscure features of the original -# script, the rewrite in Perl is more close to the original script -# meaning it also share some of the ugly parts as well. +# See the "MySQL Test framework manual" for more information +# http://dev.mysql.com/doc/mysqltest/en/index.html # -# - The original intention was that this script was to be a prototype -# to be the base for a new C version with full functionality. Since -# then it was decided that the Perl version should replace the -# Bourne shell version, but the Perl style still reflects the wish -# to make the Perl to C step easy. +# Please keep the test framework tools identical in all versions! +# +############################################################################## # -# Some coding style from the original intent has been kept +# Coding style directions for this perl script # # - To make this Perl script easy to alter even for those that not -# code Perl that often, the coding style is as close as possible to +# code Perl that often, keeep the coding style as close as possible to # the C/C++ MySQL coding standard. # # - All lists of arguments to send to commands are Perl lists/arrays, @@ -42,15 +36,6 @@ # the information. This separates the "find information" from the # "do the work" and makes the program more easy to maintain. # -# - At the moment, there are tons of "global" variables that control -# this script, even accessed from the files in "lib/*.pl". This -# will change over time, for now global variables are used instead -# of using %opt, %path and %exe hashes, because I want more -# compile time checking, that hashes would not give me. Once this -# script is debugged, hashes will be used and passed as parameters -# to functions, to more closely mimic how it would be coded in C -# using structs. -# # - The rule when it comes to the logic of this program is # # command_line_setup() - is to handle the logic between flags @@ -66,10 +51,6 @@ # "http://www.plover.com/~mjd/perl/Trace/" and run this script like # "perl -d:Trace mysql-test-run.pl" # -# FIXME Save a PID file from this code as well, to record the process -# id we think it has. In Cygwin, a fork creates one Cygwin process, -# and then the real Win32 process. Cygwin Perl can only kill Cygwin -# processes. And "mysqld --bootstrap ..." doesn't save a PID file. $Devel::Trace::TRACE= 0; # Don't trace boring init stuff @@ -80,12 +61,20 @@ use File::Copy; use Cwd; use Getopt::Long; use Sys::Hostname; -#use Carp; use IO::Socket; use IO::Socket::INET; use Data::Dumper; use strict; -#use diagnostics; +use warnings; +use diagnostics; + +select(STDOUT); +$| = 1; # Automatically flush STDOUT + +our $glob_win32_perl= ($^O eq "MSWin32"); # ActiveState Win32 Perl +our $glob_cygwin_perl= ($^O eq "cygwin"); # Cygwin Perl +our $glob_win32= ($glob_win32_perl or $glob_cygwin_perl); +our $glob_netware= ($^O eq "NetWare"); # NetWare require "lib/mtr_cases.pl"; require "lib/mtr_im.pl"; @@ -102,38 +91,14 @@ require "lib/mtr_stress.pl"; $Devel::Trace::TRACE= 1; -# Used by gcov -our @mysqld_src_dirs= - ( - "strings", - "mysys", - "include", - "extra", - "regex", - "isam", - "merge", - "myisam", - "myisammrg", - "heap", - "sql", - ); - ############################################################################## # # Default settings # ############################################################################## -# We are to use handle_options() in "mysys/my_getopt.c" for the C version -# -# In the C version we want to use structs and, in some cases, arrays of -# structs. We let each struct be a separate hash. - # Misc global variables - -our $glob_win32= 0; # OS and native Win32 executables -our $glob_win32_perl= 0; # ActiveState Win32 Perl -our $glob_cygwin_perl= 0; # Cygwin Perl +our $mysql_version_id; our $glob_mysql_test_dir= undef; our $glob_mysql_bench_dir= undef; our $glob_hostname= undef; @@ -147,42 +112,44 @@ our @glob_test_mode; our $glob_basedir; -# The total result - our $path_charsetsdir; our $path_client_bindir; our $path_language; our $path_timefile; our $path_snapshot; -our $path_slave_load_tmpdir; # What is this?! our $path_mysqltest_log; our $path_current_test_log; our $path_my_basedir; + our $opt_vardir; # A path but set directly on cmd line -our $opt_vardir_trace; # unix formatted opt_vardir for trace files +our $path_vardir_trace; # unix formatted opt_vardir for trace files our $opt_tmpdir; # A path but set directly on cmd line +# Visual Studio produces executables in different sub-directories based on the +# configuration used to build them. To make life easier, an environment +# variable or command-line option may be specified to control which set of +# executables will be used by the test suite. +our $opt_vs_config = $ENV{'MTR_VS_CONFIG'}; + +our $default_vardir; + our $opt_usage; our $opt_suite; -our $opt_netware; - our $opt_script_debug= 0; # Script debugging, enable with --script-debug our $opt_verbose= 0; # Verbose output, enable with --verbose -# Options FIXME not all.... - our $exe_master_mysqld; our $exe_mysql; our $exe_mysqladmin; our $exe_mysqlbinlog; our $exe_mysql_client_test; our $exe_mysqld; -our $exe_mysqlcheck; # Called from test case -our $exe_mysqldump; # Called from test case -our $exe_mysqlslap; # Called from test case -our $exe_mysqlimport; # Called from test case -our $exe_mysqlshow; # Called from test case +our $exe_mysqlcheck; +our $exe_mysqldump; +our $exe_mysqlslap; +our $exe_mysqlimport; +our $exe_mysqlshow; our $exe_mysql_fix_system_tables; our $exe_mysqltest; our $exe_ndbd; @@ -218,6 +185,7 @@ our $opt_fast; our $opt_force; our $opt_reorder= 0; our $opt_enable_disabled; +our $opt_mem; our $opt_gcov; our $opt_gcov_err; @@ -239,7 +207,7 @@ our $opt_gprof_dir; our $opt_gprof_master; our $opt_gprof_slave; -our $master; # Will be struct in C +our $master; our $slave; our $clusters; @@ -253,8 +221,6 @@ our $opt_ndbconnectstring_slave; our $opt_record; our $opt_check_testcases; -our $opt_result_ext; - our $opt_skip; our $opt_skip_rpl; our $max_slave_num= 0; @@ -316,7 +282,7 @@ our $opt_skip_ndbcluster= 0; our $opt_skip_ndbcluster_slave= 0; our $opt_with_ndbcluster= 0; our $opt_with_ndbcluster_only= 0; -our $opt_ndbcluster_supported= 0; +our $glob_ndbcluster_supported= 0; our $opt_ndb_extra_test= 0; our $opt_skip_master_binlog= 0; our $opt_skip_slave_binlog= 0; @@ -326,7 +292,7 @@ our $exe_ndb_waiter; our $path_ndb_tools_dir; our $path_ndb_examples_dir; our $exe_ndb_example; -our $file_ndb_testrun_log; +our $path_ndb_testrun_log; our @data_dir_lst; @@ -334,6 +300,9 @@ our $used_binlog_format; our $debug_compiled_binaries; our $glob_tot_real_time= 0; +our %mysqld_variables; + + ###################################################################### # # Function declarations @@ -343,14 +312,14 @@ our $glob_tot_real_time= 0; sub main (); sub initial_setup (); sub command_line_setup (); -sub snapshot_setup (); +sub datadir_setup (); sub executable_setup (); sub environment_setup (); -sub kill_running_server (); +sub kill_running_servers (); sub cleanup_stale_files (); -sub check_ssl_support (); +sub check_ssl_support ($); sub check_running_as_root(); -sub check_ndbcluster_support (); +sub check_ndbcluster_support ($); sub rm_ndbcluster_tables ($); sub ndbcluster_start_install ($); sub ndbcluster_start ($$); @@ -366,8 +335,8 @@ sub run_testcase_stop_servers ($$$); sub run_testcase_start_servers ($); sub run_testcase_check_skip_test($); sub report_failure_and_restart ($); -sub do_before_start_master ($$); -sub do_before_start_slave ($$); +sub do_before_start_master ($); +sub do_before_start_slave ($); sub ndbd_start ($$$); sub ndb_mgmd_start ($); sub mysqld_start ($$$); @@ -386,13 +355,13 @@ main(); sub main () { - initial_setup(); command_line_setup(); - executable_setup(); - check_ndbcluster_support(); - check_ssl_support(); - check_debug_support(); + check_ndbcluster_support(\%mysqld_variables); + check_ssl_support(\%mysqld_variables); + check_debug_support(\%mysqld_variables); + + executable_setup(); environment_setup(); signal_setup(); @@ -426,6 +395,8 @@ sub main () { my ($need_ndbcluster,$need_im); foreach my $test (@$tests) { + next if $test->{skip}; + $need_ndbcluster||= $test->{ndb_test}; $need_im||= $test->{component_id} eq 'im'; @@ -437,77 +408,35 @@ sub main () { } $use_innodb||= $test->{'innodb_test'}; } - $opt_skip_ndbcluster= $opt_skip_ndbcluster_slave= 1 - unless $need_ndbcluster; - $opt_skip_im= 1 unless $need_im; - - snapshot_setup(); - initialize_servers(); - - run_suite($opt_suite, $tests); - } - - mtr_exit(0); -} - -############################################################################## -# -# Initial setup independent on command line arguments -# -############################################################################## - -sub initial_setup () { - - select(STDOUT); - $| = 1; # Make unbuffered - $glob_scriptname= basename($0); - - $glob_win32_perl= ($^O eq "MSWin32"); - $glob_cygwin_perl= ($^O eq "cygwin"); - $glob_win32= ($glob_win32_perl or $glob_cygwin_perl); - - # We require that we are in the "mysql-test" directory - # to run mysql-test-run + # Check if cluster can be skipped + if ( !$need_ndbcluster ) + { + $opt_skip_ndbcluster= 1; + $opt_skip_ndbcluster_slave= 1; + } - if (! -f $glob_scriptname) - { - mtr_error("Can't find the location for the mysql-test-run script\n" . - "Go to to the mysql-test directory and execute the script " . - "as follows:\n./$glob_scriptname"); - } + # Check if slave cluster can be skipped + if ($max_slave_num == 0) + { + $opt_skip_ndbcluster_slave= 1; + } - if ( -d "../sql" ) - { - $opt_source_dist= 1; - } + # Check if im can be skipped + if ( ! $need_im ) + { + $opt_skip_im= 1; + } - $glob_hostname= mtr_short_hostname(); + initialize_servers(); - # 'basedir' is always parent of "mysql-test" directory - $glob_mysql_test_dir= cwd(); - if ( $glob_cygwin_perl ) - { - # Windows programs like 'mysqld' needs Windows paths - $glob_mysql_test_dir= `cygpath -m "$glob_mysql_test_dir"`; - chomp($glob_mysql_test_dir); + run_suite($opt_suite, $tests); } - $glob_basedir= dirname($glob_mysql_test_dir); - # Expect mysql-bench to be located adjacent to the source tree, by default - $glob_mysql_bench_dir= "$glob_basedir/../mysql-bench" - unless defined $glob_mysql_bench_dir; - - # needs to be same length to test logging (FIXME what???) - $path_slave_load_tmpdir= "../../var/tmp"; - - $path_my_basedir= - $opt_source_dist ? $glob_mysql_test_dir : $glob_basedir; - $glob_timers= mtr_init_timers(); + mtr_exit(0); } - ############################################################################## # # Default settings @@ -583,10 +512,11 @@ sub command_line_setup () { 'compress' => \$opt_compress, 'bench' => \$opt_bench, 'small-bench' => \$opt_small_bench, + 'with-ndbcluster' => \$opt_with_ndbcluster, + 'vs-config' => \$opt_vs_config, # Control what test suites or cases to run 'force' => \$opt_force, - 'with-ndbcluster' => \$opt_with_ndbcluster, 'with-ndbcluster-only' => \$opt_with_ndbcluster_only, 'skip-ndbcluster|skip-ndb' => \$opt_skip_ndbcluster, 'skip-ndbcluster-slave|skip-ndb-slave' @@ -661,12 +591,12 @@ sub command_line_setup () { 'tmpdir=s' => \$opt_tmpdir, 'vardir=s' => \$opt_vardir, 'benchdir=s' => \$glob_mysql_bench_dir, + 'mem' => \$opt_mem, # Misc 'comment=s' => \$opt_comment, 'debug' => \$opt_debug, 'fast' => \$opt_fast, - 'netware' => \$opt_netware, 'reorder' => \$opt_reorder, 'enable-disabled' => \$opt_enable_disabled, 'script-debug' => \$opt_script_debug, @@ -689,6 +619,69 @@ sub command_line_setup () { usage("") if $opt_usage; + $glob_scriptname= basename($0); + + # We require that we are in the "mysql-test" directory + # to run mysql-test-run + if (! -f $glob_scriptname) + { + mtr_error("Can't find the location for the mysql-test-run script\n" . + "Go to to the mysql-test directory and execute the script " . + "as follows:\n./$glob_scriptname"); + } + + if ( -d "../sql" ) + { + $opt_source_dist= 1; + } + + $glob_hostname= mtr_short_hostname(); + + # 'basedir' is always parent of "mysql-test" directory + $glob_mysql_test_dir= cwd(); + if ( $glob_cygwin_perl ) + { + # Windows programs like 'mysqld' needs Windows paths + $glob_mysql_test_dir= `cygpath -m "$glob_mysql_test_dir"`; + chomp($glob_mysql_test_dir); + } + $glob_basedir= dirname($glob_mysql_test_dir); + + # Expect mysql-bench to be located adjacent to the source tree, by default + $glob_mysql_bench_dir= "$glob_basedir/../mysql-bench" + unless defined $glob_mysql_bench_dir; + + $path_my_basedir= + $opt_source_dist ? $glob_mysql_test_dir : $glob_basedir; + + $glob_timers= mtr_init_timers(); + + # + # Find the mysqld executable to be able to find the mysqld version + # number as early as possible + # + + # Look for the client binaries + $path_client_bindir= mtr_path_exists(vs_config_dirs('client', ''), + "$glob_basedir/client_release", + "$glob_basedir/client_debug", + "$glob_basedir/client", + "$glob_basedir/bin"); + + $exe_mysqld= mtr_exe_exists (vs_config_dirs('sql', 'mysqld'), + "$glob_basedir/sql/mysqld", + "$path_client_bindir/mysqld-max-nt", + "$path_client_bindir/mysqld-max", + "$path_client_bindir/mysqld-nt", + "$path_client_bindir/mysqld", + "$path_client_bindir/mysqld-debug", + "$path_client_bindir/mysqld-max", + "$glob_basedir/libexec/mysqld", + "$glob_basedir/bin/mysqld"); + + # Use the mysqld found above to find out what features are available + collect_mysqld_features(); + if ( $opt_comment ) { print "\n"; @@ -722,29 +715,75 @@ sub command_line_setup () { # -------------------------------------------------------------------------- # Find out type of logging that are being used # -------------------------------------------------------------------------- - # NOTE if the default binlog format is changed, this has to be changed $used_binlog_format= "stmt"; - foreach my $arg ( @opt_extra_mysqld_opt ) + if ( $mysql_version_id >= 50100 ) { - if ( defined mtr_match_substring($arg,"binlog-format=row")) + $used_binlog_format= "mixed"; # Default value for binlog format + + foreach my $arg ( @opt_extra_mysqld_opt ) + { + if ( $arg =~ /binlog-format=(\S+)/ ) + { + $used_binlog_format= $1; + } + } + mtr_report("Using binlog format '$used_binlog_format'"); + } + + # -------------------------------------------------------------------------- + # Check if we should speed up tests by trying to run on tmpfs + # -------------------------------------------------------------------------- + if ( $opt_mem ) + { + mtr_error("Can't use --mem and --vardir at the same time ") + if $opt_vardir; + mtr_error("Can't use --mem and --tmpdir at the same time ") + if $opt_tmpdir; + + # Use /dev/shm as the preferred location for vardir and + # thus implicitly also tmpdir. Add other locations to list + my @tmpfs_locations= ("/dev/shm"); + # One could maybe use "mount" to find tmpfs location(s) + foreach my $fs (@tmpfs_locations) { - $used_binlog_format= "row"; + if ( -d $fs ) + { + mtr_report("Using tmpfs in $fs"); + $opt_mem= "$fs/var"; + $opt_mem .= $ENV{'MTR_BUILD_THREAD'} if $ENV{'MTR_BUILD_THREAD'}; + last; + } } } - mtr_report("Using binlog format '$used_binlog_format'"); # -------------------------------------------------------------------------- # Set the "var/" directory, as it is the base for everything else # -------------------------------------------------------------------------- - + $default_vardir= "$glob_mysql_test_dir/var"; if ( ! $opt_vardir ) { - $opt_vardir= "$glob_mysql_test_dir/var"; + $opt_vardir= $default_vardir; } - $opt_vardir_trace= $opt_vardir; + elsif ( $mysql_version_id < 50000 and + $opt_vardir ne $default_vardir) + { + # Version 4.1 and --vardir was specified + # Only supported as a symlink from var/ + # by setting up $opt_mem that symlink will be created + if ( ! $glob_win32 ) + { + # Only platforms that have native symlinks can use the vardir trick + $opt_mem= $opt_vardir; + mtr_report("Using 4.1 vardir trick"); + } + + $opt_vardir= $default_vardir; + } + + $path_vardir_trace= $opt_vardir; # Chop off any "c:", DBUG likes a unix path ex: c:/src/... => /src/... - $opt_vardir_trace=~ s/^\w://; + $path_vardir_trace=~ s/^\w://; # We make the path absolute, as the server will do a chdir() before usage unless ( $opt_vardir =~ m,^/, or @@ -755,31 +794,46 @@ sub command_line_setup () { } # -------------------------------------------------------------------------- - # If not set, set these to defaults + # Set tmpdir # -------------------------------------------------------------------------- - $opt_tmpdir= "$opt_vardir/tmp" unless $opt_tmpdir; $opt_tmpdir =~ s,/+$,,; # Remove ending slash if any # -------------------------------------------------------------------------- - # Do sanity checks of command line arguments + # Set socket # -------------------------------------------------------------------------- - - if ( ! $opt_socket ) - { # FIXME set default before reading options? -# $opt_socket= '@MYSQL_UNIX_ADDR@'; - $opt_socket= "/tmp/mysql.sock"; # FIXME + if (!$opt_socket) + { + $opt_socket= $mysqld_variables{'socket'}; } # -------------------------------------------------------------------------- - # Look at the command line options and set script flags + # Check im suport # -------------------------------------------------------------------------- + if ( $mysql_version_id < 50000 ) + { + # Instance manager is not supported until 5.0 + $opt_skip_im= 1; + + } + + if ( $glob_win32 ) + { + mtr_report("Disable Instance manager - not supported on Windows"); + $opt_skip_im= 1; + } + # -------------------------------------------------------------------------- + # Record flag + # -------------------------------------------------------------------------- if ( $opt_record and ! @opt_cases ) { mtr_error("Will not run in record mode without a specific test case"); } + # -------------------------------------------------------------------------- + # Embedded server flag + # -------------------------------------------------------------------------- if ( $opt_embedded_server ) { $glob_use_embedded_server= 1; @@ -794,14 +848,21 @@ sub command_line_setup () { } } + + # -------------------------------------------------------------------------- + # ps protcol flag + # -------------------------------------------------------------------------- if ( $opt_ps_protocol ) { push(@glob_test_mode, "ps-protocol"); } - if ( $opt_with_ndbcluster and $opt_skip_ndbcluster) + # -------------------------------------------------------------------------- + # Ndb cluster flags + # -------------------------------------------------------------------------- + if ( $opt_with_ndbcluster and !$opt_bench) { - mtr_error("Can't specify both --with-ndbcluster and --skip-ndbcluster"); + mtr_error("Can only use --with-ndbcluster togheter with --bench"); } if ( $opt_ndbconnectstring ) @@ -834,22 +895,33 @@ sub command_line_setup () { $opt_ndbconnectstring_slave= "host=localhost:$opt_ndbcluster_port_slave"; } + # -------------------------------------------------------------------------- + # Bench flags + # -------------------------------------------------------------------------- if ( $opt_small_bench ) { $opt_bench= 1; } + # -------------------------------------------------------------------------- + # Sleep flag + # -------------------------------------------------------------------------- if ( $opt_sleep ) { $opt_sleep_time_after_restart= $opt_sleep; } + # -------------------------------------------------------------------------- + # Gcov flag + # -------------------------------------------------------------------------- if ( $opt_gcov and ! $opt_source_dist ) { mtr_error("Coverage test needs the source - please use source dist"); } + # -------------------------------------------------------------------------- # Check debug related options + # -------------------------------------------------------------------------- if ( $opt_gdb || $opt_client_gdb || $opt_ddd || $opt_client_ddd || $opt_manual_gdb || $opt_manual_ddd || $opt_manual_debug || $opt_debugger || $opt_client_debugger ) @@ -864,13 +936,15 @@ sub command_line_setup () { } } - # Check IM arguments - if ( $glob_win32 ) - { - mtr_report("Disable Instance manager - not supported on Windows"); - $opt_skip_im= 1; - } + # -------------------------------------------------------------------------- + # Check if special exe was selected for master or slave + # -------------------------------------------------------------------------- + $exe_master_mysqld= $exe_master_mysqld || $exe_mysqld; + $exe_slave_mysqld= $exe_slave_mysqld || $exe_mysqld; + + # -------------------------------------------------------------------------- # Check valgrind arguments + # -------------------------------------------------------------------------- if ( $opt_valgrind or $opt_valgrind_path or defined $opt_valgrind_options) { mtr_report("Turning on valgrind for all executables"); @@ -885,7 +959,7 @@ sub command_line_setup () { } elsif ( $opt_valgrind_mysqltest ) { - mtr_report("Turning on valgrind for mysqltest only"); + mtr_report("Turning on valgrind for mysqltest and mysql_client_test only"); $opt_valgrind= 1; } @@ -1120,11 +1194,12 @@ sub command_line_setup () { $path_timefile= "$opt_vardir/log/mysqltest-time"; $path_mysqltest_log= "$opt_vardir/log/mysqltest.log"; $path_current_test_log= "$opt_vardir/log/current_test"; + $path_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log"; $path_snapshot= "$opt_tmpdir/snapshot_$opt_master_myport/"; } -sub snapshot_setup () { +sub datadir_setup () { # Make a list of all data_dirs @data_dir_lst = ( @@ -1152,6 +1227,135 @@ sub snapshot_setup () { # ############################################################################## + +sub collect_mysqld_features () { + # + # Execute "mysqld --no-defaults --help --verbose", that will + # print out version and a list of all features and settings + # + my $found_variable_list_start= 0; + my $spec_file= "$glob_mysql_test_dir/mysqld.spec.$$"; + if ( mtr_run($exe_mysqld, + ["--no-defaults", + "--verbose", + "--help"], + "", "$spec_file", "$spec_file", "") != 0 ) + { + mtr_error("Failed to get version and list of features from %s", + $exe_mysqld); + } + + my $F= IO::File->new($spec_file) or + mtr_error("can't open file \"$spec_file\": $!"); + + while ( my $line= <$F> ) + { + # First look for version + if ( !$mysql_version_id ) + { + # Look for version + my $exe_name= basename($exe_mysqld); + mtr_verbose("exe_name: $exe_name"); + if ( $line =~ /^\S*$exe_name\s\sVer\s([0-9]*)\.([0-9]*)\.([0-9]*)/ ) + { + #print "Major: $1 Minor: $2 Build: $3\n"; + $mysql_version_id= $1*10000 + $2*100 + $3; + #print "mysql_version_id: $mysql_version_id\n"; + mtr_report("MySQL Version $1.$2.$3"); + } + } + else + { + if (!$found_variable_list_start) + { + # Look for start of variables list + if ( $line =~ /[\-]+\s[\-]+/ ) + { + $found_variable_list_start= 1; + } + } + else + { + # Put variables into hash + if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ ) + { + # print "$1=\"$2\"\n"; + $mysqld_variables{$1}= $2; + } + else + { + # The variable list is ended with a blank line + if ( $line =~ /^[\s]*$/ ) + { + last; + } + else + { + # Send out a warning, we should fix the variables that has no + # space between variable name and it's value + # or should it be fixed width column parsing? It does not + # look like that in function my_print_variables in my_getopt.c + mtr_warning("Could not parse variable list line : $line"); + } + } + } + } + } + unlink($spec_file); + mtr_error("Could not find version of MySQL") unless $mysql_version_id; + mtr_error("Could not find variabes list") unless $found_variable_list_start; + +} + + +sub executable_setup_im () { + + # Look for instance manager binary - mysqlmanager + $exe_im= + mtr_exe_maybe_exists( + "$glob_basedir/server-tools/instance-manager/mysqlmanager", + "$glob_basedir/libexec/mysqlmanager"); + + return ($exe_im eq ""); +} + +sub executable_setup_ndb () { + + # Look for ndb tols and binaries + my $ndb_path= mtr_file_exists("$glob_basedir/ndb", + "$glob_basedir/storage/ndb", + "$glob_basedir/bin"); + + $exe_ndbd= + mtr_exe_maybe_exists("$ndb_path/src/kernel/ndbd", + "$ndb_path/ndbd"); + $exe_ndb_mgm= + mtr_exe_maybe_exists("$ndb_path/src/mgmclient/ndb_mgm", + "$ndb_path/ndb_mgm"); + $exe_ndb_mgmd= + mtr_exe_maybe_exists("$ndb_path/src/mgmsrv/ndb_mgmd", + "$ndb_path/ndb_mgmd"); + $exe_ndb_waiter= + mtr_exe_maybe_exists("$ndb_path/tools/ndb_waiter", + "$ndb_path/ndb_waiter"); + + # May not exist + $path_ndb_tools_dir= mtr_file_exists("$ndb_path/tools", + "$ndb_path"); + # May not exist + $path_ndb_examples_dir= + mtr_file_exists("$ndb_path/ndbapi-examples", + "$ndb_path/examples"); + # May not exist + $exe_ndb_example= + mtr_file_exists("$path_ndb_examples_dir/ndbapi_simple/ndbapi_simple"); + + return ( $exe_ndbd eq "" or + $exe_ndb_mgm eq "" or + $exe_ndb_mgmd eq "" or + $exe_ndb_waiter eq ""); +} + sub executable_setup () { # @@ -1169,161 +1373,101 @@ sub executable_setup () { } } - if ( $opt_source_dist ) + # Look for language files and charsetsdir, use same share + my $path_share= mtr_path_exists("$glob_basedir/share/mysql", + "$glob_basedir/sql/share", + "$glob_basedir/share"); + + $path_language= mtr_path_exists("$path_share/english"); + $path_charsetsdir= mtr_path_exists("$path_share/charsets"); + + # Look for my_print_defaults + $exe_my_print_defaults= + mtr_exe_exists(vs_config_dirs('extra', 'my_print_defaults'), + "$path_client_bindir/my_print_defaults", + "$glob_basedir/extra/my_print_defaults"); + + # Look for perror + $exe_perror= mtr_exe_exists(vs_config_dirs('extra', 'perror'), + "$glob_basedir/extra/perror", + "$path_client_bindir/perror"); + + # Look for the client binaries + $exe_mysqlcheck= mtr_exe_exists("$path_client_bindir/mysqlcheck"); + $exe_mysqldump= mtr_exe_exists("$path_client_bindir/mysqldump"); + $exe_mysqlimport= mtr_exe_exists("$path_client_bindir/mysqlimport"); + $exe_mysqlshow= mtr_exe_exists("$path_client_bindir/mysqlshow"); + $exe_mysqlbinlog= mtr_exe_exists("$path_client_bindir/mysqlbinlog"); + $exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin"); + $exe_mysql= mtr_exe_exists("$path_client_bindir/mysql"); + if ( $mysql_version_id >= 50100 ) { - if ( $glob_win32 ) - { - $path_client_bindir= mtr_path_exists("$glob_basedir/client_release", - "$glob_basedir/client_debug", - "$glob_basedir/bin", - # New CMake locations. - "$glob_basedir/client/release", - "$glob_basedir/client/debug"); - $exe_mysqld= mtr_exe_exists ("$path_client_bindir/mysqld-max-nt", - "$path_client_bindir/mysqld-max", - "$path_client_bindir/mysqld-nt", - "$path_client_bindir/mysqld", - "$path_client_bindir/mysqld-max", - "$path_client_bindir/mysqld-debug", - "$glob_basedir/sql/release/mysqld", - "$glob_basedir/sql/debug/mysqld"); - $path_language= mtr_path_exists("$glob_basedir/share/english/", - "$glob_basedir/sql/share/english/"); - $path_charsetsdir= mtr_path_exists("$glob_basedir/share/charsets", - "$glob_basedir/sql/share/charsets"); - $exe_my_print_defaults= - mtr_exe_exists("$path_client_bindir/my_print_defaults", - "$glob_basedir/extra/release/my_print_defaults", - "$glob_basedir/extra/debug/my_print_defaults"); - $exe_perror= - mtr_exe_exists("$path_client_bindir/perror", - "$glob_basedir/extra/release/perror", - "$glob_basedir/extra/debug/perror"); - } - else - { - $path_client_bindir= mtr_path_exists("$glob_basedir/client"); - $exe_mysqld= mtr_exe_exists ("$glob_basedir/sql/mysqld"); - $exe_mysqlslap= mtr_exe_exists ("$path_client_bindir/mysqlslap"); - $path_language= mtr_path_exists("$glob_basedir/sql/share/english/"); - $path_charsetsdir= mtr_path_exists("$glob_basedir/sql/share/charsets"); - - $exe_im= mtr_exe_exists( - "$glob_basedir/server-tools/instance-manager/mysqlmanager"); - $exe_my_print_defaults= - mtr_exe_exists("$glob_basedir/extra/my_print_defaults"); - $exe_perror= - mtr_exe_exists("$glob_basedir/extra/perror"); - } + $exe_mysqlslap= mtr_exe_exists("$path_client_bindir/mysqlslap"); + } - if ( $glob_use_embedded_server ) - { - my $path_examples= "$glob_basedir/libmysqld/examples"; - $exe_mysqltest= mtr_exe_exists("$path_examples/mysqltest_embedded"); - $exe_mysql_client_test= - mtr_exe_exists("$path_examples/mysql_client_test_embedded", - "/usr/bin/false"); - } - else - { - $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest"); - $exe_mysql_client_test= - mtr_exe_exists("$glob_basedir/tests/mysql_client_test", - "$glob_basedir/tests/release/mysql_client_test", - "$glob_basedir/tests/debug/mysql_client_test", - "$path_client_bindir/mysql_client_test", - "/usr/bin/false"); - } - $exe_mysqlcheck= mtr_exe_exists("$path_client_bindir/mysqlcheck"); - $exe_mysqldump= mtr_exe_exists("$path_client_bindir/mysqldump"); - $exe_mysqlimport= mtr_exe_exists("$path_client_bindir/mysqlimport"); - $exe_mysqlshow= mtr_exe_exists("$path_client_bindir/mysqlshow"); - $exe_mysqlbinlog= mtr_exe_exists("$path_client_bindir/mysqlbinlog"); - $exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin"); - $exe_mysql= mtr_exe_exists("$path_client_bindir/mysql"); + if ( ! $glob_win32 ) + { + # Look for mysql_fix_system_table script $exe_mysql_fix_system_tables= mtr_script_exists("$glob_basedir/scripts/mysql_fix_privilege_tables", - "/usr/bin/false"); - $path_ndb_tools_dir= mtr_path_exists("$glob_basedir/storage/ndb/tools"); - $path_ndb_examples_dir= mtr_path_exists("$glob_basedir/storage/ndb/ndbapi-examples"); - $exe_ndb_example= mtr_file_exists("$path_ndb_examples_dir/ndbapi_simple/ndbapi_simple"); - $exe_ndb_mgm= "$glob_basedir/storage/ndb/src/mgmclient/ndb_mgm"; - $exe_ndb_waiter= "$glob_basedir/storage/ndb/tools/ndb_waiter"; - $exe_ndbd= "$glob_basedir/storage/ndb/src/kernel/ndbd"; - $exe_ndb_mgmd= "$glob_basedir/storage/ndb/src/mgmsrv/ndb_mgmd"; - $lib_udf_example= - mtr_file_exists("$glob_basedir/sql/.libs/udf_example.so", - "$glob_basedir/sql/release/udf_example.dll", - "$glob_basedir/sql/debug/udf_example.dll"); + "$path_client_bindir/mysql_fix_privilege_tables"); } - else + + + if ( ! $opt_skip_ndbcluster and executable_setup_ndb()) { - $path_client_bindir= mtr_path_exists("$glob_basedir/bin"); - $exe_mysqlcheck= mtr_exe_exists("$path_client_bindir/mysqlcheck"); - $exe_mysqldump= mtr_exe_exists("$path_client_bindir/mysqldump"); - $exe_mysqlimport= mtr_exe_exists("$path_client_bindir/mysqlimport"); - $exe_mysqlshow= mtr_exe_exists("$path_client_bindir/mysqlshow"); - $exe_mysqlbinlog= mtr_exe_exists("$path_client_bindir/mysqlbinlog"); - $exe_mysqladmin= mtr_exe_exists("$path_client_bindir/mysqladmin"); - $exe_mysql= mtr_exe_exists("$path_client_bindir/mysql"); - $exe_mysql_fix_system_tables= - mtr_script_exists("$path_client_bindir/mysql_fix_privilege_tables", - "$glob_basedir/scripts/mysql_fix_privilege_tables", - "/usr/bin/false"); - $exe_my_print_defaults= - mtr_exe_exists("$path_client_bindir/my_print_defaults"); - $exe_perror= - mtr_exe_exists("$path_client_bindir/perror"); - - $path_language= mtr_path_exists("$glob_basedir/share/mysql/english/", - "$glob_basedir/share/english/"); - $path_charsetsdir= mtr_path_exists("$glob_basedir/share/mysql/charsets", - "$glob_basedir/share/charsets"); - - if ( $glob_win32 ) - { - $exe_mysqld= mtr_exe_exists ("$glob_basedir/bin/mysqld-nt", - "$glob_basedir/bin/mysqld", - "$glob_basedir/bin/mysqld-debug",); - } - else - { - $exe_mysqld= mtr_exe_exists ("$glob_basedir/libexec/mysqld", - "$glob_basedir/bin/mysqld"); - $exe_mysqlslap= mtr_exe_exists("$path_client_bindir/mysqlslap"); - } - $exe_im= mtr_exe_exists("$glob_basedir/libexec/mysqlmanager", - "$glob_basedir/bin/mysqlmanager"); - if ( $glob_use_embedded_server ) - { - $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest_embedded"); - $exe_mysql_client_test= - mtr_exe_exists("$glob_basedir/tests/mysql_client_test_embedded", - "$path_client_bindir/mysql_client_test_embedded", - "/usr/bin/false"); - } - else + mtr_warning("Could not find all required ndb binaries, " . + "all ndb tests will fail, use --skip-ndbcluster to " . + "skip testing it."); + + foreach my $cluster (@{$clusters}) { - $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest"); - $exe_mysql_client_test= - mtr_exe_exists("$path_client_bindir/mysql_client_test", - "$glob_basedir/tests/release/mysql_client_test", - "$glob_basedir/tests/debug/mysql_client_test", - "/usr/bin/false"); # FIXME temporary + $cluster->{"executable_setup_failed"}= 1; } + } - $path_ndb_tools_dir= "$glob_basedir/bin"; - $path_ndb_examples_dir= "$glob_basedir/ndbapi-examples"; - $exe_ndb_mgm= "$glob_basedir/bin/ndb_mgm"; - $exe_ndb_waiter= "$glob_basedir/bin/ndb_waiter"; - $exe_ndbd= "$glob_basedir/bin/ndbd"; - $exe_ndb_mgmd= "$glob_basedir/bin/ndb_mgmd"; + if ( ! $opt_skip_im and executable_setup_im()) + { + mtr_warning("Could not find all required instance manager binaries, " . + "all im tests will fail, use --skip-im to " . + "continue without instance manager"); + $instance_manager->{"executable_setup_failed"}= 1; } - $exe_master_mysqld= $exe_master_mysqld || $exe_mysqld; - $exe_slave_mysqld= $exe_slave_mysqld || $exe_mysqld; + # Look for the udf_example library + $lib_udf_example= + mtr_file_exists(vs_config_dirs('sql', 'udf_example.dll'), + "$glob_basedir/sql/.libs/udf_example.so",); - $file_ndb_testrun_log= "$opt_vardir/log/ndb_testrun.log"; + # Look for mysqltest executable + if ( $glob_use_embedded_server ) + { + $exe_mysqltest= + mtr_exe_exists(vs_config_dirs('libmysqld/examples', 'mysqltest_embedded'), + "$glob_basedir/libmysqld/examples/mysqltest_embedded", + "$path_client_bindir/mysqltest_embedded"); + } + else + { + $exe_mysqltest= mtr_exe_exists("$path_client_bindir/mysqltest"); + } + + # Look for mysql_client_test executable which may _not_ exist in + # some versions, test using it should be skipped + if ( $glob_use_embedded_server ) + { + $exe_mysql_client_test= + mtr_exe_maybe_exists( + vs_config_dirs('libmysqld/examples', 'mysql_client_test_embedded'), + "$glob_basedir/libmysqld/examples/mysql_client_test_embedded"); + } + else + { + $exe_mysql_client_test= + mtr_exe_maybe_exists(vs_config_dirs('tests', 'mysql_client_test'), + "$glob_basedir/tests/mysql_client_test", + "$glob_basedir/bin"); + } } @@ -1343,6 +1487,47 @@ sub generate_cmdline_mysqldump ($) { # ############################################################################## +sub mysql_client_test_arguments() +{ + my $exe= $exe_mysql_client_test; + + my $args; + mtr_init_args(\$args); + if ( $opt_valgrind_mysqltest ) + { + valgrind_arguments($args, \$exe); + } + + mtr_add_arg($args, "--no-defaults"); + mtr_add_arg($args, "--testcase"); + mtr_add_arg($args, "--user=root"); + mtr_add_arg($args, "--port=$master->[0]->{'port'}"); + mtr_add_arg($args, "--socket=$master->[0]->{'path_sock'}"); + + if ( $mysql_version_id >= 50000 ) + { + mtr_add_arg($args, "--vardir=$opt_vardir") + } + + if ( $opt_debug ) + { + mtr_add_arg($args, + "--debug=d:t:A,$path_vardir_trace/log/mysql_client_test.trace"); + } + + if ( $glob_use_embedded_server ) + { + mtr_add_arg($args, + " -A --language=$path_language"); + mtr_add_arg($args, + " -A --datadir=$slave->[0]->{'path_myddir'}"); + mtr_add_arg($args, + " -A --character-sets-dir=$path_charsetsdir"); + } + + return join(" ", $exe, @$args); +} + # Note that some env is setup in spawn/run, in "mtr_process.pl" sub environment_setup () { @@ -1368,7 +1553,7 @@ sub environment_setup () { # -------------------------------------------------------------------------- # Add the path where libndbclient can be found # -------------------------------------------------------------------------- - if ( $opt_ndbcluster_supported ) + if ( $glob_ndbcluster_supported ) { push(@ld_library_paths, "$glob_basedir/storage/ndb/src/.libs"); } @@ -1394,11 +1579,13 @@ sub environment_setup () { } $ENV{'LD_LIBRARY_PATH'}= join(":", @ld_library_paths, - split(':', $ENV{'LD_LIBRARY_PATH'})); + $ENV{'LD_LIBRARY_PATHS'} ? + split(':', $ENV{'LD_LIBRARY_PATH'}) : ()); mtr_debug("LD_LIBRARY_PATH: $ENV{'LD_LIBRARY_PATH'}"); $ENV{'DYLD_LIBRARY_PATH'}= join(":", @ld_library_paths, - split(':', $ENV{'DYLD_LIBRARY_PATH'})); + $ENV{'DYLD_LIBRARY_PATH'} ? + split(':', $ENV{'DYLD_LIBRARY_PATH'}) : ()); mtr_debug("DYLD_LIBRARY_PATH: $ENV{'DYLD_LIBRARY_PATH'}"); @@ -1422,47 +1609,67 @@ sub environment_setup () { $ENV{'SLAVE_MYPORT'}= $slave->[0]->{'port'}; $ENV{'SLAVE_MYPORT1'}= $slave->[1]->{'port'}; $ENV{'SLAVE_MYPORT2'}= $slave->[2]->{'port'}; -# $ENV{'MYSQL_TCP_PORT'}= '@MYSQL_TCP_PORT@'; # FIXME - $ENV{'MYSQL_TCP_PORT'}= 3306; + $ENV{'MYSQL_TCP_PORT'}= $mysqld_variables{'port'}; + $ENV{'IM_PATH_SOCK'}= $instance_manager->{path_sock}; + $ENV{'IM_USERNAME'}= $instance_manager->{admin_login}; + $ENV{'IM_PASSWORD'}= $instance_manager->{admin_password}; $ENV{MTR_BUILD_THREAD}= 0 unless $ENV{MTR_BUILD_THREAD}; # Set if not set + $ENV{'EXE_MYSQL'}= $exe_mysql; + + # ---------------------------------------------------- # Setup env for NDB # ---------------------------------------------------- - $ENV{'NDB_MGM'}= $exe_ndb_mgm; + if ( ! $opt_skip_ndbcluster ) + { + $ENV{'NDB_MGM'}= $exe_ndb_mgm; - $ENV{'NDBCLUSTER_PORT'}= $opt_ndbcluster_port; - $ENV{'NDBCLUSTER_PORT_SLAVE'}= $opt_ndbcluster_port_slave; + $ENV{'NDBCLUSTER_PORT'}= $opt_ndbcluster_port; + $ENV{'NDBCLUSTER_PORT_SLAVE'}= $opt_ndbcluster_port_slave; - $ENV{'NDB_EXTRA_TEST'}= $opt_ndb_extra_test; + $ENV{'NDB_EXTRA_TEST'}= $opt_ndb_extra_test; - $ENV{'NDB_BACKUP_DIR'}= $clusters->[0]->{'data_dir'}; - $ENV{'NDB_DATA_DIR'}= $clusters->[0]->{'data_dir'}; - $ENV{'NDB_TOOLS_DIR'}= $path_ndb_tools_dir; - $ENV{'NDB_TOOLS_OUTPUT'}= $file_ndb_testrun_log; - $ENV{'NDB_CONNECTSTRING'}= $opt_ndbconnectstring; + $ENV{'NDB_BACKUP_DIR'}= $clusters->[0]->{'data_dir'}; + $ENV{'NDB_DATA_DIR'}= $clusters->[0]->{'data_dir'}; + $ENV{'NDB_TOOLS_DIR'}= $path_ndb_tools_dir; + $ENV{'NDB_TOOLS_OUTPUT'}= $path_ndb_testrun_log; + $ENV{'NDB_CONNECTSTRING'}= $opt_ndbconnectstring; - $ENV{'NDB_EXAMPLES_DIR'}= $path_ndb_examples_dir; - $ENV{'MY_NDB_EXAMPLES_BINARY'}= $exe_ndb_example; - $ENV{'NDB_EXAMPLES_OUTPUT'}= $file_ndb_testrun_log; + if ( $mysql_version_id >= 50000 ) + { + $ENV{'NDB_EXAMPLES_DIR'}= $path_ndb_examples_dir; + $ENV{'MY_NDB_EXAMPLES_BINARY'}= $exe_ndb_example; + } + $ENV{'NDB_EXAMPLES_OUTPUT'}= $path_ndb_testrun_log; + } # ---------------------------------------------------- # Setup env for IM # ---------------------------------------------------- - $ENV{'IM_EXE'}= $exe_im; - $ENV{'IM_PATH_PID'}= $instance_manager->{path_pid}; - $ENV{'IM_PATH_ANGEL_PID'}= $instance_manager->{path_angel_pid}; - $ENV{'IM_PORT'}= $instance_manager->{port}; - $ENV{'IM_DEFAULTS_PATH'}= $instance_manager->{defaults_file}; - $ENV{'IM_PASSWORD_PATH'}= $instance_manager->{password_file}; - - $ENV{'IM_MYSQLD1_SOCK'}= $instance_manager->{instances}->[0]->{path_sock}; - $ENV{'IM_MYSQLD1_PORT'}= $instance_manager->{instances}->[0]->{port}; - $ENV{'IM_MYSQLD1_PATH_PID'}=$instance_manager->{instances}->[0]->{path_pid}; - $ENV{'IM_MYSQLD2_SOCK'}= $instance_manager->{instances}->[1]->{path_sock}; - $ENV{'IM_MYSQLD2_PORT'}= $instance_manager->{instances}->[1]->{port}; - $ENV{'IM_MYSQLD2_PATH_PID'}=$instance_manager->{instances}->[1]->{path_pid}; + if ( ! $opt_skip_im ) + { + $ENV{'IM_EXE'}= $exe_im; + $ENV{'IM_PATH_PID'}= $instance_manager->{path_pid}; + $ENV{'IM_PATH_ANGEL_PID'}= $instance_manager->{path_angel_pid}; + $ENV{'IM_PORT'}= $instance_manager->{port}; + $ENV{'IM_DEFAULTS_PATH'}= $instance_manager->{defaults_file}; + $ENV{'IM_PASSWORD_PATH'}= $instance_manager->{password_file}; + + $ENV{'IM_MYSQLD1_SOCK'}= + $instance_manager->{instances}->[0]->{path_sock}; + $ENV{'IM_MYSQLD1_PORT'}= + $instance_manager->{instances}->[0]->{port}; + $ENV{'IM_MYSQLD1_PATH_PID'}= + $instance_manager->{instances}->[0]->{path_pid}; + $ENV{'IM_MYSQLD2_SOCK'}= + $instance_manager->{instances}->[1]->{path_sock}; + $ENV{'IM_MYSQLD2_PORT'}= + $instance_manager->{instances}->[1]->{port}; + $ENV{'IM_MYSQLD2_PATH_PID'}= + $instance_manager->{instances}->[1]->{path_pid}; + } # ---------------------------------------------------- # Setup env so childs can execute mysqlcheck @@ -1475,7 +1682,7 @@ sub environment_setup () { if ( $opt_debug ) { $cmdline_mysqlcheck .= - " --debug=d:t:A,$opt_vardir_trace/log/mysqlcheck.trace"; + " --debug=d:t:A,$path_vardir_trace/log/mysqlcheck.trace"; } $ENV{'MYSQL_CHECK'}= $cmdline_mysqlcheck; @@ -1488,9 +1695,9 @@ sub environment_setup () { if ( $opt_debug ) { $cmdline_mysqldump .= - " --debug=d:t:A,$opt_vardir_trace/log/mysqldump-master.trace"; + " --debug=d:t:A,$path_vardir_trace/log/mysqldump-master.trace"; $cmdline_mysqldumpslave .= - " --debug=d:t:A,$opt_vardir_trace/log/mysqldump-slave.trace"; + " --debug=d:t:A,$path_vardir_trace/log/mysqldump-slave.trace"; } $ENV{'MYSQL_DUMP'}= $cmdline_mysqldump; $ENV{'MYSQL_DUMP_SLAVE'}= $cmdline_mysqldumpslave; @@ -1499,7 +1706,7 @@ sub environment_setup () { # ---------------------------------------------------- # Setup env so childs can execute mysqlslap # ---------------------------------------------------- - unless ( $glob_win32 ) + if ( $exe_mysqlslap ) { my $cmdline_mysqlslap= "$exe_mysqlslap -uroot " . @@ -1508,9 +1715,9 @@ sub environment_setup () { "--lock-directory=$opt_tmpdir"; if ( $opt_debug ) - { + { $cmdline_mysqlslap .= - " --debug=d:t:A,$opt_vardir_trace/log/mysqlslap.trace"; + " --debug=d:t:A,$path_vardir_trace/log/mysqlslap.trace"; } $ENV{'MYSQL_SLAP'}= $cmdline_mysqlslap; } @@ -1526,7 +1733,7 @@ sub environment_setup () { if ( $opt_debug ) { $cmdline_mysqlimport .= - " --debug=d:t:A,$opt_vardir_trace/log/mysqlimport.trace"; + " --debug=d:t:A,$path_vardir_trace/log/mysqlimport.trace"; } $ENV{'MYSQL_IMPORT'}= $cmdline_mysqlimport; @@ -1542,7 +1749,7 @@ sub environment_setup () { if ( $opt_debug ) { $cmdline_mysqlshow .= - " --debug=d:t:A,$opt_vardir_trace/log/mysqlshow.trace"; + " --debug=d:t:A,$path_vardir_trace/log/mysqlshow.trace"; } $ENV{'MYSQL_SHOW'}= $cmdline_mysqlshow; @@ -1551,13 +1758,16 @@ sub environment_setup () { # ---------------------------------------------------- my $cmdline_mysqlbinlog= "$exe_mysqlbinlog" . - " --no-defaults --local-load=$opt_tmpdir" . - " --character-sets-dir=$path_charsetsdir"; + " --no-defaults --local-load=$opt_tmpdir"; + if ( $mysql_version_id >= 50000 ) + { + $cmdline_mysqlbinlog .=" --character-sets-dir=$path_charsetsdir"; + } if ( $opt_debug ) { $cmdline_mysqlbinlog .= - " --debug=d:t:A,$opt_vardir_trace/log/mysqlbinlog.trace"; + " --debug=d:t:A,$path_vardir_trace/log/mysqlbinlog.trace"; } $ENV{'MYSQL_BINLOG'}= $cmdline_mysqlbinlog; @@ -1575,38 +1785,21 @@ sub environment_setup () { # ---------------------------------------------------- # Setup env so childs can execute mysql_client_test # ---------------------------------------------------- - my $cmdline_mysql_client_test= - "$exe_mysql_client_test --no-defaults --testcase --user=root --silent " . - "--port=$master->[0]->{'port'} " . - "--vardir=$opt_vardir " . - "--socket=$master->[0]->{'path_sock'}"; - - if ( $opt_debug ) - { - $cmdline_mysql_client_test .= - " --debug=d:t:A,$opt_vardir_trace/log/mysql_client_test.trace"; - } - - if ( $glob_use_embedded_server ) - { - $cmdline_mysql_client_test.= - " -A --language=$path_language" . - " -A --datadir=$slave->[0]->{'path_myddir'}" . - " -A --character-sets-dir=$path_charsetsdir"; - } - $ENV{'MYSQL_CLIENT_TEST'}= $cmdline_mysql_client_test; - + $ENV{'MYSQL_CLIENT_TEST'}= mysql_client_test_arguments(); # ---------------------------------------------------- # Setup env so childs can execute mysql_fix_system_tables # ---------------------------------------------------- - my $cmdline_mysql_fix_system_tables= - "$exe_mysql_fix_system_tables --no-defaults --host=localhost --user=root --password= " . - "--basedir=$glob_basedir --bindir=$path_client_bindir --verbose " . - "--port=$master->[0]->{'port'} " . - "--socket=$master->[0]->{'path_sock'}"; - - $ENV{'MYSQL_FIX_SYSTEM_TABLES'}= $cmdline_mysql_fix_system_tables; + if ( ! $glob_win32 ) + { + my $cmdline_mysql_fix_system_tables= + "$exe_mysql_fix_system_tables --no-defaults --host=localhost " . + "--user=root --password= " . + "--basedir=$glob_basedir --bindir=$path_client_bindir --verbose " . + "--port=$master->[0]->{'port'} " . + "--socket=$master->[0]->{'path_sock'}"; + $ENV{'MYSQL_FIX_SYSTEM_TABLES'}= $cmdline_mysql_fix_system_tables; + } # ---------------------------------------------------- # Setup env so childs can execute my_print_defaults @@ -1641,12 +1834,26 @@ sub environment_setup () { print "Using SLAVE_MYPORT = $ENV{SLAVE_MYPORT}\n"; print "Using SLAVE_MYPORT1 = $ENV{SLAVE_MYPORT1}\n"; print "Using SLAVE_MYPORT2 = $ENV{SLAVE_MYPORT2}\n"; - print "Using NDBCLUSTER_PORT = $ENV{NDBCLUSTER_PORT}\n"; - print "Using NDBCLUSTER_PORT_SLAVE = $ENV{NDBCLUSTER_PORT_SLAVE}\n"; - print "Using IM_PORT = $ENV{IM_PORT}\n"; - print "Using IM_MYSQLD1_PORT = $ENV{IM_MYSQLD1_PORT}\n"; - print "Using IM_MYSQLD2_PORT = $ENV{IM_MYSQLD2_PORT}\n"; + if ( ! $opt_skip_ndbcluster ) + { + print "Using NDBCLUSTER_PORT = $ENV{NDBCLUSTER_PORT}\n"; + if ( ! $opt_skip_ndbcluster_slave ) + { + print "Using NDBCLUSTER_PORT_SLAVE = $ENV{NDBCLUSTER_PORT_SLAVE}\n"; + } + } + if ( ! $opt_skip_im ) + { + print "Using IM_PORT = $ENV{IM_PORT}\n"; + print "Using IM_MYSQLD1_PORT = $ENV{IM_MYSQLD1_PORT}\n"; + print "Using IM_MYSQLD2_PORT = $ENV{IM_MYSQLD2_PORT}\n"; + } } + + # Create an environment variable to make it possible + # to detect that valgrind is being used from test cases + $ENV{'VALGRIND_TEST'}= $opt_valgrind; + } @@ -1676,7 +1883,7 @@ sub handle_int_signal () { # ############################################################################## -sub kill_running_server () { +sub kill_running_servers () { if ( $opt_fast or $glob_use_embedded_server ) { @@ -1694,28 +1901,55 @@ sub kill_running_server () { # started from this run of the script, this is terminating # leftovers from previous runs. + if ( ! -d $opt_vardir ) + { + if ( -l $opt_vardir and ! -d readlink($opt_vardir) ) + { + mtr_report("Removing $opt_vardir symlink without destination"); + unlink($opt_vardir); + } + # The "var" dir does not exist already + # the processes that mtr_kill_leftovers start will write + # their log files to var/log so it should be created + mkpath("$opt_vardir/log"); + } mtr_kill_leftovers(); } } sub cleanup_stale_files () { + my $created_by_mem_file= "$glob_mysql_test_dir/var/created_by_mem"; + mtr_report("Removing Stale Files"); - if ( $opt_vardir eq "$glob_mysql_test_dir/var" ) + if ( $opt_vardir eq $default_vardir ) { # # Running with "var" in mysql-test dir # - if ( -l "$glob_mysql_test_dir/var" ) + if ( -l $opt_vardir) { - # Some users creates a soft link in mysql-test/var to another area - # - allow it - mtr_report("WARNING: Using the 'mysql-test/var' symlink"); - rmtree("$opt_vardir/log"); - rmtree("$opt_vardir/ndbcluster-$opt_ndbcluster_port"); - rmtree("$opt_vardir/run"); - rmtree("$opt_vardir/tmp"); + # var is a symlink + if (-f $created_by_mem_file) + { + # Remove the directory which the link points at + rmtree(readlink($opt_vardir)); + # Remove the entire "var" dir + rmtree("$opt_vardir/"); + # Remove the "var" symlink + unlink($opt_vardir); + } + else + { + # Some users creates a soft link in mysql-test/var to another area + # - allow it + mtr_report("WARNING: Using the 'mysql-test/var' symlink"); + rmtree("$opt_vardir/log"); + rmtree("$opt_vardir/ndbcluster-$opt_ndbcluster_port"); + rmtree("$opt_vardir/run"); + rmtree("$opt_vardir/tmp"); + } } else { @@ -1731,12 +1965,23 @@ sub cleanup_stale_files () { # Remove the var/ dir in mysql-test dir if any # this could be an old symlink that shouldn't be there - rmtree("$glob_mysql_test_dir/var"); + rmtree($default_vardir); # Remove the "var" dir rmtree("$opt_vardir/"); } + if ( $opt_mem ) + { + # Runinng with var as a link to some "memory" location, normally tmpfs + rmtree($opt_mem); + mkpath($opt_mem); + mtr_report("Creating symlink from $opt_vardir to $opt_mem"); + symlink($opt_mem, $opt_vardir); + # Put a small file to recognize this dir was created by --mem + mtr_tofile($created_by_mem_file, $opt_mem); + } + mkpath("$opt_vardir/log"); mkpath("$opt_vardir/run"); mkpath("$opt_vardir/tmp"); @@ -1797,8 +2042,8 @@ sub check_running_as_root () { } - -sub check_ssl_support () { +sub check_ssl_support ($) { + my $mysqld_variables= shift; if ($opt_skip_ssl || $opt_extern) { @@ -1808,13 +2053,7 @@ sub check_ssl_support () { return; } - # check ssl support by testing using a switch - # that is only available in that case - if ( mtr_run($exe_mysqld, - ["--no-defaults", - "--ssl", - "--help"], - "", "/dev/null", "/dev/null", "") != 0 ) + if ( ! $mysqld_variables->{'ssl'} ) { if ( $opt_ssl) { @@ -1831,17 +2070,12 @@ sub check_ssl_support () { } -sub check_debug_support () { +sub check_debug_support ($) { + my $mysqld_variables= shift; - # check debug support by testing using a switch - # that is only available in that case - if ( mtr_run($exe_mysqld, - ["--no-defaults", - "--debug", - "--help"], - "", "/dev/null", "/dev/null", "") != 0 ) + if ( ! $mysqld_variables->{'debug'} ) { - # mtr_report("Binaries are not debug compiled"); + #mtr_report("Binaries are not debug compiled"); $debug_compiled_binaries= 0; if ( $opt_debug ) @@ -1856,11 +2090,37 @@ sub check_debug_support () { ############################################################################## # +# Helper function to handle configuration-based subdirectories which Visual +# Studio uses for storing binaries. If opt_vs_config is set, this returns +# a path based on that setting; if not, it returns paths for the default +# /release/ and /debug/ subdirectories. +# +# $exe can be undefined, if the directory itself will be used +# +############################################################################### + +sub vs_config_dirs ($$) { + my ($path_part, $exe) = @_; + + $exe = "" if not defined $exe; + + if ($opt_vs_config) + { + return ("$glob_basedir/$path_part/$opt_vs_config/$exe"); + } + + return ("$glob_basedir/$path_part/release/$exe", + "$glob_basedir/$path_part/debug/$exe"); +} + +############################################################################## +# # Start the ndb cluster # ############################################################################## -sub check_ndbcluster_support () { +sub check_ndbcluster_support ($) { + my $mysqld_variables= shift; if ($opt_skip_ndbcluster) { @@ -1869,21 +2129,23 @@ sub check_ndbcluster_support () { return; } - # check ndbcluster support by runnning mysqld using a switch - # that is only available in that case - if ( mtr_run($exe_mysqld, - ["--no-defaults", - "--ndb-use-exact-count", - "--help"], - "", "/dev/null", "/dev/null", "") != 0 ) + if ( ! $mysqld_variables->{'ndb-connectstring'} ) { mtr_report("Skipping ndbcluster, mysqld not compiled with ndbcluster"); $opt_skip_ndbcluster= 1; $opt_skip_ndbcluster_slave= 1; return; } - $opt_ndbcluster_supported= 1; + $glob_ndbcluster_supported= 1; mtr_report("Using ndbcluster when necessary, mysqld supports it"); + + if ( $mysql_version_id < 50100 ) + { + # Slave cluster is not supported until 5.1 + $opt_skip_ndbcluster_slave= 1; + + } + return; } @@ -1891,11 +2153,6 @@ sub check_ndbcluster_support () { sub ndbcluster_start_install ($) { my $cluster= shift; - if ( $opt_skip_ndbcluster or $glob_use_running_ndbcluster ) - { - return 0; - } - mtr_report("Installing $cluster->{'name'} Cluster"); mkdir($cluster->{'data_dir'}); @@ -1914,11 +2171,22 @@ sub ndbcluster_start_install ($) { if (!$opt_bench) { # Use a smaller configuration - $ndb_no_ord=32; - $ndb_con_op=5000; - $ndb_dmem="20M"; - $ndb_imem="1M"; - $ndb_pbmem="4M"; + if ( $mysql_version_id < 50100 ) + { + # 4.1 and 5.0 is using a "larger" --small configuration + $ndb_no_ord=128; + $ndb_con_op=10000; + $ndb_dmem="40M"; + $ndb_imem="12M"; + } + else + { + $ndb_no_ord=32; + $ndb_con_op=5000; + $ndb_dmem="20M"; + $ndb_imem="1M"; + $ndb_pbmem="4M"; + } } my $config_file_template= "ndb/ndb_config_${nodes}_node.ini"; @@ -1941,6 +2209,11 @@ sub ndbcluster_start_install ($) { s/CHOOSE_HOSTNAME_.*/$ndb_host/; s/CHOOSE_FILESYSTEM/$cluster->{'data_dir'}/; s/CHOOSE_PORT_MGM/$cluster->{'port'}/; + if ( $mysql_version_id < 50000 ) + { + my $base_port= $cluster->{'port'} + 1; + s/CHOOSE_PORT_TRANSPORTER/$base_port/; + } s/CHOOSE_DiskPageBufferMemory/$ndb_pbmem/; print OUT "$_ \n"; @@ -2062,7 +2335,10 @@ sub ndbd_start ($$$) { mtr_add_arg($args, "--no-defaults"); mtr_add_arg($args, "--core"); mtr_add_arg($args, "--ndb-connectstring=%s", "$cluster->{'connect_string'}"); - mtr_add_arg($args, "--character-sets-dir=%s", "$path_charsetsdir"); + if ( $mysql_version_id >= 50000) + { + mtr_add_arg($args, "--character-sets-dir=%s", "$path_charsetsdir"); + } mtr_add_arg($args, "--nodaemon"); mtr_add_arg($args, "$extra_args"); @@ -2163,8 +2439,6 @@ sub run_benchmarks ($) { chdir($glob_mysql_bench_dir) or mtr_error("Couldn't chdir to '$glob_mysql_bench_dir': $!"); - # FIXME write shorter.... - if ( ! $benchmark ) { mtr_add_arg($args, "--log"); @@ -2196,9 +2470,6 @@ sub run_benchmarks ($) { # ############################################################################## -# FIXME how to specify several suites to run? Comma separated list? - - sub run_suite () { my ($suite, $tests)= @_; @@ -2255,11 +2526,14 @@ sub run_suite () { ############################################################################## sub initialize_servers () { + + datadir_setup(); + if ( ! $glob_use_running_server ) { - kill_running_server(); + kill_running_servers(); - unless ( $opt_start_dirty ) + if ( ! $opt_start_dirty ) { cleanup_stale_files(); mysql_install_db(); @@ -2292,10 +2566,26 @@ sub mysql_install_db () { my $cluster_started_ok= 1; # Assume it can be started - if (ndbcluster_start_install($clusters->[0]) || - $max_slave_num && ndbcluster_start_install($clusters->[1])) + if ($opt_skip_ndbcluster || $glob_use_running_ndbcluster || + $clusters->[0]->{executable_setup_failed}) + { + # Don't install master cluster + } + elsif (ndbcluster_start_install($clusters->[0])) + { + mtr_warning("Failed to start install of $clusters->[0]->{name}"); + $cluster_started_ok= 0; + } + + if ($max_slave_num == 0 || + $opt_skip_ndbcluster_slave || $glob_use_running_ndbcluster_slave || + $clusters->[1]->{executable_setup_failed}) + { + # Don't install slave cluster + } + elsif (ndbcluster_start_install($clusters->[1])) { - mtr_warning("Failed to start install of cluster"); + mtr_warning("Failed to start install of $clusters->[1]->{name}"); $cluster_started_ok= 0; } @@ -2328,9 +2618,6 @@ sub mysql_install_db () { } } - # Stop clusters... - stop_all_servers(); - return 0; } @@ -2392,14 +2679,15 @@ sub install_db ($$) { mtr_add_arg($args, "--skip-innodb"); mtr_add_arg($args, "--skip-ndbcluster"); mtr_add_arg($args, "--tmpdir=."); + mtr_add_arg($args, "--core-file"); if ( $opt_debug ) { mtr_add_arg($args, "--debug=d:t:i:A,%s/log/bootstrap_%s.trace", - $opt_vardir_trace, $type); + $path_vardir_trace, $type); } - if ( ! $opt_netware ) + if ( ! $glob_netware ) { mtr_add_arg($args, "--language=%s", $path_language); mtr_add_arg($args, "--character-sets-dir=%s", $path_charsetsdir); @@ -2492,9 +2780,15 @@ skip-innodb skip-ndbcluster EOF ; - + if ( $mysql_version_id < 50100 ) + { + print OUT "skip-bdb\n"; + } print OUT "nonguarded\n" if $instance->{'nonguarded'}; - print OUT "log-output=FILE\n" if $instance->{'old_log_format'}; + if ( $mysql_version_id >= 50100 ) + { + print OUT "log-output=FILE\n" if $instance->{'old_log_format'}; + } print OUT "\n"; } @@ -2553,21 +2847,47 @@ sub run_testcase_check_skip_test($) return 1; } - # If test needs cluster, check that master installed ok - if ( $tinfo->{'ndb_test'} and !$clusters->[0]->{'installed_ok'} ) + if ($tinfo->{'ndb_test'}) { - mtr_report_test_name($tinfo); - mtr_report_test_failed($tinfo); - return 1; + foreach my $cluster (@{$clusters}) + { + last if ($opt_skip_ndbcluster_slave and + $cluster->{'name'} eq 'Slave'); + + # If test needs this cluster, check binaries was found ok + if ( $cluster->{'executable_setup_failed'} ) + { + mtr_report_test_name($tinfo); + $tinfo->{comment}= + "Failed to find cluster binaries"; + mtr_report_test_failed($tinfo); + return 1; + } + + # If test needs this cluster, check it was installed ok + if ( !$cluster->{'installed_ok'} ) + { + mtr_report_test_name($tinfo); + $tinfo->{comment}= + "Cluster $cluster->{'name'} was not installed ok"; + mtr_report_test_failed($tinfo); + return 1; + } + + } } - # If test needs slave cluster, check that it installed ok - if ( $tinfo->{'ndb_test'} and $tinfo->{'slave_num'} and - !$clusters->[1]->{'installed_ok'} ) + if ( $tinfo->{'component_id'} eq 'im' ) { - mtr_report_test_name($tinfo); - mtr_report_test_failed($tinfo); - return 1; + # If test needs im, check binaries was found ok + if ( $instance_manager->{'executable_setup_failed'} ) + { + mtr_report_test_name($tinfo); + $tinfo->{comment}= + "Failed to find MySQL manager binaries"; + mtr_report_test_failed($tinfo); + return 1; + } } return 0; @@ -2579,28 +2899,40 @@ sub do_before_run_mysqltest($) my $tinfo= shift; my $tname= $tinfo->{'name'}; - # Remove old reject file - if ( $opt_suite eq "main" ) + # Remove old files produced by mysqltest + my $result_dir= "r"; + if ( $opt_suite ne "main" ) { - unlink("r/$tname.reject"); + $result_dir= "suite/$opt_suite/r"; } - else - { - unlink("suite/$opt_suite/r/$tname.reject"); - } - + unlink("$result_dir/$tname.reject"); + unlink("$result_dir/$tname.progress"); + unlink("$result_dir/$tname.log"); + unlink("$result_dir/$tname.warnings"); -# MASV cleanup... mtr_tonewfile($path_current_test_log,"$tname\n"); # Always tell where we are # output current test to ndbcluster log file to enable diagnostics - mtr_tofile($file_ndb_testrun_log,"CURRENT TEST $tname\n"); + mtr_tofile($path_ndb_testrun_log,"CURRENT TEST $tname\n"); mtr_tofile($master->[0]->{'path_myerr'},"CURRENT_TEST: $tname\n"); if ( $master->[1]->{'pid'} ) { mtr_tofile($master->[1]->{'path_myerr'},"CURRENT_TEST: $tname\n"); } + + if ( $mysql_version_id < 50000 ) + { + # Set envirnoment variable NDB_STATUS_OK to 1 + # if script decided to run mysqltest cluster _is_ installed ok + $ENV{'NDB_STATUS_OK'} = "1"; + } + elsif ( $mysql_version_id < 50100 ) + { + # Set envirnoment variable NDB_STATUS_OK to YES + # if script decided to run mysqltest cluster _is_ installed ok + $ENV{'NDB_STATUS_OK'} = "YES"; + } } sub do_after_run_mysqltest($) @@ -2608,14 +2940,95 @@ sub do_after_run_mysqltest($) my $tinfo= shift; my $tname= $tinfo->{'name'}; - #MASV cleanup - # Save info from this testcase run to mysqltest.log - my $testcase_log= mtr_fromfile($path_timefile) if -f $path_timefile; - mtr_tofile($path_mysqltest_log,"CURRENT TEST $tname\n"); - mtr_tofile($path_mysqltest_log, $testcase_log); + mtr_tofile($path_mysqltest_log,"CURRENT TEST $tname\n"); + + # Save info from this testcase run to mysqltest.log + mtr_appendfile_to_file($path_timefile, $path_mysqltest_log) + if -f $path_timefile; + + # Remove the file that mysqltest writes info to + unlink($path_timefile); + +} + + +sub find_testcase_skipped_reason($) +{ + my ($tinfo)= @_; + + # Open mysqltest.log + my $F= IO::File->new($path_timefile) or + mtr_error("can't open file \"$path_timefile\": $!"); + my $reason; + + while ( my $line= <$F> ) + { + # Look for "reason: <reason fo skiping test>" + if ( $line =~ /reason: (.*)/ ) + { + $reason= $1; + } + } + + if ( ! $reason ) + { + mtr_warning("Could not find reason for skipping test in $path_timefile"); + $reason= "Detected by testcase(reason unknown) "; } + $tinfo->{'comment'}= $reason; +} +sub analyze_testcase_failure_sync_with_master($) +{ + my ($tinfo)= @_; + + my $args; + mtr_init_args(\$args); + + mtr_add_arg($args, "--no-defaults"); + mtr_add_arg($args, "--silent"); + mtr_add_arg($args, "-v"); + mtr_add_arg($args, "--skip-safemalloc"); + mtr_add_arg($args, "--tmpdir=%s", $opt_tmpdir); + + mtr_add_arg($args, "--socket=%s", $master->[0]->{'path_sock'}); + mtr_add_arg($args, "--port=%d", $master->[0]->{'port'}); + mtr_add_arg($args, "--database=test"); + mtr_add_arg($args, "--user=%s", $opt_user); + mtr_add_arg($args, "--password="); + + # Run the test file and append output to log file + mtr_run_test($exe_mysqltest,$args, + "include/analyze_failure_sync_with_master.test", + "$path_timefile", "$path_timefile","", + { append_log_file => 1 }); + +} + +sub analyze_testcase_failure($) +{ + my ($tinfo)= @_; + + # Open mysqltest.log + my $F= IO::File->new($path_timefile) or + mtr_error("can't open file \"$path_timefile\": $!"); + + while ( my $line= <$F> ) + { + # Look for "mysqltest: At line nnn: <error> + if ( $line =~ /mysqltest: At line [0-9]*: (.*)/ ) + { + my $error= $1; + # Look for "could not sync with master" + if ( $error =~ /could not sync with master/ ) + { + analyze_testcase_failure_sync_with_master($tinfo); + } + } + } +} + ############################################################################## # # Run a single test case @@ -2635,17 +3048,38 @@ sub do_after_run_mysqltest($) sub run_testcase ($) { my $tinfo= shift; + # ------------------------------------------------------- + # Init variables that can change between each test case + # ------------------------------------------------------- + + $ENV{'TZ'}= $tinfo->{'timezone'}; + mtr_verbose("Starting server with timezone: $tinfo->{'timezone'}"); + my $master_restart= run_testcase_need_master_restart($tinfo); my $slave_restart= run_testcase_need_slave_restart($tinfo); if ($master_restart or $slave_restart) { + # Can't restart a running server that may be in use + if ( $glob_use_running_server ) + { + mtr_report_test_name($tinfo); + $tinfo->{comment}= "Can't restart a running server"; + mtr_report_test_skipped($tinfo); + return; + } + run_testcase_stop_servers($tinfo, $master_restart, $slave_restart); } my $died= mtr_record_dead_children(); if ($died or $master_restart or $slave_restart) { - run_testcase_start_servers($tinfo); + if (run_testcase_start_servers($tinfo)) + { + mtr_report_test_name($tinfo); + report_failure_and_restart($tinfo); + return 1; + } } # ---------------------------------------------------------------------- @@ -2654,6 +3088,7 @@ sub run_testcase ($) { # ---------------------------------------------------------------------- if ( $opt_start_and_exit or $opt_start_dirty ) { + mtr_timer_stop_all($glob_timers); mtr_report("\nServers started, exiting"); exit(0); } @@ -2672,10 +3107,7 @@ sub run_testcase ($) { # Testcase itself tell us to skip this one # Try to get reason from mysqltest.log - my $last_line= mtr_lastlinefromfile($path_timefile) if -f $path_timefile; - my $reason= mtr_match_prefix($last_line, "reason: "); - $tinfo->{'comment'}= - defined $reason ? $reason : "Detected by testcase(reason unknown) "; + find_testcase_skipped_reason($tinfo); mtr_report_test_skipped($tinfo); } elsif ( $res == 63 ) @@ -2683,16 +3115,20 @@ sub run_testcase ($) { $tinfo->{'timeout'}= 1; # Mark as timeout report_failure_and_restart($tinfo); } - else + elsif ( $res == 1 ) { - # Test case failed, if in control mysqltest returns 1 - if ( $res != 1 ) + if ( $opt_force ) { - mtr_tofile($path_timefile, - "mysqltest returned unexpected code $res, " . - "it has probably crashed"); + analyze_testcase_failure($tinfo); } - + # Test case failure reported by mysqltest + report_failure_and_restart($tinfo); + } + else + { + # mysqltest failed, probably crashed + $tinfo->{comment}= + "mysqltest returned unexpected code $res, it has probably crashed"; report_failure_and_restart($tinfo); } @@ -2702,13 +3138,10 @@ sub run_testcase ($) { # ---------------------------------------------------------------------- # Stop Instance Manager if we are processing an IM-test case. # ---------------------------------------------------------------------- - - if ( ! $glob_use_running_server and $tinfo->{'component_id'} eq 'im' ) + if ( $tinfo->{'component_id'} eq 'im' and + !mtr_im_stop($instance_manager, $tinfo->{'name'}) ) { - unless ( mtr_im_stop($instance_manager, $tinfo->{'name'}) ) - { - mtr_error("Failed to stop Instance Manager.") - } + mtr_error("Failed to stop Instance Manager.") } } @@ -2824,24 +3257,17 @@ sub report_failure_and_restart ($) { ############################################################################## -# The embedded server needs the cleanup so we do some of the start work -# but stop before actually running mysqld or anything. -sub do_before_start_master ($$) { - my $tname= shift; - my $init_script= shift; +sub do_before_start_master ($) { + my ($tinfo)= @_; + + my $tname= $tinfo->{'name'}; + my $init_script= $tinfo->{'master_sh'}; # FIXME what about second master..... - # Remove stale binary logs except for 2 tests which need them FIXME here???? - if ( $tname ne "rpl_crash_binlog_ib_1b" and - $tname ne "rpl_crash_binlog_ib_2b" and - $tname ne "rpl_crash_binlog_ib_3b") + foreach my $bin ( glob("$opt_vardir/log/master*-bin*") ) { - # FIXME we really want separate dir for binlogs - foreach my $bin ( glob("$opt_vardir/log/master*-bin*") ) - { - unlink($bin); - } + unlink($bin); } # FIXME only remove the ones that are tied to this master @@ -2861,31 +3287,23 @@ sub do_before_start_master ($$) { # mtr_warning("$init_script exited with code $ret"); } } - # for gcov FIXME needed? If so we need more absolute paths - # chdir($glob_basedir); } -sub do_before_start_slave ($$) { - my $tname= shift; - my $init_script= shift; +sub do_before_start_slave ($) { + my ($tinfo)= @_; + + my $tname= $tinfo->{'name'}; + my $init_script= $tinfo->{'master_sh'}; - # Remove stale binary logs and old master.info files - # except for too tests which need them - if ( $tname ne "rpl_crash_binlog_ib_1b" and - $tname ne "rpl_crash_binlog_ib_2b" and - $tname ne "rpl_crash_binlog_ib_3b" ) + foreach my $bin ( glob("$opt_vardir/log/slave*-bin*") ) { - # FIXME we really want separate dir for binlogs - foreach my $bin ( glob("$opt_vardir/log/slave*-bin*") ) - { - unlink($bin); - } - # FIXME really master?! - unlink("$slave->[0]->{'path_myddir'}/master.info"); - unlink("$slave->[0]->{'path_myddir'}/relay-log.info"); + unlink($bin); } + unlink("$slave->[0]->{'path_myddir'}/master.info"); + unlink("$slave->[0]->{'path_myddir'}/relay-log.info"); + # Run slave initialization shell script if one exists if ( $init_script ) { @@ -2924,14 +3342,18 @@ sub mysqld_arguments ($$$$$) { $prefix= "--server-arg="; } else { # We can't pass embedded server --no-defaults - mtr_add_arg($args, "%s--no-defaults", $prefix); + mtr_add_arg($args, "--no-defaults"); } mtr_add_arg($args, "%s--console", $prefix); mtr_add_arg($args, "%s--basedir=%s", $prefix, $path_my_basedir); mtr_add_arg($args, "%s--character-sets-dir=%s", $prefix, $path_charsetsdir); - mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix); + if ( $mysql_version_id >= 50000 ) + { + mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix); + } + mtr_add_arg($args, "%s--default-character-set=latin1", $prefix); mtr_add_arg($args, "%s--language=%s", $prefix, $path_language); mtr_add_arg($args, "%s--tmpdir=$opt_tmpdir", $prefix); @@ -2980,7 +3402,10 @@ sub mysqld_arguments ($$$$$) { mtr_add_arg($args, "%s--ndbcluster", $prefix); mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix, $cluster->{'connect_string'}); - mtr_add_arg($args, "%s--ndb-extra-logging", $prefix); + if ( $mysql_version_id >= 50100 ) + { + mtr_add_arg($args, "%s--ndb-extra-logging", $prefix); + } } } @@ -2998,7 +3423,7 @@ sub mysqld_arguments ($$$$$) { $opt_vardir, $sidx); # FIXME use own dir for binlogs mtr_add_arg($args, "%s--log-slave-updates", $prefix); } - # FIXME option duplicated for slave + mtr_add_arg($args, "%s--log=%s", $prefix, $slave->[$idx]->{'path_mylog'}); mtr_add_arg($args, "%s--master-retry-count=10", $prefix); @@ -3019,8 +3444,9 @@ sub mysqld_arguments ($$$$$) { # Directory where slaves find the dumps generated by "load data" # on the server. The path need to have constant length otherwise # test results will vary, thus a relative path is used. + my $slave_load_path= "../tmp"; mtr_add_arg($args, "%s--slave-load-tmpdir=%s", $prefix, - "../tmp"); + $slave_load_path); mtr_add_arg($args, "%s--socket=%s", $prefix, $slave->[$idx]->{'path_sock'}); mtr_add_arg($args, "%s--set-variable=slave_net_timeout=10", $prefix); @@ -3055,7 +3481,10 @@ sub mysqld_arguments ($$$$$) { mtr_add_arg($args, "%s--ndbcluster", $prefix); mtr_add_arg($args, "%s--ndb-connectstring=%s", $prefix, $clusters->[$slave->[$idx]->{'cluster'}]->{'connect_string'}); - mtr_add_arg($args, "%s--ndb-extra-logging", $prefix); + if ( $mysql_version_id >= 50100 ) + { + mtr_add_arg($args, "%s--ndb-extra-logging", $prefix); + } } } # end slave @@ -3064,12 +3493,12 @@ sub mysqld_arguments ($$$$$) { if ( $type eq 'master' ) { mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/master%s.trace", - $prefix, $opt_vardir_trace, $sidx); + $prefix, $path_vardir_trace, $sidx); } if ( $type eq 'slave' ) { mtr_add_arg($args, "%s--debug=d:t:i:A,%s/log/slave%s.trace", - $prefix, $opt_vardir_trace, $sidx); + $prefix, $path_vardir_trace, $sidx); } } @@ -3077,7 +3506,6 @@ sub mysqld_arguments ($$$$$) { mtr_add_arg($args, "%s--key_buffer_size=1M", $prefix); mtr_add_arg($args, "%s--sort_buffer=256K", $prefix); mtr_add_arg($args, "%s--max_heap_table_size=1M", $prefix); - mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix); if ( $opt_ssl_supported ) { @@ -3160,6 +3588,9 @@ sub mysqld_start ($$$) { my $type= $mysqld->{'type'}; my $idx= $mysqld->{'idx'}; + mtr_error("Internal error: mysqld should never be started for embedded") + if $glob_use_embedded_server; + if ( $type eq 'master' ) { $exe= $exe_master_mysqld; @@ -3211,15 +3642,6 @@ sub mysqld_start ($$$) { $wait_for_pid_file= 0; } - if ($exe_libtool and $opt_valgrind) - { - # Add "libtool --mode-execute" - # if running in valgrind(to avoid valgrinding bash) - unshift(@$args, "--mode=execute", $exe); - $exe= $exe_libtool; - } - - if ( defined $exe ) { $pid= mtr_spawn($exe, $args, "", @@ -3255,10 +3677,13 @@ sub stop_all_servers () { print "Stopping All Servers\n"; - print "Shutting-down Instance Manager\n"; - unless (mtr_im_stop($instance_manager, "stop_all_servers")) + if ( ! $opt_skip_im ) { - mtr_error("Failed to stop Instance Manager.") + print "Shutting-down Instance Manager\n"; + unless (mtr_im_stop($instance_manager, "stop_all_servers")) + { + mtr_error("Failed to stop Instance Manager.") + } } my %admin_pids; # hash of admin processes that requests shutdown @@ -3333,46 +3758,46 @@ sub run_testcase_need_master_restart($) # We try to find out if we are to restart the master(s) my $do_restart= 0; # Assumes we don't have to - if ( $tinfo->{'master_sh'} ) + if ( $glob_use_embedded_server ) + { + mtr_verbose("Never start or restart for embedded server"); + return $do_restart; + } + elsif ( $tinfo->{'master_sh'} ) { $do_restart= 1; # Always restart if script to run - mtr_verbose("Restart because: Always restart if script to run"); + mtr_verbose("Restart master: Always restart if script to run"); + } + if ( $tinfo->{'force_restart'} ) + { + $do_restart= 1; # Always restart if --force-restart in -opt file + mtr_verbose("Restart master: Restart forced with --force-restart"); } elsif ( ! $opt_skip_ndbcluster and - $tinfo->{'ndb_test'} == 0 and + !$tinfo->{'ndb_test'} and $clusters->[0]->{'pid'} != 0 ) { $do_restart= 1; # Restart without cluster - mtr_verbose("Restart because: Test does not need cluster"); + mtr_verbose("Restart master: Test does not need cluster"); } elsif ( ! $opt_skip_ndbcluster and - $tinfo->{'ndb_test'} == 1 and + $tinfo->{'ndb_test'} and $clusters->[0]->{'pid'} == 0 ) { $do_restart= 1; # Restart with cluster - mtr_verbose("Restart because: Test need cluster"); - } - elsif ( $master->[0]->{'running_master_is_special'} and - $master->[0]->{'running_master_is_special'}->{'timezone'} eq - $tinfo->{'timezone'} and - mtr_same_opts($master->[0]->{'running_master_is_special'}->{'master_opt'}, - $tinfo->{'master_opt'}) ) - { - # If running master was started with special settings, but - # the current test requires the same ones, we *don't* restart. - $do_restart= 0; - mtr_verbose("Skip restart: options are equal " . - join(" ", @{$tinfo->{'master_opt'}})); + mtr_verbose("Restart master: Test need cluster"); } - elsif ( $tinfo->{'master_restart'} ) + elsif( $tinfo->{'component_id'} eq 'im' ) { $do_restart= 1; - mtr_verbose("Restart because: master_restart"); + mtr_verbose("Restart master: Always restart for im tests"); } - elsif ( $master->[0]->{'running_master_is_special'} ) + elsif ( $master->[0]->{'running_master_options'} and + $master->[0]->{'running_master_options'}->{'timezone'} ne + $tinfo->{'timezone'}) { $do_restart= 1; - mtr_verbose("Restart because: running_master_is_special"); + mtr_verbose("Restart master: Different timezone"); } # Check that running master was started with same options # as the current test requires @@ -3380,10 +3805,15 @@ sub run_testcase_need_master_restart($) $tinfo->{'master_opt'}) ) { $do_restart= 1; - mtr_verbose("Restart because: running with different options '" . + mtr_verbose("Restart master: running with different options '" . join(" ", @{$tinfo->{'master_opt'}}) . "' != '" . join(" ", @{$master->[0]->{'start_opts'}}) . "'" ); } + elsif( ! $master->[0]->{'pid'} ) + { + $do_restart= 1; + mtr_verbose("Restart master: master is not started"); + } return $do_restart; } @@ -3395,57 +3825,40 @@ sub run_testcase_need_slave_restart($) # We try to find out if we are to restart the slaves my $do_slave_restart= 0; # Assumes we don't have to - # FIXME only restart slave when necessary - $do_slave_restart= 1; - -# if ( ! $slave->[0]->{'pid'} ) -# { -# # mtr_verbose("Slave not started, no need to check slave restart"); -# } -# elsif ( $do_restart ) -# { -# $do_slave_restart= 1; # Always restart if master restart -# mtr_verbose("Restart slave because: Master restart"); -# } -# elsif ( $tinfo->{'slave_sh'} ) -# { -# $do_slave_restart= 1; # Always restart if script to run -# mtr_verbose("Restart slave because: Always restart if script to run"); -# } -# elsif ( ! $opt_skip_ndbcluster_slave and -# $tinfo->{'ndb_test'} == 0 and -# $clusters->[1]->{'pid'} != 0 ) -# { -# $do_slave_restart= 1; # Restart without slave cluster -# mtr_verbose("Restart slave because: Test does not need slave cluster"); -# } -# elsif ( ! $opt_with_ndbcluster_slave and -# $tinfo->{'ndb_test'} == 1 and -# $clusters->[1]->{'pid'} == 0 ) -# { -# $do_slave_restart= 1; # Restart with slave cluster -# mtr_verbose("Restart slave because: Test need slave cluster"); -# } -# elsif ( $tinfo->{'slave_restart'} ) -# { -# $do_slave_restart= 1; -# mtr_verbose("Restart slave because: slave_restart"); -# } -# elsif ( $slave->[0]->{'running_slave_is_special'} ) -# { -# $do_slave_restart= 1; -# mtr_verbose("Restart slave because: running_slave_is_special"); -# } -# # Check that running slave was started with same options -# # as the current test requires -# elsif (! mtr_same_opts($slave->[0]->{'start_opts'}, -# $tinfo->{'slave_opt'}) ) -# { -# $do_slave_restart= 1; -# mtr_verbose("Restart slave because: running with different options '" . -# join(" ", @{$tinfo->{'slave_opt'}}) . "' != '" . -# join(" ", @{$slave->[0]->{'start_opts'}}) . "'" ); -# } + if ( $glob_use_embedded_server ) + { + mtr_verbose("Never start or restart for embedded server"); + return $do_slave_restart; + } + elsif ( $max_slave_num == 0) + { + mtr_verbose("Skip slave restart: No testcase use slaves"); + } + else + { + + # Check if any slave is currently started + my $any_slave_started= 0; + foreach my $mysqld (@{$slave}) + { + if ( $mysqld->{'pid'} ) + { + $any_slave_started= 1; + last; + } + } + + if ($any_slave_started) + { + mtr_verbose("Restart slave: Slave is started, always restart"); + $do_slave_restart= 1; + } + elsif ( $tinfo->{'slave_num'} ) + { + mtr_verbose("Restart slave: Test need slave"); + $do_slave_restart= 1; + } + } return $do_slave_restart; @@ -3464,22 +3877,16 @@ sub run_testcase_need_slave_restart($) sub run_testcase_stop_servers($$$) { my ($tinfo, $do_restart, $do_slave_restart)= @_; - - if ( $glob_use_running_server || $glob_use_embedded_server ) - { - return; - } - my $pid; my %admin_pids; # hash of admin processes that requests shutdown my @kill_pids; # list of processes to shutdown/kill - # Remember if we restarted for this test case + # Remember if we restarted for this test case (count restarts) $tinfo->{'restarted'}= $do_restart; if ( $do_restart ) { - delete $master->[0]->{'running_master_is_special'}; # Forget history + delete $master->[0]->{'running_master_options'}; # Forget history # Start shutdown of all started masters foreach my $mysqld (@{$master}) @@ -3529,7 +3936,7 @@ sub run_testcase_stop_servers($$$) { if ( $do_restart || $do_slave_restart ) { - delete $slave->[0]->{'running_slave_is_special'}; # Forget history + delete $slave->[0]->{'running_slave_options'}; # Forget history # Start shutdown of all started slaves foreach my $mysqld (@{$slave}) @@ -3600,16 +4007,21 @@ sub run_testcase_stop_servers($$$) { } } + +# +# run_testcase_start_servers +# +# Start the servers needed by this test case +# +# RETURN +# 0 OK +# 1 Start failed +# + sub run_testcase_start_servers($) { my $tinfo= shift; - my $tname= $tinfo->{'name'}; - if ( $glob_use_running_server or $glob_use_embedded_server ) - { - return; - } - if ( $tinfo->{'component_id'} eq 'mysqld' ) { if ( ! $opt_skip_ndbcluster and @@ -3623,7 +4035,7 @@ sub run_testcase_start_servers($) { if ( !$master->[0]->{'pid'} ) { # Master mysqld is not started - do_before_start_master($tname,$tinfo->{'master_sh'}); + do_before_start_master($tinfo); mysqld_start($master->[0],$tinfo->{'master_opt'},[]); @@ -3633,27 +4045,28 @@ sub run_testcase_start_servers($) { { # Test needs cluster, start an extra mysqld connected to cluster - # First wait for first mysql server to have created ndb system tables ok - # FIXME This is a workaround so that only one mysqld creates the tables - if ( ! sleep_until_file_created( - "$master->[0]->{'path_myddir'}/cluster/apply_status.ndb", - $master->[0]->{'start_timeout'}, - $master->[0]->{'pid'})) + if ( $mysql_version_id >= 50100 ) { - mtr_report("Failed to create 'cluster/apply_status' table"); - report_failure_and_restart($tinfo); - return; + # First wait for first mysql server to have created ndb system + # tables ok FIXME This is a workaround so that only one mysqld + # create the tables + if ( ! sleep_until_file_created( + "$master->[0]->{'path_myddir'}/cluster/apply_status.ndb", + $master->[0]->{'start_timeout'}, + $master->[0]->{'pid'})) + { + + $tinfo->{'comment'}= "Failed to create 'cluster/apply_status' table"; + return 1; + } } mtr_tofile($master->[1]->{'path_myerr'},"CURRENT_TEST: $tname\n"); mysqld_start($master->[1],$tinfo->{'master_opt'},[]); } - if ( $tinfo->{'master_restart'} ) - { - # Save this test case information, so next can examine it - $master->[0]->{'running_master_is_special'}= $tinfo; - } + # Save this test case information, so next can examine it + $master->[0]->{'running_master_options'}= $tinfo; } elsif ( ! $opt_skip_im and $tinfo->{'component_id'} eq 'im' ) { @@ -3664,12 +4077,10 @@ sub run_testcase_start_servers($) { im_create_defaults_file($instance_manager); - unless ( mtr_im_start($instance_manager, $tinfo->{im_opts}) ) + if ( ! mtr_im_start($instance_manager, $tinfo->{im_opts}) ) { - report_failure_and_restart($tinfo); - mtr_report("Failed to start Instance Manager. " . - "The test '$tname' is marked as failed."); - return; + $tinfo->{'comment'}= "Failed to start Instance Manager. "; + return 1; } } @@ -3682,7 +4093,7 @@ sub run_testcase_start_servers($) { restore_slave_databases($tinfo->{'slave_num'}); - do_before_start_slave($tname,$tinfo->{'slave_sh'}); + do_before_start_slave($tinfo); if ( ! $opt_skip_ndbcluster_slave and !$clusters->[1]->{'pid'} and @@ -3702,12 +4113,8 @@ sub run_testcase_start_servers($) { } } - if ( $tinfo->{'slave_restart'} ) - { - # Save this test case information, so next can examine it - $slave->[0]->{'running_slave_is_special'}= $tinfo; - } - + # Save this test case information, so next can examine it + $slave->[0]->{'running_slave_options'}= $tinfo; } # Wait for clusters to start @@ -3719,7 +4126,8 @@ sub run_testcase_start_servers($) { if (ndbcluster_wait_started($cluster, "")) { # failed to start - mtr_report("Start of $cluster->{'name'} cluster failed, "); + $tinfo->{'comment'}= "Start of $cluster->{'name'} cluster failed"; + return 1; } } @@ -3731,9 +4139,13 @@ sub run_testcase_start_servers($) { if (mysqld_wait_started($mysqld)) { - mtr_warning("Failed to start $mysqld->{'type'} mysqld $mysqld->{'idx'}"); + # failed to start + $tinfo->{'comment'}= + "Failed to start $mysqld->{'type'} mysqld $mysqld->{'idx'}"; + return 1; } } + return 0; } # @@ -3741,6 +4153,10 @@ sub run_testcase_start_servers($) { # Before a testcase, run in record mode, save result file to var # After testcase, run and compare with the recorded file, they should be equal! # +# RETURN VALUE +# 0 OK +# 1 Check failed +# sub run_check_testcase ($$) { my $mode= shift; @@ -3774,7 +4190,7 @@ sub run_check_testcase ($$) { my $res = mtr_run_test($exe_mysqltest,$args, "include/check-testcase.test", "", "", ""); - if ( $res == 1 and $mode = "after") + if ( $res == 1 and $mode eq "after") { mtr_run("diff",["-u", "$opt_vardir/tmp/$name.result", @@ -3785,6 +4201,7 @@ sub run_check_testcase ($$) { { mtr_error("Could not execute 'check-testcase' $mode testcase"); } + return $res; } @@ -3856,11 +4273,6 @@ sub run_mysqltest ($) { mtr_add_arg($args, "--big-test"); } - if ( $opt_valgrind ) - { - mtr_add_arg($args, "--valgrind"); - } - if ( $opt_compress ) { mtr_add_arg($args, "--compress"); @@ -3874,7 +4286,7 @@ sub run_mysqltest ($) { if ( $opt_debug ) { mtr_add_arg($args, "--debug=d:t:A,%s/log/mysqltest.trace", - $opt_vardir_trace); + $path_vardir_trace); } if ( $opt_ssl_supported ) @@ -3952,14 +4364,6 @@ sub run_mysqltest ($) { debugger_arguments(\$args, \$exe, "client"); } - if ($exe_libtool and $opt_valgrind) - { - # Add "libtool --mode-execute" before the test to execute - # if running in valgrind(to avoid valgrinding bash) - unshift(@$args, "--mode=execute", $exe); - $exe= $exe_libtool; - } - if ( $opt_check_testcases ) { foreach my $mysqld (@{$master}, @{$slave}) @@ -3971,11 +4375,6 @@ sub run_mysqltest ($) { } } - # ------------------------------------------------------- - # Init variables that change for each testcase - # ------------------------------------------------------- - $ENV{'TZ'}= $tinfo->{'timezone'}; - my $res = mtr_run_test($exe,$args,"","",$path_timefile,""); if ( $opt_check_testcases ) @@ -3984,7 +4383,11 @@ sub run_mysqltest ($) { { if ($mysqld->{'pid'}) { - run_check_testcase("after", $mysqld); + if (run_check_testcase("after", $mysqld)) + { + # Check failed, mark the test case with that info + $tinfo->{'check_testcase_failed'}= 1; + } } } } @@ -4186,6 +4589,14 @@ sub valgrind_arguments { mtr_add_arg($args, $$exe); $$exe= $opt_valgrind_path || "valgrind"; + + if ($exe_libtool) + { + # Add "libtool --mode-execute" before the test to execute + # if running in valgrind(to avoid valgrinding bash) + unshift(@$args, "--mode=execute", $$exe); + $$exe= $exe_libtool; + } } @@ -4205,9 +4616,7 @@ sub usage ($) { print STDERR <<HERE; -mysql-test-run [ OPTIONS ] [ TESTCASE ] - -FIXME when is TESTCASE arg used or not?! +$0 [ OPTIONS ] [ TESTCASE ] Options to control what engine/variation to run @@ -4222,6 +4631,9 @@ Options to control what engine/variation to run skip-ssl Dont start server with support for ssl connections bench Run the benchmark suite small-bench Run the benchmarks with --small-tests --small-tables + with-ndbcluster Use cluster as default table type for benchmark + vs-config Visual Studio configuration used to create executables + (default: MTR_VS_CONFIG environment variable) Options to control directories to use benchdir=DIR The directory where the benchmark suite is stored @@ -4231,11 +4643,13 @@ Options to control directories to use vardir=DIR The directory where files generated from the test run is stored (default: ./var). Specifying a ramdisk or tmpfs will speed up tests. + mem=DIR Run testsuite in "memory" using tmpfs if + available(default: /dev/shm) + Options to control what test suites or cases to run force Continue to run the suite after failure - with-ndbcluster Use cluster in all tests with-ndbcluster-only Run only tests that include "ndb" in the filename skip-ndb[cluster] Skip all tests that need cluster skip-ndb[cluster]-slave Skip all tests that need a slave cluster @@ -4297,7 +4711,8 @@ Options for coverage, profiling etc valgrind Run the "mysqltest" and "mysqld" executables using valgrind with options($default_valgrind_options) valgrind-all Synonym for --valgrind - valgrind-mysqltest Run the "mysqltest" executable with valgrind + valgrind-mysqltest Run the "mysqltest" and "mysql_client_test" executable + with valgrind valgrind-mysqld Run the "mysqld" executable with valgrind valgrind-options=ARGS Options to give valgrind, replaces default options valgrind-path=[EXE] Path to the valgrind executable diff --git a/mysql-test/r/binlog_row_mix_innodb_myisam.result b/mysql-test/r/binlog_row_mix_innodb_myisam.result index a192d243bb0..e063d7371a9 100644 --- a/mysql-test/r/binlog_row_mix_innodb_myisam.result +++ b/mysql-test/r/binlog_row_mix_innodb_myisam.result @@ -220,7 +220,7 @@ select (@before:=unix_timestamp())*0; (@before:=unix_timestamp())*0 0 begin; - select * from t1 for update; +select * from t1 for update; insert into t2 values (20); ERROR HY000: Lock wait timeout exceeded; try restarting transaction select (@after:=unix_timestamp())*0; diff --git a/mysql-test/r/binlog_stm_mix_innodb_myisam.result b/mysql-test/r/binlog_stm_mix_innodb_myisam.result index 95b6eb953a2..8ab6840d441 100644 --- a/mysql-test/r/binlog_stm_mix_innodb_myisam.result +++ b/mysql-test/r/binlog_stm_mix_innodb_myisam.result @@ -195,7 +195,7 @@ select (@before:=unix_timestamp())*0; (@before:=unix_timestamp())*0 0 begin; - select * from t1 for update; +select * from t1 for update; insert into t2 values (20); ERROR HY000: Lock wait timeout exceeded; try restarting transaction select (@after:=unix_timestamp())*0; diff --git a/mysql-test/r/check.result b/mysql-test/r/check.result index 4c565f4f1b1..60806e7393e 100644 --- a/mysql-test/r/check.result +++ b/mysql-test/r/check.result @@ -1,6 +1,6 @@ drop table if exists t1; create table t1(n int not null, key(n), key(n), key(n), key(n)); - check table t1 extended; +check table t1 extended; insert into t1 values (200000); Table Op Msg_type Msg_text test.t1 check status OK diff --git a/mysql-test/r/csv.result b/mysql-test/r/csv.result index 222d4de8059..32ca47e20d2 100644 --- a/mysql-test/r/csv.result +++ b/mysql-test/r/csv.result @@ -4913,8 +4913,7 @@ bonfire Colombo nondecreasing DROP TABLE t1; -ALTER TABLE t2 RENAME t1 -#; +ALTER TABLE t2 RENAME t1; DROP TABLE t1; CREATE TABLE t1 ( Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, diff --git a/mysql-test/r/drop.result b/mysql-test/r/drop.result index 53b2ea8c84a..24f1b654733 100644 --- a/mysql-test/r/drop.result +++ b/mysql-test/r/drop.result @@ -79,9 +79,9 @@ drop table if exists t1; create table t1 (i int); lock tables t1 read; create database mysqltest; - drop table t1; +drop table t1; show open tables; - drop database mysqltest; +drop database mysqltest; select 1; 1 1 diff --git a/mysql-test/r/flush.result b/mysql-test/r/flush.result index a7f5e5e8fec..7eb7fd16edb 100644 --- a/mysql-test/r/flush.result +++ b/mysql-test/r/flush.result @@ -9,13 +9,13 @@ n flush tables with read lock; drop table t2; ERROR HY000: Can't execute the query because you have a conflicting read lock - drop table t2; +drop table t2; unlock tables; create database mysqltest; create table mysqltest.t1(n int); insert into mysqltest.t1 values (23); flush tables with read lock; - drop database mysqltest; +drop database mysqltest; select * from mysqltest.t1; n 23 @@ -51,7 +51,7 @@ drop table t1, t2, t3; create table t1 (c1 int); create table t2 (c1 int); lock table t1 write; - flush tables with read lock; - insert into t2 values(1); +flush tables with read lock; +insert into t2 values(1); unlock tables; drop table t1, t2; diff --git a/mysql-test/r/flush_block_commit.result b/mysql-test/r/flush_block_commit.result index e4a9dfcfff1..56f8acab896 100644 --- a/mysql-test/r/flush_block_commit.result +++ b/mysql-test/r/flush_block_commit.result @@ -5,7 +5,7 @@ insert into t1 values(1); flush tables with read lock; select * from t1; a - commit; +commit; select * from t1; a unlock tables; @@ -14,8 +14,8 @@ select * from t1 for update; a 1 begin; - select * from t1 for update; - flush tables with read lock; +select * from t1 for update; +flush tables with read lock; commit; a 1 @@ -45,7 +45,7 @@ flush tables with read lock; show master status; File Position Binlog_Do_DB Binlog_Ignore_DB master-bin.000001 102 - commit; +commit; show master status; File Position Binlog_Do_DB Binlog_Ignore_DB master-bin.000001 102 diff --git a/mysql-test/r/flush_read_lock_kill.result b/mysql-test/r/flush_read_lock_kill.result index dfdcf51457a..6703b6bd533 100644 --- a/mysql-test/r/flush_read_lock_kill.result +++ b/mysql-test/r/flush_read_lock_kill.result @@ -1,7 +1,7 @@ drop table if exists t1; create table t1 (kill_id int); insert into t1 values(connection_id()); - flush tables with read lock; +flush tables with read lock; select ((@id := kill_id) - kill_id) from t1; ((@id := kill_id) - kill_id) 0 diff --git a/mysql-test/r/flush_table.result b/mysql-test/r/flush_table.result index b29c83eb574..8821bade6b4 100644 --- a/mysql-test/r/flush_table.result +++ b/mysql-test/r/flush_table.result @@ -9,7 +9,7 @@ test.t1 check status OK unlock tables; lock table t1 read; lock table t1 read; - flush table t1; +flush table t1; select * from t1; a 1 @@ -19,7 +19,7 @@ a 1 unlock tables; lock table t1 write; - lock table t1 read; +lock table t1 read; flush table t1; select * from t1; a @@ -27,7 +27,7 @@ a unlock tables; unlock tables; lock table t1 read; - lock table t1 write; +lock table t1 write; flush table t1; select * from t1; a diff --git a/mysql-test/r/func_compress.result b/mysql-test/r/func_compress.result index 1a5e64978e6..715f319198c 100644 --- a/mysql-test/r/func_compress.result +++ b/mysql-test/r/func_compress.result @@ -79,6 +79,16 @@ uncompress(a) uncompressed_length(a) NULL NULL a 1 drop table t1; +create table t1(a blob); +insert into t1 values ('0'), (NULL), ('0'); +select compress(a), compress(a) from t1; +select compress(a) is null from t1; +compress(a) is null +0 +1 +0 +drop table t1; +End of 4.1 tests create table t1 (a varchar(32) not null); insert into t1 values ('foo'); explain select * from t1 where uncompress(a) is null; diff --git a/mysql-test/r/func_date_add.result b/mysql-test/r/func_date_add.result index 841d13a6ea6..ac5709260fd 100644 --- a/mysql-test/r/func_date_add.result +++ b/mysql-test/r/func_date_add.result @@ -71,3 +71,17 @@ NULL NULL NULL drop table t1; +End of 4.1 tests +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 DAY; +CAST('2006-09-26' AS DATE) + INTERVAL 1 DAY +2006-09-27 +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 MONTH; +CAST('2006-09-26' AS DATE) + INTERVAL 1 MONTH +2006-10-26 +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 YEAR; +CAST('2006-09-26' AS DATE) + INTERVAL 1 YEAR +2007-09-26 +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 WEEK; +CAST('2006-09-26' AS DATE) + INTERVAL 1 WEEK +2006-10-03 +End of 5.0 tests diff --git a/mysql-test/r/func_misc.result b/mysql-test/r/func_misc.result index f383a717a85..3ebf071a5bb 100644 --- a/mysql-test/r/func_misc.result +++ b/mysql-test/r/func_misc.result @@ -63,7 +63,7 @@ FROM t1 WHERE conn = 'default'; IS_USED_LOCK('bug16501') = connection_id 1 - SELECT GET_LOCK('bug16501',600); +SELECT GET_LOCK('bug16501',600); SELECT IS_USED_LOCK('bug16501') = CONNECTION_ID(); IS_USED_LOCK('bug16501') = CONNECTION_ID() 1 diff --git a/mysql-test/r/func_sapdb.result b/mysql-test/r/func_sapdb.result index 7e9bba9710c..29ceb6ecaa4 100644 --- a/mysql-test/r/func_sapdb.result +++ b/mysql-test/r/func_sapdb.result @@ -107,7 +107,9 @@ subtime("02:01:01.999999", "01:01:01.999999") 01:00:00.000000 select timediff("1997-01-01 23:59:59.000001","1995-12-31 23:59:59.000002"); timediff("1997-01-01 23:59:59.000001","1995-12-31 23:59:59.000002") -8807:59:59.999999 +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '8807:59:59.999999' select timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002"); timediff("1997-12-31 23:59:59.000001","1997-12-30 01:01:01.000002") 46:58:57.999999 @@ -219,13 +221,16 @@ SELECT TIMEDIFF(t1, t4) As ttt, TIMEDIFF(t2, t3) As qqq, TIMEDIFF(t3, t2) As eee, TIMEDIFF(t2, t4) As rrr from test; ttt qqq eee rrr -744:00:00 NULL NULL NULL -26305:01:02 22:58:58 -22:58:58 NULL --26305:01:02 -22:58:58 22:58:58 NULL +838:59:59 22:58:58 -22:58:58 NULL +-838:59:59 -22:58:58 22:58:58 NULL NULL 26:02:02 -26:02:02 NULL 00:00:00 -26:02:02 26:02:02 NULL NULL NULL NULL NULL NULL NULL NULL NULL 00:00:00 -24:00:00 24:00:00 NULL +Warnings: +Warning 1292 Truncated incorrect time value: '26305:01:02' +Warning 1292 Truncated incorrect time value: '-26305:01:02' drop table t1, test; select addtime("-01:01:01.01", "-23:59:59.1") as a; a @@ -235,7 +240,9 @@ a 10000 select microsecond(19971231235959.01) as a; a -10000 +0 +Warnings: +Warning 1292 Truncated incorrect time value: '19971231235959.01' select date_add("1997-12-31",INTERVAL "10.09" SECOND_MICROSECOND) as a; a 1997-12-31 00:00:10.090000 diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 82c361edd39..037b1ca9df7 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -339,7 +339,9 @@ extract(DAY_MINUTE FROM "02 10:11:12") 21011 select extract(DAY_SECOND FROM "225 10:11:12"); extract(DAY_SECOND FROM "225 10:11:12") -225101112 +8385959 +Warnings: +Warning 1292 Truncated incorrect time value: '225 10:11:12' select extract(HOUR FROM "1999-01-02 10:11:12"); extract(HOUR FROM "1999-01-02 10:11:12") 10 @@ -612,7 +614,7 @@ date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) 2003-01-03 01:01:01 select date_add(date,INTERVAL "1" WEEK) from t1; date_add(date,INTERVAL "1" WEEK) -2003-01-09 00:00:00 +2003-01-09 select date_add(date,INTERVAL "1" QUARTER) from t1; date_add(date,INTERVAL "1" QUARTER) 2003-04-02 @@ -621,7 +623,7 @@ timestampadd(MINUTE, 1, date) 2003-01-02 00:01:00 select timestampadd(WEEK, 1, date) from t1; timestampadd(WEEK, 1, date) -2003-01-09 00:00:00 +2003-01-09 select timestampadd(SQL_TSI_SECOND, 1, date) from t1; timestampadd(SQL_TSI_SECOND, 1, date) 2003-01-02 00:00:01 @@ -890,6 +892,93 @@ t1 CREATE TABLE `t1` ( `from_unixtime(1) + 0` double(23,6) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; +SELECT SEC_TO_TIME(3300000); +SEC_TO_TIME(3300000) +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '3300000' +SELECT SEC_TO_TIME(3300000)+0; +SEC_TO_TIME(3300000)+0 +8385959.000000 +Warnings: +Warning 1292 Truncated incorrect time value: '3300000' +SELECT SEC_TO_TIME(3600 * 4294967296); +SEC_TO_TIME(3600 * 4294967296) +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '15461882265600' +SELECT TIME_TO_SEC('916:40:00'); +TIME_TO_SEC('916:40:00') +3020399 +Warnings: +Warning 1292 Truncated incorrect time value: '916:40:00' +SELECT ADDTIME('500:00:00', '416:40:00'); +ADDTIME('500:00:00', '416:40:00') +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '916:40:00' +SELECT ADDTIME('916:40:00', '416:40:00'); +ADDTIME('916:40:00', '416:40:00') +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '916:40:00' +Warning 1292 Truncated incorrect time value: '1255:39:59' +SELECT SUBTIME('916:40:00', '416:40:00'); +SUBTIME('916:40:00', '416:40:00') +422:19:59 +Warnings: +Warning 1292 Truncated incorrect time value: '916:40:00' +SELECT SUBTIME('-916:40:00', '416:40:00'); +SUBTIME('-916:40:00', '416:40:00') +-838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '-916:40:00' +Warning 1292 Truncated incorrect time value: '-1255:39:59' +SELECT MAKETIME(916,0,0); +MAKETIME(916,0,0) +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '916:00:00' +SELECT MAKETIME(4294967296, 0, 0); +MAKETIME(4294967296, 0, 0) +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '4294967296:00:00' +SELECT MAKETIME(-4294967296, 0, 0); +MAKETIME(-4294967296, 0, 0) +-838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '-4294967296:00:00' +SELECT MAKETIME(0, 4294967296, 0); +MAKETIME(0, 4294967296, 0) +NULL +SELECT MAKETIME(0, 0, 4294967296); +MAKETIME(0, 0, 4294967296) +NULL +SELECT MAKETIME(CAST(-1 AS UNSIGNED), 0, 0); +MAKETIME(CAST(-1 AS UNSIGNED), 0, 0) +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '18446744073709551615:00:00' +SELECT EXTRACT(HOUR FROM '100000:02:03'); +EXTRACT(HOUR FROM '100000:02:03') +838 +Warnings: +Warning 1292 Truncated incorrect time value: '100000:02:03' +CREATE TABLE t1(f1 TIME); +INSERT INTO t1 VALUES('916:00:00 a'); +Warnings: +Warning 1265 Data truncated for column 'f1' at row 1 +Warning 1264 Out of range value for column 'f1' at row 1 +SELECT * FROM t1; +f1 +838:59:59 +DROP TABLE t1; +SELECT SEC_TO_TIME(CAST(-1 AS UNSIGNED)); +SEC_TO_TIME(CAST(-1 AS UNSIGNED)) +838:59:59 +Warnings: +Warning 1292 Truncated incorrect time value: '18446744073709551615' SET NAMES latin1; SET character_set_results = NULL; SHOW VARIABLES LIKE 'character_set_results'; @@ -922,18 +1011,6 @@ union (select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H); H 5 -SET NAMES latin1; -SET character_set_results = NULL; -SHOW VARIABLES LIKE 'character_set_results'; -Variable_name Value -character_set_results -CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32) CHARACTER SET BINARY); -INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd'); -SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868; -fmtddate field2 -Sep-4 12:00AM abcd -DROP TABLE testBug8868; -SET NAMES DEFAULT; End of 4.1 tests explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2; diff --git a/mysql-test/r/grant2.result b/mysql-test/r/grant2.result index 79ba073a856..4b089c1d5e9 100644 --- a/mysql-test/r/grant2.result +++ b/mysql-test/r/grant2.result @@ -336,12 +336,12 @@ drop database mysqltest_1; set password = password("changed"); ERROR 42000: Access denied for user ''@'localhost' to database 'mysql' lock table mysql.user write; - flush privileges; - grant all on *.* to 'mysqltest_1'@'localhost'; +flush privileges; +grant all on *.* to 'mysqltest_1'@'localhost'; unlock tables; lock table mysql.user write; - set password for 'mysqltest_1'@'localhost' = password(''); - revoke all on *.* from 'mysqltest_1'@'localhost'; +set password for 'mysqltest_1'@'localhost' = password(''); +revoke all on *.* from 'mysqltest_1'@'localhost'; unlock tables; drop user 'mysqltest_1'@'localhost'; create database TESTDB; diff --git a/mysql-test/r/handler_innodb.result b/mysql-test/r/handler_innodb.result index 89569d918ca..1bd50612a3f 100644 --- a/mysql-test/r/handler_innodb.result +++ b/mysql-test/r/handler_innodb.result @@ -476,7 +476,7 @@ handler t1 read first; c1 1 send the below to another connection, do not wait for the result - optimize table t1; +optimize table t1; proceed with the normal connection handler t1 read next; c1 @@ -502,7 +502,7 @@ flush tables with read lock; drop table t1; ERROR HY000: Can't execute the query because you have a conflicting read lock send the below to another connection, do not wait for the result - drop table t1; +drop table t1; proceed with the normal connection select * from t1; c1 diff --git a/mysql-test/r/handler_myisam.result b/mysql-test/r/handler_myisam.result index 8edf191b1b0..beb1a40c318 100644 --- a/mysql-test/r/handler_myisam.result +++ b/mysql-test/r/handler_myisam.result @@ -476,7 +476,7 @@ handler t1 read first; c1 1 send the below to another connection, do not wait for the result - optimize table t1; +optimize table t1; proceed with the normal connection handler t1 read next; c1 @@ -502,7 +502,7 @@ flush tables with read lock; drop table t1; ERROR HY000: Can't execute the query because you have a conflicting read lock send the below to another connection, do not wait for the result - drop table t1; +drop table t1; proceed with the normal connection select * from t1; c1 diff --git a/mysql-test/r/im_daemon_life_cycle.result b/mysql-test/r/im_daemon_life_cycle.result index eee8479888a..23990240acd 100644 --- a/mysql-test/r/im_daemon_life_cycle.result +++ b/mysql-test/r/im_daemon_life_cycle.result @@ -8,6 +8,7 @@ mysqld2 offline Killing the process... Sleeping... Success: the process was restarted. +Success: server is ready to accept connection on socket. -------------------------------------------------------------------- -- Test for BUG#12751 diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index b73b59a433a..305e89f0325 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -759,6 +759,7 @@ select table_schema,table_name, column_name from information_schema.columns where data_type = 'longtext'; table_schema table_name column_name +information_schema COLUMNS COLUMN_DEFAULT information_schema COLUMNS COLUMN_TYPE information_schema EVENTS EVENT_DEFINITION information_schema EVENTS SQL_MODE @@ -1315,6 +1316,19 @@ WHERE table_name=(SELECT MAX(table_name) FROM information_schema.tables); table_name VIEWS +DROP TABLE IF EXISTS bug23037; +DROP FUNCTION IF EXISTS get_value; +SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037'; +COLUMN_NAME MD5(COLUMN_DEFAULT) LENGTH(COLUMN_DEFAULT) +fld1 7cf7a6782be951a1f2464a350da926a5 65532 +SELECT MD5(get_value()); +MD5(get_value()) +7cf7a6782be951a1f2464a350da926a5 +SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT), COLUMN_DEFAULT=get_value() FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037'; +COLUMN_NAME MD5(COLUMN_DEFAULT) LENGTH(COLUMN_DEFAULT) COLUMN_DEFAULT=get_value() +fld1 7cf7a6782be951a1f2464a350da926a5 65532 1 +DROP TABLE bug23037; +DROP FUNCTION get_value; End of 5.0 tests. select * from information_schema.engines WHERE ENGINE="MyISAM"; ENGINE SUPPORT COMMENT TRANSACTIONS XA SAVEPOINTS diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index 4acfaf58a7d..fb854ed7992 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1,11 +1,5 @@ SET SESSION STORAGE_ENGINE = InnoDB; drop table if exists t1,t2,t1m,t1i,t2m,t2i,t4; -create table t1(f1 varchar(800) binary not null, key(f1)) -character set utf8 collate utf8_general_ci; -Warnings: -Warning 1071 Specified key was too long; max key length is 765 bytes -insert into t1 values('aaa'); -drop table t1; create table t1 ( c_id int(11) not null default '0', org_id int(11) default null, @@ -111,6 +105,14 @@ SELECT `id1` FROM `t1` WHERE `id1` NOT IN (SELECT `id1` FROM `t2` WHERE `id2` = id1 2 DROP TABLE t1, t2; +create table t1 (c1 int) engine=innodb; +handler t1 open; +handler t1 read first; +c1 +Before and after comparison +0 +drop table t1; +End of 4.1 tests create table t1m (a int) engine = MEMORY; create table t1i (a int); create table t2m (a int) engine = MEMORY; @@ -248,6 +250,22 @@ b c d drop table t1,t4; +DROP TABLE IF EXISTS t2, t1; +CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY) ENGINE= InnoDB; +CREATE TABLE t2 ( +i INT NOT NULL, +FOREIGN KEY (i) REFERENCES t1 (i) ON DELETE NO ACTION +) ENGINE= InnoDB; +INSERT INTO t1 VALUES (1); +INSERT INTO t2 VALUES (1); +DELETE IGNORE FROM t1 WHERE i = 1; +Warnings: +Error 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`i`) REFERENCES `t1` (`i`) ON DELETE NO ACTION) +SELECT * FROM t1, t2; +i i +1 1 +DROP TABLE t2, t1; +End of 4.1 tests. create table t1 ( a varchar(30), b varchar(30), primary key(a), key(b) ); @@ -369,6 +387,23 @@ Warnings: Warning 1071 Specified key was too long; max key length is 765 bytes insert into t1 values('aaa'); drop table t1; +CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c FLOAT, KEY b(b)) ENGINE = INNODB; +INSERT INTO t1 VALUES ( 1 , 1 , 1); +INSERT INTO t1 SELECT a + 1 , MOD(a + 1 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 2 , MOD(a + 2 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 4 , MOD(a + 4 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 8 , MOD(a + 8 , 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 16, MOD(a + 16, 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 32, MOD(a + 32, 20), 1 FROM t1; +INSERT INTO t1 SELECT a + 64, MOD(a + 64, 20), 1 FROM t1; +EXPLAIN SELECT b, SUM(c) FROM t1 GROUP BY b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index NULL b 5 NULL 128 +EXPLAIN SELECT SQL_BIG_RESULT b, SUM(c) FROM t1 GROUP BY b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 128 Using filesort +DROP TABLE t1; +End of 5.0 tests CREATE TABLE `t2` ( `k` int(11) NOT NULL auto_increment, `a` int(11) default NULL, @@ -437,3 +472,4 @@ k a c 11 15 1 12 20 1 drop table t2; +End of 5.1 tests diff --git a/mysql-test/r/innodb_notembedded.result b/mysql-test/r/innodb_notembedded.result index 9aac20e515d..cc13a429dfc 100644 --- a/mysql-test/r/innodb_notembedded.result +++ b/mysql-test/r/innodb_notembedded.result @@ -10,7 +10,7 @@ start transaction; select f1(); f1() 100 - update t1 set col2=0 where col1=1; +update t1 set col2=0 where col1=1; select * from t1; col1 col2 1 100 diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result index b78c677fb02..cf5486d1091 100644 --- a/mysql-test/r/kill.result +++ b/mysql-test/r/kill.result @@ -22,7 +22,7 @@ create table t2 (id int unsigned not null); insert into t2 select id from t1; create table t3 (kill_id int); insert into t3 values(connection_id()); - select id from t1 where id in (select distinct id from t2); +select id from t1 where id in (select distinct id from t2); select ((@id := kill_id) - kill_id) from t3; ((@id := kill_id) - kill_id) 0 @@ -32,7 +32,7 @@ drop table t1, t2, t3; select get_lock("a", 10); get_lock("a", 10) 1 - select get_lock("a", 10); +select get_lock("a", 10); get_lock("a", 10) NULL select 1; diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index 8ff02d898a3..2445b3e0c69 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -2,8 +2,8 @@ drop table if exists t1,t2; create table t1(n int); insert into t1 values (1); lock tables t1 write; - update low_priority t1 set n = 4; - select n from t1; +update low_priority t1 set n = 4; +select n from t1; unlock tables; n 4 @@ -11,8 +11,8 @@ drop table t1; create table t1(n int); insert into t1 values (1); lock tables t1 read; - update low_priority t1 set n = 4; - select n from t1; +update low_priority t1 set n = 4; +select n from t1; unlock tables; n 1 @@ -23,7 +23,7 @@ insert into t1 values(1,1); insert into t1 values(2,2); insert into t2 values(1,2); lock table t1 read; - update t1,t2 set c=a where b=d; +update t1,t2 set c=a where b=d; select c from t2; c 2 @@ -32,14 +32,14 @@ drop table t2; create table t1 (a int); create table t2 (a int); lock table t1 write, t2 write; - insert t1 select * from t2; +insert t1 select * from t2; drop table t2; ERROR 42S02: Table 'test.t2' doesn't exist drop table t1; create table t1 (a int); create table t2 (a int); lock table t1 write, t2 write, t1 as t1_2 write, t2 as t2_2 write; - insert t1 select * from t2; +insert t1 select * from t2; drop table t2; ERROR 42S02: Table 'test.t2' doesn't exist drop table t1; @@ -54,7 +54,7 @@ use mysql; LOCK TABLES columns_priv WRITE, db WRITE, host WRITE, user WRITE; FLUSH TABLES; use mysql; - SELECT user.Select_priv FROM user, db WHERE user.user = db.user LIMIT 1; +SELECT user.Select_priv FROM user, db WHERE user.user = db.user LIMIT 1; OPTIMIZE TABLES columns_priv, db, host, user; Table Op Msg_type Msg_text mysql.columns_priv optimize status OK @@ -68,14 +68,14 @@ use test; use test; CREATE TABLE t1 (c1 int); LOCK TABLE t1 WRITE; - FLUSH TABLES WITH READ LOCK; +FLUSH TABLES WITH READ LOCK; CREATE TABLE t2 (c1 int); UNLOCK TABLES; UNLOCK TABLES; DROP TABLE t1, t2; CREATE TABLE t1 (c1 int); LOCK TABLE t1 WRITE; - FLUSH TABLES WITH READ LOCK; +FLUSH TABLES WITH READ LOCK; CREATE TABLE t2 AS SELECT * FROM t1; ERROR HY000: Table 't2' was not locked with LOCK TABLES UNLOCK TABLES; @@ -83,7 +83,7 @@ UNLOCK TABLES; DROP TABLE t1; CREATE DATABASE mysqltest_1; FLUSH TABLES WITH READ LOCK; - DROP DATABASE mysqltest_1; +DROP DATABASE mysqltest_1; DROP DATABASE mysqltest_1; ERROR HY000: Can't execute the query because you have a conflicting read lock UNLOCK TABLES; @@ -91,7 +91,7 @@ DROP DATABASE mysqltest_1; ERROR HY000: Can't drop database 'mysqltest_1'; database doesn't exist 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; // +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/log_tables.result b/mysql-test/r/log_tables.result index a9683cc7c56..2836b96d7b5 100644 --- a/mysql-test/r/log_tables.result +++ b/mysql-test/r/log_tables.result @@ -39,14 +39,14 @@ ERROR HY000: You can't use usual read lock with log tables. Try READ LOCAL inste lock tables mysql.slow_log READ LOCAL, mysql.general_log READ LOCAL; unlock tables; lock tables mysql.general_log READ LOCAL; - flush logs; +flush logs; unlock tables; select "Mark that we woke up from flush logs in the test" as "test passed"; test passed Mark that we woke up from flush logs in the test lock tables mysql.general_log READ LOCAL; - truncate mysql.general_log; +truncate mysql.general_log; unlock tables; select "Mark that we woke up from TRUNCATE in the test" as "test passed"; @@ -218,3 +218,71 @@ unlock tables; use mysql; lock tables general_log read local, help_category read local; unlock tables; +use mysql; +RENAME TABLE general_log TO renamed_general_log; +ERROR HY000: Cannot rename 'general_log'. When logging enabled, rename to/from log table must rename two tables: the log table to an archive table and another table back to 'general_log' +RENAME TABLE slow_log TO renamed_slow_log; +ERROR HY000: Cannot rename 'slow_log'. When logging enabled, rename to/from log table must rename two tables: the log table to an archive table and another table back to 'slow_log' +truncate table general_log; +select * from general_log; +event_time user_host thread_id server_id command_type argument +TIMESTAMP USER_HOST THREAD_ID 1 Query select * from general_log +truncate table slow_log; +select * from slow_log; +start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text +create table general_log_new like general_log; +rename table general_log TO renamed_general_log, general_log_new TO general_log; +create table slow_log_new like slow_log; +rename table slow_log TO renamed_slow_log, slow_log_new TO slow_log; +rename table general_log TO general_log_new, renamed_general_log TO general_log, slow_log to renamed_slow_log; +ERROR HY000: Cannot rename 'slow_log'. When logging enabled, rename to/from log table must rename two tables: the log table to an archive table and another table back to 'slow_log' +select * from general_log; +event_time user_host thread_id server_id command_type argument +TIMESTAMP USER_HOST THREAD_ID 1 Query create table slow_log_new like slow_log +TIMESTAMP USER_HOST THREAD_ID 1 Query rename table slow_log TO renamed_slow_log, slow_log_new TO slow_log +TIMESTAMP USER_HOST THREAD_ID 1 Query rename table general_log TO general_log_new, renamed_general_log TO general_log, slow_log to renamed_slow_log +TIMESTAMP USER_HOST THREAD_ID 1 Query select * from general_log +select * from renamed_general_log; +event_time user_host thread_id server_id command_type argument +TIMESTAMP USER_HOST THREAD_ID 1 Query select * from general_log +TIMESTAMP USER_HOST THREAD_ID 1 Query truncate table slow_log +TIMESTAMP USER_HOST THREAD_ID 1 Query select * from slow_log +TIMESTAMP USER_HOST THREAD_ID 1 Query create table general_log_new like general_log +TIMESTAMP USER_HOST THREAD_ID 1 Query rename table general_log TO renamed_general_log, general_log_new TO general_log +select * from slow_log; +start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text +select * from renamed_slow_log; +start_time user_host query_time lock_time rows_sent rows_examined db last_insert_id insert_id server_id sql_text +set global general_log='OFF'; +RENAME TABLE general_log TO general_log2; +set global slow_query_log='OFF'; +RENAME TABLE slow_log TO slow_log2; +set global general_log='ON'; +ERROR HY000: Cannot activate 'general' log +set global slow_query_log='ON'; +ERROR HY000: Cannot activate 'slow query' log +RENAME TABLE general_log2 TO general_log; +RENAME TABLE slow_log2 TO slow_log; +set global general_log='ON'; +set global slow_query_log='ON'; +flush logs; +flush logs; +drop table renamed_general_log, renamed_slow_log; +use test; +use mysql; +repair table general_log; +Table Op Msg_type Msg_text +mysql.general_log repair status OK +repair table slow_log; +Table Op Msg_type Msg_text +mysql.slow_log repair status OK +create table general_log_new like general_log; +create table slow_log_new like slow_log; +show tables like "%log%"; +Tables_in_mysql (%log%) +general_log +general_log_new +slow_log +slow_log_new +drop table slow_log_new, general_log_new; +use test; diff --git a/mysql-test/r/multi_update.result b/mysql-test/r/multi_update.result index 3ed0222fcdb..6d8e5dfdf2c 100644 --- a/mysql-test/r/multi_update.result +++ b/mysql-test/r/multi_update.result @@ -509,8 +509,8 @@ create table t2 (a int); insert into t2 values (10), (20), (30); create view v1 as select a as b, a/10 as a from t2; lock table t1 write; - alter table t1 add column c int default 100 after a; - update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a; +alter table t1 add column c int default 100 after a; +update t1, v1 set t1.b=t1.a+t1.b+v1.b where t1.a=v1.a; unlock tables; select * from t1; a c b diff --git a/mysql-test/r/mysql.result b/mysql-test/r/mysql.result index 1053b1918fb..14267afc27e 100644 --- a/mysql-test/r/mysql.result +++ b/mysql-test/r/mysql.result @@ -149,4 +149,33 @@ ERROR at line 1: USE must be followed by a database name \\ '; '; +create table t17583 (a int); +insert into t17583 (a) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +select count(*) from t17583; +count(*) +1280 +drop table t17583; +Test connect without db- or host-name => reconnect +Test connect with dbname only => new dbname, old hostname +ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'connecttest' at line 1 +Test connect with _invalid_ dbname only => new invalid dbname, old hostname +ERROR 1049 (42000) at line 1: Unknown database 'invalid' +ERROR 1049 (42000) at line 1: Unknown database 'invalid' +Test connect with dbname + hostname +Test connect with dbname + _invalid_ hostname +ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno) +ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'invalid_hostname' (errno) +The commands reported in the bug report +ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyril has found a bug :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno) +Too long dbname +ERROR 1049 (42000) at line 1: Unknown database 'test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' +Too long hostname +ERROR 2005 (HY000) at line 1: Unknown MySQL server host 'cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' (errno) End of 5.0 tests diff --git a/mysql-test/r/mysqldump-max.result b/mysql-test/r/mysqldump-max.result index 613db96be93..e78fc4d386a 100644 --- a/mysql-test/r/mysqldump-max.result +++ b/mysql-test/r/mysqldump-max.result @@ -1,21 +1,4 @@ -drop table if exists t1; -Warnings: -Note 1051 Unknown table 't1' -drop table if exists t2; -Warnings: -Note 1051 Unknown table 't2' -drop table if exists t3; -Warnings: -Note 1051 Unknown table 't3' -drop table if exists t4; -Warnings: -Note 1051 Unknown table 't4' -drop table if exists t5; -Warnings: -Note 1051 Unknown table 't5' -drop table if exists t6; -Warnings: -Note 1051 Unknown table 't6' +drop table if exists t1, t2, t3, t4, t5, t6; create table t1 (id int(8), name varchar(32)); create table t2 (id int(8), name varchar(32)) ENGINE="MyISAM"; create table t3 (id int(8), name varchar(32)) ENGINE="MEMORY"; diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index b59f63d207e..54c68701f78 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -3195,6 +3195,28 @@ UNLOCK TABLES; DROP TABLE `t1`; # +# Bug #19745: mysqldump --xml produces invalid xml +# +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (f1 int(10), data MEDIUMBLOB); +INSERT INTO t1 VALUES(1,0xff00fef0); +<?xml version="1.0"?> +<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> +<database name="test"> + <table_structure name="t1"> + <field Field="f1" Type="int(10)" Null="YES" Key="" Extra="" /> + <field Field="data" Type="mediumblob" Null="YES" Key="" Extra="" /> + </table_structure> + <table_data name="t1"> + <row> + <field name="f1">1</field> + <field name="data" xsi:type="xs:hexBinary">FF00FEF0</field> + </row> + </table_data> +</database> +</mysqldump> +DROP TABLE t1; +# # End of 5.0 tests # drop table if exists t1; diff --git a/mysql-test/r/mysqltest.result b/mysql-test/r/mysqltest.result index ce9fb6941f3..1cfc482416e 100644 --- a/mysql-test/r/mysqltest.result +++ b/mysql-test/r/mysqltest.result @@ -152,8 +152,38 @@ mysqltest: At line 1: Missing delimiter mysqltest: At line 1: End of line junk detected: "sleep 7 # Another comment " +mysqltest: At line 1: Missing delimiter +mysqltest: At line 1: Missing delimiter +mysqltest: At line 1: End of line junk detected: "disconnect default + +# +# comment +# comment2 + +# comment 3 +--disable_query_log +" +mysqltest: At line 1: End of line junk detected: "disconnect default # comment +# comment part2 + +# comment 3 +--disable_query_log +" mysqltest: At line 1: Extra delimiter ";" found mysqltest: At line 1: Extra delimiter ";" found +mysqltest: At line 1: Missing argument(s) to 'error' +mysqltest: At line 1: Missing argument(s) to 'error' +mysqltest: At line 1: The sqlstate definition must start with an uppercase S +mysqltest: At line 1: The error name definition must start with an uppercase E +mysqltest: At line 1: Invalid argument to error: '9eeeee' - the errno may only consist of digits[0-9] +mysqltest: At line 1: Invalid argument to error: '1sssss' - the errno may only consist of digits[0-9] +mysqltest: At line 1: The sqlstate must be exactly 5 chars long +mysqltest: At line 1: The sqlstate may only consist of digits[0-9] and _uppercase_ letters +mysqltest: At line 1: The sqlstate must be exactly 5 chars long +mysqltest: At line 1: Unknown SQL error name 'E9999' +mysqltest: At line 1: Invalid argument to error: '999e9' - the errno may only consist of digits[0-9] +mysqltest: At line 1: Invalid argument to error: '9b' - the errno may only consist of digits[0-9] +mysqltest: At line 1: Too many errorcodes specified MySQL "MySQL" MySQL: The world''s most popular open source database @@ -239,7 +269,7 @@ mysqltest: At line 1: Missing assignment operator in let 1 # Execute: echo $success ; 1 -mysqltest: At line 1: Missing file name in source +mysqltest: At line 1: Missing required argument 'filename' to command 'source' mysqltest: At line 1: Could not open file ./non_existingFile mysqltest: In included file "MYSQLTEST_VARDIR/tmp/recursive.sql": At line 1: Source directives are nesting too deep mysqltest: In included file "MYSQLTEST_VARDIR/tmp/error.sql": At line 1: query 'garbage ' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'garbage' at line 1 @@ -332,16 +362,16 @@ Counter is greater than 0, (counter=10) Counter is not 0, (counter=0) 1 Testing while with not -mysqltest: In included file "./include/mysqltest_while.inc": At line 64: Nesting too deeply +mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest_while.inc": At line 64: Nesting too deeply mysqltest: At line 1: missing '(' in while mysqltest: At line 1: missing ')' in while mysqltest: At line 1: Missing '{' after while. Found "dec $i" mysqltest: At line 1: Stray '}' - end of block before beginning mysqltest: At line 1: Stray 'end' command - end of block before beginning -mysqltest: At line 1: query '' failed: 1065: Query was empty +mysqltest: At line 1: query '{' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{' at line 1 mysqltest: At line 1: Missing '{' after while. Found "echo hej" mysqltest: At line 3: Missing end of block -mysqltest: At line 1: Missing newline between while and '{' +mysqltest: At line 3: Missing end of block mysqltest: At line 1: missing '(' in if mysqltest: At line 1: Stray 'end' command - end of block before beginning select "b" bs col1, "c" bs col2; @@ -371,17 +401,15 @@ mysqltest: At line 1: Wrong column number to replace_column in 'replace_column 1 mysqltest: At line 1: Invalid integer argument "10!" mysqltest: At line 1: End of line junk detected: "!" mysqltest: At line 1: Invalid integer argument "a" -mysqltest: At line 1: Syntax error in connect - expected '(' found 'mysqltest: At line 1: Missing connection host -mysqltest: At line 1: Missing connection host -mysqltest: At line 1: Missing connection user -mysqltest: At line 1: Missing connection user -mysqltest: At line 1: Missing connection password -mysqltest: At line 1: Missing connection db -mysqltest: At line 1: Could not open connection 'con2': 1049 Unknown database 'illegal_db' +mysqltest: At line 1: Missing required argument 'connection name' to command 'connect' +mysqltest: At line 1: Missing required argument 'connection name' to command 'connect' +mysqltest: At line 1: Missing required argument 'host' to command 'connect' +mysqltest: At line 1: Missing required argument 'host' to command 'connect' +mysqltest: At line 1: query 'connect con2,localhost,root,,illegal_db' failed: 1049: Unknown database 'illegal_db' mysqltest: At line 1: Illegal argument for port: 'illegal_port' mysqltest: At line 1: Illegal option to connect: SMTP OK -mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest.sql": At line 7: Connection limit exhausted - increase MAX_CONS in mysqltest.c +mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest.sql": At line 7: Connection limit exhausted, you can have max 128 connections mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest.sql": At line 3: connection 'test_con1' not found in connection pool mysqltest: In included file "MYSQLTEST_VARDIR/tmp/mysqltest.sql": At line 2: Connection test_con1 already exists connect(localhost,root,,test,MASTER_PORT,MASTER_SOCKET); @@ -449,7 +477,6 @@ sleep; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sleep' at line 1 ; ERROR 42000: Query was empty -End of 5.0 tests select "b" as col1, "c" as col2; col1 col2 b c @@ -477,4 +504,20 @@ a D 1 1 1 4 drop table t1; -End of 5.1 tests +mysqltest: At line 1: Missing required argument 'filename' to command 'remove_file' +mysqltest: At line 1: Missing required argument 'filename' to command 'write_file' +mysqltest: At line 1: End of file encountered before 'EOF' delimiter was found +mysqltest: At line 1: End of line junk detected: "write_file filename "; +" +mysqltest: At line 1: Missing required argument 'filename' to command 'file_exists' +mysqltest: At line 1: Missing required argument 'from_file' to command 'copy_file' +mysqltest: At line 1: Missing required argument 'to_file' to command 'copy_file' +hello +hello +hello +mysqltest: At line 1: Max delimiter length(16) exceeded +hello +hello +mysqltest: At line 1: test of die +Some output +End of tests diff --git a/mysql-test/r/ndb_basic.result b/mysql-test/r/ndb_basic.result index 6503e5eecb9..e0255ddb9e7 100644 --- a/mysql-test/r/ndb_basic.result +++ b/mysql-test/r/ndb_basic.result @@ -568,7 +568,7 @@ t1 insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2),(6,1),(7,1); explain select * from t1 where a12345678901234567890123456789a1234567890=2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref a12345678901234567890123456789a1234567890 a12345678901234567890123456789a1234567890 5 const 1 Using where +1 SIMPLE t1 ref a12345678901234567890123456789a1234567890 a12345678901234567890123456789a1234567890 5 const # Using where select * from t1 where a12345678901234567890123456789a1234567890=2; a1234567890123456789012345678901234567890 a12345678901234567890123456789a1234567890 5 2 diff --git a/mysql-test/r/ndb_blob.result b/mysql-test/r/ndb_blob.result index 829c67905bf..04f2cea6250 100644 --- a/mysql-test/r/ndb_blob.result +++ b/mysql-test/r/ndb_blob.result @@ -40,7 +40,7 @@ insert into t1 values(2,@b2,222,@d2); commit; explain select * from t1 where a = 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 +1 SIMPLE t1 const PRIMARY PRIMARY 4 const # select a,length(b),substr(b,1+2*900,2),length(d),substr(d,1+3*900,3) from t1 where a=1; a length(b) substr(b,1+2*900,2) length(d) substr(d,1+3*900,3) @@ -87,7 +87,7 @@ replace t1 set a=2,b=@b2,c=222,d=@d2; commit; explain select * from t1 where a = 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 +1 SIMPLE t1 const PRIMARY PRIMARY 4 const # select a,length(b),substr(b,1+2*900,2),length(d),substr(d,1+3*900,3) from t1 where a=1; a length(b) substr(b,1+2*900,2) length(d) substr(d,1+3*900,3) @@ -134,7 +134,7 @@ insert into t1 values(2,@b2,222,@d2); commit; explain select * from t1 where c = 111; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref c c 4 const 1 +1 SIMPLE t1 ref c c 4 const # select a,length(b),substr(b,1+2*900,2),length(d),substr(d,1+3*900,3) from t1 where c=111; a length(b) substr(b,1+2*900,2) length(d) substr(d,1+3*900,3) @@ -177,7 +177,7 @@ insert into t1 values(9,'b9',999,'dd9'); commit; explain select * from t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 9 +1 SIMPLE t1 ALL NULL NULL NULL NULL # select * from t1 order by a; a b c d 1 b1 111 dd1 @@ -212,7 +212,7 @@ insert into t1 values(2,@b2,222,@d2); commit; explain select * from t1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 2 +1 SIMPLE t1 ALL NULL NULL NULL NULL # select a,length(b),substr(b,1+2*900,2),length(d),substr(d,1+3*900,3) from t1 order by a; a length(b) substr(b,1+2*900,2) length(d) substr(d,1+3*900,3) @@ -242,7 +242,7 @@ insert into t1 values(9,'b9',999,'dd9'); commit; explain select * from t1 where c >= 100 order by a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range c c 4 NULL 9 Using where; Using filesort +1 SIMPLE t1 range c c 4 NULL # Using where; Using filesort select * from t1 where c >= 100 order by a; a b c d 1 b1 111 dd1 @@ -278,7 +278,7 @@ insert into t1 values(2,@b2,222,@d2); commit; explain select * from t1 where c >= 100 order by a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range c c 4 NULL 2 Using where; Using filesort +1 SIMPLE t1 range c c 4 NULL # Using where; Using filesort select a,length(b),substr(b,1+2*900,2),length(d),substr(d,1+3*900,3) from t1 where c >= 100 order by a; a length(b) substr(b,1+2*900,2) length(d) substr(d,1+3*900,3) diff --git a/mysql-test/r/ndb_charset.result b/mysql-test/r/ndb_charset.result index b3a2112d50b..1c65a380039 100644 --- a/mysql-test/r/ndb_charset.result +++ b/mysql-test/r/ndb_charset.result @@ -112,9 +112,9 @@ unique key(a) ) engine=ndb; insert into t1 values(1, 'aAa'); insert into t1 values(2, 'aaa'); -ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' insert into t1 values(3, 'AAA'); -ERROR 23000: Duplicate entry '3' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' select * from t1 order by p; p a 1 aAa @@ -138,9 +138,9 @@ unique key(a) ) engine=ndb; insert into t1 values (1,'A'),(2,'b '),(3,'C '),(4,'d '),(5,'E'),(6,'f'); insert into t1 values(99,'b'); -ERROR 23000: Duplicate entry '99' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' insert into t1 values(99,'a '); -ERROR 23000: Duplicate entry '99' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' select a,length(a) from t1 order by a; a length(a) A 1 @@ -186,9 +186,6 @@ p a 4 aAa 5 aaa 6 AAA -explain select * from t1 where a = 'zZz' order by p; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const a NULL NULL NULL 1 select * from t1 where a = 'aAa' order by p; p a 1 aAa @@ -223,9 +220,6 @@ p a 4 aAa 5 aaa 6 AAA -explain select * from t1 where a = 'zZz' order by p; -id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const a NULL NULL NULL 1 select * from t1 where a = 'aAa' order by p; p a 1 aAa diff --git a/mysql-test/r/ndb_condition_pushdown.result b/mysql-test/r/ndb_condition_pushdown.result index 713e6e4c057..0d67d310a2b 100644 --- a/mysql-test/r/ndb_condition_pushdown.result +++ b/mysql-test/r/ndb_condition_pushdown.result @@ -513,7 +513,7 @@ time_field = '01:01:01' and date_time = '1901-01-01 01:01:01' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where string = "aaaa" and vstring = "aaaa" and @@ -570,7 +570,7 @@ time_field != '01:01:01' and date_time != '1901-01-01 01:01:01' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where string != "aaaa" and vstring != "aaaa" and @@ -629,7 +629,7 @@ time_field > '01:01:01' and date_time > '1901-01-01 01:01:01' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where string > "aaaa" and vstring > "aaaa" and @@ -688,7 +688,7 @@ time_field >= '01:01:01' and date_time >= '1901-01-01 01:01:01' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where string >= "aaaa" and vstring >= "aaaa" and @@ -748,7 +748,7 @@ time_field < '04:04:04' and date_time < '1904-04-04 04:04:04' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where string < "dddd" and vstring < "dddd" and @@ -807,7 +807,7 @@ time_field <= '04:04:04' and date_time <= '1904-04-04 04:04:04' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where string <= "dddd" and vstring <= "dddd" and @@ -868,7 +868,7 @@ time_field = '01:01:01' and date_time = '1901-01-01 01:01:01' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref medium_index medium_index 3 const 1 Using where with pushed condition; Using filesort +1 SIMPLE t1 ref medium_index medium_index 3 const # Using where with pushed condition; Using filesort select auto from t1 where string = "aaaa" and vstring = "aaaa" and @@ -925,7 +925,7 @@ time_field != '01:01:01' and date_time != '1901-01-01 01:01:01' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 3 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where string != "aaaa" and vstring != "aaaa" and @@ -984,7 +984,7 @@ time_field > '01:01:01' and date_time > '1901-01-01 01:01:01' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 3 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where string > "aaaa" and vstring > "aaaa" and @@ -1043,7 +1043,7 @@ time_field >= '01:01:01' and date_time >= '1901-01-01 01:01:01' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where string >= "aaaa" and vstring >= "aaaa" and @@ -1103,7 +1103,7 @@ time_field < '04:04:04' and date_time < '1904-04-04 04:04:04' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 3 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where string < "dddd" and vstring < "dddd" and @@ -1162,7 +1162,7 @@ time_field <= '04:04:04' and date_time <= '1904-04-04 04:04:04' order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where string <= "dddd" and vstring <= "dddd" and @@ -1202,7 +1202,7 @@ bin like concat(0xBB, '%') and vbin like concat(0xBB, '%') order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where string like "b%" and vstring like "b%" and @@ -1219,7 +1219,7 @@ bin not like concat(0xBB, '%') and vbin not like concat(0xBB, '%') order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where string not like "b%" and vstring not like "b%" and @@ -1255,7 +1255,7 @@ select auto from t1 where (date_time between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 3 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where (string between "aaaa" and "cccc") and (vstring between "aaaa" and "cccc") and @@ -1307,7 +1307,7 @@ select auto from t1 where ('1901-01-01 01:01:01' between date_time and date_time) order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 1 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where ("aaaa" between string and string) and ("aaaa" between vstring and vstring) and @@ -1358,7 +1358,7 @@ select auto from t1 where (date_time not between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 1 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where (string not between "aaaa" and "cccc") and (vstring not between "aaaa" and "cccc") and @@ -1409,7 +1409,7 @@ select auto from t1 where ('1901-01-01 01:01:01' not between date_time and date_time) order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 3 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where ("aaaa" not between string and string) and ("aaaa" not between vstring and vstring) and @@ -1462,7 +1462,7 @@ time_field in('01:01:01','03:03:03') and date_time in('1901-01-01 01:01:01','1903-03-03 03:03:03') order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 2 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where string in("aaaa","cccc") and vstring in("aaaa","cccc") and @@ -1514,7 +1514,7 @@ select auto from t1 where '1901-01-01 01:01:01' in(date_time) order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ref medium_index medium_index 3 const 1 Using where with pushed condition; Using filesort +1 SIMPLE t1 ref medium_index medium_index 3 const # Using where with pushed condition; Using filesort select auto from t1 where "aaaa" in(string) and "aaaa" in(vstring) and @@ -1565,7 +1565,7 @@ time_field not in('01:01:01','03:03:03') and date_time not in('1901-01-01 01:01:01','1903-03-03 03:03:03') order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range medium_index medium_index 3 NULL 6 Using where with pushed condition; Using filesort +1 SIMPLE t1 range medium_index medium_index 3 NULL # Using where with pushed condition; Using filesort select auto from t1 where string not in("aaaa","cccc") and vstring not in("aaaa","cccc") and @@ -1617,7 +1617,7 @@ select auto from t1 where '1901-01-01 01:01:01' not in(date_time) order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where with pushed condition; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select auto from t1 where "aaaa" not in(string) and "aaaa" not in(vstring) and @@ -1704,7 +1704,7 @@ count(*) explain select * from t2 where attr3 is null or attr1 > 2 and pk1= 3 order by pk1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL PRIMARY NULL NULL NULL 6 Using where with pushed condition; Using filesort +1 SIMPLE t2 ALL PRIMARY NULL NULL NULL # Using where with pushed condition; Using filesort select * from t2 where attr3 is null or attr1 > 2 and pk1= 3 order by pk1; pk1 attr1 attr2 attr3 2 2 NULL NULL @@ -1712,7 +1712,7 @@ pk1 attr1 attr2 attr3 explain select * from t2 where attr3 is not null and attr1 > 2 order by pk1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where with pushed condition; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select * from t2 where attr3 is not null and attr1 > 2 order by pk1; pk1 attr1 attr2 attr3 3 3 3 d @@ -1721,7 +1721,7 @@ pk1 attr1 attr2 attr3 explain select * from t3 where attr2 > 9223372036854775803 and attr3 != 3 order by pk1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where with pushed condition; Using filesort +1 SIMPLE t3 ALL NULL NULL NULL NULL # Using where with pushed condition; Using filesort select * from t3 where attr2 > 9223372036854775803 and attr3 != 3 order by pk1; pk1 attr1 attr2 attr3 attr4 2 2 9223372036854775804 2 c @@ -1730,15 +1730,15 @@ pk1 attr1 attr2 attr3 attr4 explain select * from t2,t3 where t2.attr1 < 1 and t2.attr2 = t3.attr2 and t3.attr1 < 5 order by t2.pk1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where with pushed condition; Using temporary; Using filesort -1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where with pushed condition +1 SIMPLE t2 ALL NULL NULL NULL NULL # Using where with pushed condition; Using temporary; Using filesort +1 SIMPLE t3 ALL NULL NULL NULL NULL # Using where with pushed condition select * from t2,t3 where t2.attr1 < 1 and t2.attr2 = t3.attr2 and t3.attr1 < 5 order by t2.pk1; pk1 attr1 attr2 attr3 pk1 attr1 attr2 attr3 attr4 0 0 0 a 0 0 0 0 a explain select * from t4 where attr1 < 5 and attr2 > 9223372036854775803 and attr3 != 3 order by t4.pk1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t4 range attr1 attr1 4 NULL 5 Using where with pushed condition; Using filesort +1 SIMPLE t4 range attr1 attr1 4 NULL # Using where with pushed condition; Using filesort select * from t4 where attr1 < 5 and attr2 > 9223372036854775803 and attr3 != 3 order by t4.pk1; pk1 attr1 attr2 attr3 attr4 2 2 9223372036854775804 2 c @@ -1746,8 +1746,8 @@ pk1 attr1 attr2 attr3 attr4 explain select * from t3,t4 where t4.attr1 > 1 and t4.attr2 = t3.attr2 and t4.attr3 < 5 order by t4.pk1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t4 range attr1 attr1 4 NULL 4 Using where with pushed condition; Using temporary; Using filesort -1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t4 range attr1 attr1 4 NULL # Using where with pushed condition; Using temporary; Using filesort +1 SIMPLE t3 ALL NULL NULL NULL NULL # Using where select * from t3,t4 where t4.attr1 > 1 and t4.attr2 = t3.attr2 and t4.attr3 < 5 order by t4.pk1; pk1 attr1 attr2 attr3 attr4 pk1 attr1 attr2 attr3 attr4 2 2 9223372036854775804 2 c 2 2 9223372036854775804 2 c @@ -1756,16 +1756,16 @@ pk1 attr1 attr2 attr3 attr4 pk1 attr1 attr2 attr3 attr4 explain select auto from t1 where string = "aaaa" collate latin1_general_ci order by auto; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where; Using filesort +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where; Using filesort explain select * from t2 where (attr1 < 2) = (attr2 < 2) order by pk1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 6 Using where; Using filesort +1 SIMPLE t2 ALL NULL NULL NULL NULL # Using where; Using filesort explain select * from t3 left join t4 on t4.attr2 = t3.attr2 where t4.attr1 > 1 and t4.attr3 < 5 or t4.attr1 is null order by t4.pk1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 ALL NULL NULL NULL NULL 6 Using temporary; Using filesort -1 SIMPLE t4 ALL NULL NULL NULL NULL 6 Using where +1 SIMPLE t3 ALL NULL NULL NULL NULL # Using temporary; Using filesort +1 SIMPLE t4 ALL NULL NULL NULL NULL # Using where create table t5 (a int primary key auto_increment, b tinytext not null) engine = ndb; insert into t5 (b) values ('jonas'), ('jensing'), ('johan'); @@ -1777,7 +1777,7 @@ a b set engine_condition_pushdown = on; explain select * from t5 where b like '%jo%'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t5 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t5 ALL NULL NULL NULL NULL # Using where select * from t5 where b like '%jo%' order by a; a b 1 jonas @@ -1793,13 +1793,13 @@ auto set engine_condition_pushdown = on; explain select auto from t1 where date_time like '1902-02-02 %'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where select auto from t1 where date_time like '1902-02-02 %' order by auto; auto 2 explain select auto from t1 where date_time not like '1902-02-02 %'; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where +1 SIMPLE t1 ALL NULL NULL NULL NULL # Using where select auto from t1 where date_time not like '1902-02-02 %' order by auto; auto 3 diff --git a/mysql-test/r/ndb_dd_sql_features.result b/mysql-test/r/ndb_dd_sql_features.result index d1aba2f182e..135250fe7e8 100644 --- a/mysql-test/r/ndb_dd_sql_features.result +++ b/mysql-test/r/ndb_dd_sql_features.result @@ -441,7 +441,7 @@ INSERT INTO test.t1 values(1,@vc1,@d1); INSERT INTO test.t1 values(2,@vc2,@d2); explain SELECT * from test.t1 WHERE a1 = 1; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 const PRIMARY PRIMARY 4 const 1 +1 SIMPLE t1 const PRIMARY PRIMARY 4 const # SELECT a1,length(a2),substr(a2,1+2*900,2),length(a3),substr(a3,1+3*900,3) FROM test.t1 WHERE a1=1 ORDER BY a1; a1 length(a2) substr(a2,1+2*900,2) length(a3) substr(a3,1+3*900,3) diff --git a/mysql-test/r/ndb_index_ordered.result b/mysql-test/r/ndb_index_ordered.result index b4871180706..3b8415b9267 100644 --- a/mysql-test/r/ndb_index_ordered.result +++ b/mysql-test/r/ndb_index_ordered.result @@ -663,7 +663,7 @@ set autocommit=1; show session variables like 'ndb_index_stat_%'; Variable_name Value ndb_index_stat_cache_entries 32 -ndb_index_stat_enable ON +ndb_index_stat_enable OFF ndb_index_stat_update_freq 20 set ndb_index_stat_enable = off; show session variables like 'ndb_index_stat_%'; @@ -794,5 +794,5 @@ set ndb_index_stat_update_freq = @@global.ndb_index_stat_update_freq; show session variables like 'ndb_index_stat_%'; Variable_name Value ndb_index_stat_cache_entries 32 -ndb_index_stat_enable ON +ndb_index_stat_enable OFF ndb_index_stat_update_freq 20 diff --git a/mysql-test/r/ndb_index_unique.result b/mysql-test/r/ndb_index_unique.result index 88c6e00e215..563024a8800 100644 --- a/mysql-test/r/ndb_index_unique.result +++ b/mysql-test/r/ndb_index_unique.result @@ -22,7 +22,7 @@ select * from t1 where b = 4 order by a; a b c 3 4 6 insert into t1 values(8, 2, 3); -ERROR 23000: Duplicate entry '8' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' select * from t1 order by a; a b c 1 2 3 @@ -93,7 +93,7 @@ a b c 1 1 1 4 4 NULL insert into t1 values(5,1,1); -ERROR 23000: Duplicate entry '5' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' drop table t1; CREATE TABLE t2 ( a int unsigned NOT NULL PRIMARY KEY, @@ -116,7 +116,7 @@ select * from t2 where b = 4 order by a; a b c 3 4 6 insert into t2 values(8, 2, 3); -ERROR 23000: Duplicate entry '8' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' select * from t2 order by a; a b c 1 2 3 @@ -181,7 +181,7 @@ pk a 3 NULL 4 4 insert into t1 values (5,0); -ERROR 23000: Duplicate entry '5' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' select * from t1 order by pk; pk a -1 NULL @@ -214,7 +214,7 @@ pk a b c 0 NULL 18 NULL 1 3 19 abc insert into t2 values(2,3,19,'abc'); -ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' select * from t2 order by pk; pk a b c -1 1 17 NULL @@ -634,8 +634,11 @@ create table t1 (a int primary key, b varchar(1000) not null, unique key (b)) engine=ndb charset=utf8; insert into t1 values (1, repeat(_utf8 0xe288ab6474, 200)); insert into t1 values (2, repeat(_utf8 0xe288ab6474, 200)); -ERROR 23000: Duplicate entry '2' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' select a, sha1(b) from t1; a sha1(b) 1 08f5d02c8b8bc244f275bdfc22c42c5cab0d9d7d drop table t1; +create table t1(id int not null) engine = NDB; +alter table t1 add constraint uk_test unique (id) using hash; +drop table t1; diff --git a/mysql-test/r/ndb_multi.result b/mysql-test/r/ndb_multi.result index c73d09b6541..1c9633589e0 100644 --- a/mysql-test/r/ndb_multi.result +++ b/mysql-test/r/ndb_multi.result @@ -32,6 +32,9 @@ insert into t1 value (2); select * from t1; a 2 +select * from t1; +a +2 flush status; select * from t1; a diff --git a/mysql-test/r/ndb_subquery.result b/mysql-test/r/ndb_subquery.result index b19571b05c1..312711ab4b7 100644 --- a/mysql-test/r/ndb_subquery.result +++ b/mysql-test/r/ndb_subquery.result @@ -8,32 +8,32 @@ insert into t1 values (1,1,1),(2,2,2),(3,3,3); insert into t2 values (1,1,1),(2,2,2),(3,3,3), (4,4,4), (5,5,5); explain select * from t2 where p NOT IN (select p from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where -2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func 1 Using index +1 PRIMARY t2 ALL NULL NULL NULL NULL # Using where +2 DEPENDENT SUBQUERY t1 unique_subquery PRIMARY PRIMARY 4 func # Using index select * from t2 where p NOT IN (select p from t1) order by p; p u o 4 4 4 5 5 5 explain select * from t2 where p NOT IN (select u from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where -2 DEPENDENT SUBQUERY t1 unique_subquery u u 4 func 1 Using index +1 PRIMARY t2 ALL NULL NULL NULL NULL # Using where +2 DEPENDENT SUBQUERY t1 unique_subquery u u 4 func # Using index select * from t2 where p NOT IN (select u from t1) order by p; p u o 4 4 4 5 5 5 explain select * from t2 where p NOT IN (select o from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where -2 DEPENDENT SUBQUERY t1 index_subquery o o 4 func 1 Using index +1 PRIMARY t2 ALL NULL NULL NULL NULL # Using where +2 DEPENDENT SUBQUERY t1 index_subquery o o 4 func # Using index select * from t2 where p NOT IN (select o from t1) order by p; p u o 4 4 4 5 5 5 explain select * from t2 where p NOT IN (select p+0 from t1); id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t2 ALL NULL NULL NULL NULL 5 Using where -2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t2 ALL NULL NULL NULL NULL # Using where +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL # Using where select * from t2 where p NOT IN (select p+0 from t1) order by p; p u o 4 4 4 diff --git a/mysql-test/r/ndb_update.result b/mysql-test/r/ndb_update.result index ea6eb1644f2..8166a554084 100644 --- a/mysql-test/r/ndb_update.result +++ b/mysql-test/r/ndb_update.result @@ -18,7 +18,7 @@ pk1 b c 2 2 2 4 1 1 UPDATE t1 set pk1 = 1, c = 2 where pk1 = 4; -ERROR 23000: Duplicate entry '1' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' select * from t1 order by pk1; pk1 b c 0 0 0 diff --git a/mysql-test/r/not_partition.require b/mysql-test/r/not_partition.require new file mode 100644 index 00000000000..808242277cb --- /dev/null +++ b/mysql-test/r/not_partition.require @@ -0,0 +1,2 @@ +Variable_name Value +have_partitioning NO diff --git a/mysql-test/r/not_partition.result b/mysql-test/r/not_partition.result new file mode 100644 index 00000000000..9e205a09d78 --- /dev/null +++ b/mysql-test/r/not_partition.result @@ -0,0 +1,48 @@ +CREATE TABLE t1 ( +firstname VARCHAR(25) NOT NULL, +lastname VARCHAR(25) NOT NULL, +username VARCHAR(16) NOT NULL, +email VARCHAR(35), +joined DATE NOT NULL +) +PARTITION BY KEY(joined) +PARTITIONS 6; +ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-partition' to have it working +ALTER TABLE t1 PARTITION BY KEY(joined) PARTITIONS 2; +ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-partition' to have it working +drop table t1; +ERROR 42S02: Unknown table 't1' +CREATE TABLE t1 ( +firstname VARCHAR(25) NOT NULL, +lastname VARCHAR(25) NOT NULL, +username VARCHAR(16) NOT NULL, +email VARCHAR(35), +joined DATE NOT NULL +) +PARTITION BY RANGE( YEAR(joined) ) ( +PARTITION p0 VALUES LESS THAN (1960), +PARTITION p1 VALUES LESS THAN (1970), +PARTITION p2 VALUES LESS THAN (1980), +PARTITION p3 VALUES LESS THAN (1990), +PARTITION p4 VALUES LESS THAN MAXVALUE +); +ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-partition' to have it working +drop table t1; +ERROR 42S02: Unknown table 't1' +CREATE TABLE t1 (id INT, purchased DATE) +PARTITION BY RANGE( YEAR(purchased) ) +SUBPARTITION BY HASH( TO_DAYS(purchased) ) +SUBPARTITIONS 2 ( +PARTITION p0 VALUES LESS THAN (1990), +PARTITION p1 VALUES LESS THAN (2000), +PARTITION p2 VALUES LESS THAN MAXVALUE +); +ERROR HY000: The 'partitioning' feature is disabled; you need MySQL built with '--with-partition' to have it working +drop table t1; +ERROR 42S02: Unknown table 't1' +create table t1 (a varchar(10) charset latin1 collate latin1_bin); +insert into t1 values (''),(' '),('a'),('a '),('a '); +explain partitions select * from t1 where a='a ' OR a='a'; +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 5 Using where +drop table t1; diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index f3e44a1df60..5a8f5a3137d 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1090,41 +1090,15 @@ drop table t1; create table t1 (a int) engine myisam partition by range (a) subpartition by hash (a) -(partition p0 VALUES LESS THAN (1) DATA DIRECTORY = 'hello/master-data/tmpdata' INDEX DIRECTORY = 'hello/master-data/tmpinx' +(partition p0 VALUES LESS THAN (1) DATA DIRECTORY = 'MYSQLTEST_VARDIR/master-data/tmpdata' INDEX DIRECTORY = 'MYSQLTEST_VARDIR/master-data/tmpinx' (SUBPARTITION subpart00, SUBPARTITION subpart01)); -hello/master-data/test/t1.frm -hello/master-data/test/t1.par -hello/master-data/test/t1#P#p0#SP#subpart00.MYD -hello/master-data/test/t1#P#p0#SP#subpart00.MYI -hello/master-data/test/t1#P#p0#SP#subpart01.MYD -hello/master-data/test/t1#P#p0#SP#subpart01.MYI -hello/master-data/tmpdata/t1#P#p0#SP#subpart00.MYD -hello/master-data/tmpdata/t1#P#p0#SP#subpart01.MYD -hello/master-data/tmpinx/t1#P#p0#SP#subpart00.MYI -hello/master-data/tmpinx/t1#P#p0#SP#subpart01.MYI +Checking if file exists before alter ALTER TABLE t1 REORGANIZE PARTITION p0 INTO -(partition p1 VALUES LESS THAN (1) DATA DIRECTORY = 'hello/master-data/tmpdata' INDEX DIRECTORY = 'hello/master-data/tmpinx' +(partition p1 VALUES LESS THAN (1) DATA DIRECTORY = 'MYSQLTEST_VARDIR/master-data/tmpdata' INDEX DIRECTORY = 'MYSQLTEST_VARDIR/master-data/tmpinx' (SUBPARTITION subpart10, SUBPARTITION subpart11), -partition p2 VALUES LESS THAN (2) DATA DIRECTORY = 'hello/master-data/tmpdata' INDEX DIRECTORY = 'hello/master-data/tmpinx' +partition p2 VALUES LESS THAN (2) DATA DIRECTORY = 'MYSQLTEST_VARDIR/master-data/tmpdata' INDEX DIRECTORY = 'MYSQLTEST_VARDIR/master-data/tmpinx' (SUBPARTITION subpart20, SUBPARTITION subpart21)); -hello/master-data/test/t1.frm -hello/master-data/test/t1.par -hello/master-data/test/t1#P#p1#SP#subpart10.MYD -hello/master-data/test/t1#P#p1#SP#subpart10.MYI -hello/master-data/test/t1#P#p1#SP#subpart11.MYD -hello/master-data/test/t1#P#p1#SP#subpart11.MYI -hello/master-data/test/t1#P#p2#SP#subpart20.MYD -hello/master-data/test/t1#P#p2#SP#subpart20.MYI -hello/master-data/test/t1#P#p2#SP#subpart21.MYD -hello/master-data/test/t1#P#p2#SP#subpart21.MYI -hello/master-data/tmpdata/t1#P#p1#SP#subpart10.MYD -hello/master-data/tmpdata/t1#P#p1#SP#subpart11.MYD -hello/master-data/tmpdata/t1#P#p2#SP#subpart20.MYD -hello/master-data/tmpdata/t1#P#p2#SP#subpart21.MYD -hello/master-data/tmpinx/t1#P#p1#SP#subpart10.MYI -hello/master-data/tmpinx/t1#P#p1#SP#subpart11.MYI -hello/master-data/tmpinx/t1#P#p2#SP#subpart20.MYI -hello/master-data/tmpinx/t1#P#p2#SP#subpart21.MYI +Checking if file exists after alter drop table t1; create table t1 (a bigint unsigned not null, primary key(a)) engine = myisam diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index b7dae03bf47..a2d0782ede3 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -499,54 +499,6 @@ create temporary table if not exists t1 (a1 int); execute stmt; drop temporary table t1; deallocate prepare stmt; -CREATE TABLE t1( -ID int(10) unsigned NOT NULL auto_increment, -Member_ID varchar(15) NOT NULL default '', -Action varchar(12) NOT NULL, -Action_Date datetime NOT NULL, -Track varchar(15) default NULL, -User varchar(12) default NULL, -Date_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update -CURRENT_TIMESTAMP, -PRIMARY KEY (ID), -KEY Action (Action), -KEY Action_Date (Action_Date) -); -INSERT INTO t1(Member_ID, Action, Action_Date, Track) VALUES -('111111', 'Disenrolled', '2006-03-01', 'CAD' ), -('111111', 'Enrolled', '2006-03-01', 'CAD' ), -('111111', 'Disenrolled', '2006-07-03', 'CAD' ), -('222222', 'Enrolled', '2006-03-07', 'CAD' ), -('222222', 'Enrolled', '2006-03-07', 'CHF' ), -('222222', 'Disenrolled', '2006-08-02', 'CHF' ), -('333333', 'Enrolled', '2006-03-01', 'CAD' ), -('333333', 'Disenrolled', '2006-03-01', 'CAD' ), -('444444', 'Enrolled', '2006-03-01', 'CAD' ), -('555555', 'Disenrolled', '2006-03-01', 'CAD' ), -('555555', 'Enrolled', '2006-07-21', 'CAD' ), -('555555', 'Disenrolled', '2006-03-01', 'CHF' ), -('666666', 'Enrolled', '2006-02-09', 'CAD' ), -('666666', 'Enrolled', '2006-05-12', 'CHF' ), -('666666', 'Disenrolled', '2006-06-01', 'CAD' ); -PREPARE STMT FROM -"SELECT GROUP_CONCAT(Track SEPARATOR ', ') FROM t1 - WHERE Member_ID=? AND Action='Enrolled' AND - (Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t1 - WHERE Member_ID=? - GROUP BY Track - HAVING Track>='CAD' AND - MAX(Action_Date)>'2006-03-01')"; -SET @id='111111'; -EXECUTE STMT USING @id,@id; -GROUP_CONCAT(Track SEPARATOR ', ') -NULL -SET @id='222222'; -EXECUTE STMT USING @id,@id; -GROUP_CONCAT(Track SEPARATOR ', ') -CAD -DEALLOCATE PREPARE STMT; -DROP TABLE t1; -End of 4.1 tests create table t1 (a varchar(20)); insert into t1 values ('foo'); prepare stmt FROM 'SELECT char_length (a) FROM t1'; @@ -564,77 +516,6 @@ SELECT FOUND_ROWS(); FOUND_ROWS() 2 deallocate prepare stmt; -create table t1 (a char(3) not null, b char(3) not null, -c char(3) not null, primary key (a, b, c)); -create table t2 like t1; -prepare stmt from -"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b) - where t1.a=1"; -execute stmt; -a -execute stmt; -a -execute stmt; -a -prepare stmt from -"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from -(t1 left outer join t2 on t2.a=? and t1.b=t2.b) -left outer join t2 t3 on t3.a=? where t1.a=?"; -set @a:=1, @b:=1, @c:=1; -execute stmt using @a, @b, @c; -a b c a b c -execute stmt using @a, @b, @c; -a b c a b c -execute stmt using @a, @b, @c; -a b c a b c -deallocate prepare stmt; -drop table t1,t2; -SET @aux= "SELECT COUNT(*) - FROM INFORMATION_SCHEMA.COLUMNS A, - INFORMATION_SCHEMA.COLUMNS B - WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA - AND A.TABLE_NAME = B.TABLE_NAME - AND A.COLUMN_NAME = B.COLUMN_NAME AND - A.TABLE_NAME = 'user'"; -prepare my_stmt from @aux; -execute my_stmt; -COUNT(*) -39 -execute my_stmt; -COUNT(*) -39 -execute my_stmt; -COUNT(*) -39 -deallocate prepare my_stmt; -drop procedure if exists p1| -drop table if exists t1| -create table t1 (id int)| -insert into t1 values(1)| -create procedure p1(a int, b int) -begin -declare c int; -select max(id)+1 into c from t1; -insert into t1 select a+b; -insert into t1 select a-b; -insert into t1 select a-c; -end| -set @a= 3, @b= 4| -prepare stmt from "call p1(?, ?)"| -execute stmt using @a, @b| -execute stmt using @a, @b| -select * from t1| -id -1 -7 --1 -1 -7 --1 --5 -deallocate prepare stmt| -drop procedure p1| -drop table t1| drop table if exists t1; Warnings: Note 1051 Unknown table 't1' @@ -698,47 +579,6 @@ id 3 deallocate prepare stmt; drop table t1, t2; -create table t1 (a int); -insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); -prepare stmt from "select * from t1 limit ?, ?"; -set @offset=0, @limit=1; -execute stmt using @offset, @limit; -a -1 -select * from t1 limit 0, 1; -a -1 -set @offset=3, @limit=2; -execute stmt using @offset, @limit; -a -4 -5 -select * from t1 limit 3, 2; -a -4 -5 -prepare stmt from "select * from t1 limit ?"; -execute stmt using @limit; -a -1 -2 -prepare stmt from "select * from t1 where a in (select a from t1 limit ?)"; -ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' -prepare stmt from "select * from t1 union all select * from t1 limit ?, ?"; -set @offset=9; -set @limit=2; -execute stmt using @offset, @limit; -a -10 -1 -prepare stmt from "(select * from t1 limit ?, ?) union all - (select * from t1 limit ?, ?) order by a limit ?"; -execute stmt using @offset, @limit, @offset, @limit, @limit; -a -10 -10 -drop table t1; -deallocate prepare stmt; create table t1 (id int); prepare stmt from "insert into t1 (id) select id from t1 union select id from t1"; execute stmt; @@ -839,15 +679,6 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp select ? from t1; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? from t1' at line 1 drop table t1; -CREATE TABLE b12651_T1(a int) ENGINE=MYISAM; -CREATE TABLE b12651_T2(b int) ENGINE=MYISAM; -CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2; -PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)'; -EXECUTE b12651; -1 -DROP VIEW b12651_V1; -DROP TABLE b12651_T1, b12651_T2; -DEALLOCATE PREPARE b12651; prepare stmt from "select @@time_zone"; execute stmt; @@time_zone @@ -1064,6 +895,290 @@ select @@max_prepared_stmt_count, @@prepared_stmt_count; @@max_prepared_stmt_count @@prepared_stmt_count 3 0 set global max_prepared_stmt_count= @old_max_prepared_stmt_count; +drop table if exists t1; +create temporary table if not exists t1 (a1 int); +prepare stmt from "delete t1 from t1 where (cast(a1/3 as unsigned) * 3) = a1"; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +create temporary table if not exists t1 (a1 int); +execute stmt; +drop temporary table t1; +deallocate prepare stmt; +CREATE TABLE t1( +ID int(10) unsigned NOT NULL auto_increment, +Member_ID varchar(15) NOT NULL default '', +Action varchar(12) NOT NULL, +Action_Date datetime NOT NULL, +Track varchar(15) default NULL, +User varchar(12) default NULL, +Date_Updated timestamp NOT NULL default CURRENT_TIMESTAMP on update +CURRENT_TIMESTAMP, +PRIMARY KEY (ID), +KEY Action (Action), +KEY Action_Date (Action_Date) +); +INSERT INTO t1(Member_ID, Action, Action_Date, Track) VALUES +('111111', 'Disenrolled', '2006-03-01', 'CAD' ), +('111111', 'Enrolled', '2006-03-01', 'CAD' ), +('111111', 'Disenrolled', '2006-07-03', 'CAD' ), +('222222', 'Enrolled', '2006-03-07', 'CAD' ), +('222222', 'Enrolled', '2006-03-07', 'CHF' ), +('222222', 'Disenrolled', '2006-08-02', 'CHF' ), +('333333', 'Enrolled', '2006-03-01', 'CAD' ), +('333333', 'Disenrolled', '2006-03-01', 'CAD' ), +('444444', 'Enrolled', '2006-03-01', 'CAD' ), +('555555', 'Disenrolled', '2006-03-01', 'CAD' ), +('555555', 'Enrolled', '2006-07-21', 'CAD' ), +('555555', 'Disenrolled', '2006-03-01', 'CHF' ), +('666666', 'Enrolled', '2006-02-09', 'CAD' ), +('666666', 'Enrolled', '2006-05-12', 'CHF' ), +('666666', 'Disenrolled', '2006-06-01', 'CAD' ); +PREPARE STMT FROM +"SELECT GROUP_CONCAT(Track SEPARATOR ', ') FROM t1 + WHERE Member_ID=? AND Action='Enrolled' AND + (Track,Action_Date) IN (SELECT Track, MAX(Action_Date) FROM t1 + WHERE Member_ID=? + GROUP BY Track + HAVING Track>='CAD' AND + MAX(Action_Date)>'2006-03-01')"; +SET @id='111111'; +EXECUTE STMT USING @id,@id; +GROUP_CONCAT(Track SEPARATOR ', ') +NULL +SET @id='222222'; +EXECUTE STMT USING @id,@id; +GROUP_CONCAT(Track SEPARATOR ', ') +CAD +DEALLOCATE PREPARE STMT; +DROP TABLE t1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT, INDEX(i)); +INSERT INTO t1 VALUES (1); +PREPARE stmt FROM "SELECT (COUNT(i) = 1), COUNT(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +(COUNT(i) = 1) COUNT(i) +0 0 +SET @a = 1; +EXECUTE stmt USING @a; +(COUNT(i) = 1) COUNT(i) +1 1 +SET @a = 0; +EXECUTE stmt USING @a; +(COUNT(i) = 1) COUNT(i) +0 0 +PREPARE stmt FROM "SELECT (AVG(i) = 1), AVG(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +(AVG(i) = 1) AVG(i) +NULL NULL +SET @a = 1; +EXECUTE stmt USING @a; +(AVG(i) = 1) AVG(i) +1 1.0000 +SET @a = 0; +EXECUTE stmt USING @a; +(AVG(i) = 1) AVG(i) +NULL NULL +PREPARE stmt FROM "SELECT (VARIANCE(i) = 1), VARIANCE(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +(VARIANCE(i) = 1) VARIANCE(i) +NULL NULL +SET @a = 1; +EXECUTE stmt USING @a; +(VARIANCE(i) = 1) VARIANCE(i) +0 0.0000 +SET @a = 0; +EXECUTE stmt USING @a; +(VARIANCE(i) = 1) VARIANCE(i) +NULL NULL +PREPARE stmt FROM "SELECT (STDDEV(i) = 1), STDDEV(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +(STDDEV(i) = 1) STDDEV(i) +NULL NULL +SET @a = 1; +EXECUTE stmt USING @a; +(STDDEV(i) = 1) STDDEV(i) +0 0.0000 +SET @a = 0; +EXECUTE stmt USING @a; +(STDDEV(i) = 1) STDDEV(i) +NULL NULL +PREPARE stmt FROM "SELECT (BIT_OR(i) = 1), BIT_OR(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +(BIT_OR(i) = 1) BIT_OR(i) +0 0 +SET @a = 1; +EXECUTE stmt USING @a; +(BIT_OR(i) = 1) BIT_OR(i) +1 1 +SET @a = 0; +EXECUTE stmt USING @a; +(BIT_OR(i) = 1) BIT_OR(i) +0 0 +PREPARE stmt FROM "SELECT (BIT_AND(i) = 1), BIT_AND(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +(BIT_AND(i) = 1) BIT_AND(i) +0 18446744073709551615 +SET @a = 1; +EXECUTE stmt USING @a; +(BIT_AND(i) = 1) BIT_AND(i) +1 1 +SET @a = 0; +EXECUTE stmt USING @a; +(BIT_AND(i) = 1) BIT_AND(i) +0 18446744073709551615 +PREPARE stmt FROM "SELECT (BIT_XOR(i) = 1), BIT_XOR(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +(BIT_XOR(i) = 1) BIT_XOR(i) +0 0 +SET @a = 1; +EXECUTE stmt USING @a; +(BIT_XOR(i) = 1) BIT_XOR(i) +1 1 +SET @a = 0; +EXECUTE stmt USING @a; +(BIT_XOR(i) = 1) BIT_XOR(i) +0 0 +DEALLOCATE PREPARE stmt; +DROP TABLE t1; +End of 4.1 tests. +create table t1 (a varchar(20)); +insert into t1 values ('foo'); +prepare stmt FROM 'SELECT char_length (a) FROM t1'; +ERROR 42000: FUNCTION test.char_length does not exist +drop table t1; +create table t1 (a char(3) not null, b char(3) not null, +c char(3) not null, primary key (a, b, c)); +create table t2 like t1; +prepare stmt from +"select t1.a from (t1 left outer join t2 on t2.a=1 and t1.b=t2.b) + where t1.a=1"; +execute stmt; +a +execute stmt; +a +execute stmt; +a +prepare stmt from +"select t1.a, t1.b, t1.c, t2.a, t2.b, t2.c from +(t1 left outer join t2 on t2.a=? and t1.b=t2.b) +left outer join t2 t3 on t3.a=? where t1.a=?"; +set @a:=1, @b:=1, @c:=1; +execute stmt using @a, @b, @c; +a b c a b c +execute stmt using @a, @b, @c; +a b c a b c +execute stmt using @a, @b, @c; +a b c a b c +deallocate prepare stmt; +drop table t1,t2; +SET @aux= "SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS A, + INFORMATION_SCHEMA.COLUMNS B + WHERE A.TABLE_SCHEMA = B.TABLE_SCHEMA + AND A.TABLE_NAME = B.TABLE_NAME + AND A.COLUMN_NAME = B.COLUMN_NAME AND + A.TABLE_NAME = 'user'"; +prepare my_stmt from @aux; +execute my_stmt; +COUNT(*) +39 +execute my_stmt; +COUNT(*) +39 +execute my_stmt; +COUNT(*) +39 +deallocate prepare my_stmt; +drop procedure if exists p1| +drop table if exists t1| +create table t1 (id int)| +insert into t1 values(1)| +create procedure p1(a int, b int) +begin +declare c int; +select max(id)+1 into c from t1; +insert into t1 select a+b; +insert into t1 select a-b; +insert into t1 select a-c; +end| +set @a= 3, @b= 4| +prepare stmt from "call p1(?, ?)"| +execute stmt using @a, @b| +execute stmt using @a, @b| +select * from t1| +id +1 +7 +-1 +1 +7 +-1 +-5 +deallocate prepare stmt| +drop procedure p1| +drop table t1| +create table t1 (a int); +insert into t1 (a) values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10); +prepare stmt from "select * from t1 limit ?, ?"; +set @offset=0, @limit=1; +execute stmt using @offset, @limit; +a +1 +select * from t1 limit 0, 1; +a +1 +set @offset=3, @limit=2; +execute stmt using @offset, @limit; +a +4 +5 +select * from t1 limit 3, 2; +a +4 +5 +prepare stmt from "select * from t1 limit ?"; +execute stmt using @limit; +a +1 +2 +prepare stmt from "select * from t1 where a in (select a from t1 limit ?)"; +ERROR 42000: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' +prepare stmt from "select * from t1 union all select * from t1 limit ?, ?"; +set @offset=9; +set @limit=2; +execute stmt using @offset, @limit; +a +10 +1 +prepare stmt from "(select * from t1 limit ?, ?) union all + (select * from t1 limit ?, ?) order by a limit ?"; +execute stmt using @offset, @limit, @offset, @limit, @limit; +a +10 +10 +drop table t1; +deallocate prepare stmt; +CREATE TABLE b12651_T1(a int) ENGINE=MYISAM; +CREATE TABLE b12651_T2(b int) ENGINE=MYISAM; +CREATE VIEW b12651_V1 as SELECT b FROM b12651_T2; +PREPARE b12651 FROM 'SELECT 1 FROM b12651_T1 WHERE a IN (SELECT b FROM b12651_V1)'; +EXECUTE b12651; +1 +DROP VIEW b12651_V1; +DROP TABLE b12651_T1, b12651_T2; +DEALLOCATE PREPARE b12651; create table t1 (id int); prepare ins_call from "insert into t1 (id) values (1)"; execute ins_call; @@ -1360,27 +1475,49 @@ i 1 DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; +DROP PROCEDURE IF EXISTS p1; +flush status; +prepare sq from 'show status like "slow_queries"'; +execute sq; +Variable_name Value +Slow_queries 0 +prepare no_index from 'select 1 from information_schema.tables limit 1'; +execute sq; +Variable_name Value +Slow_queries 0 +execute no_index; +1 +1 +execute sq; +Variable_name Value +Slow_queries 1 +deallocate prepare no_index; +deallocate prepare sq; End of 5.0 tests. create procedure proc_1() reset query cache; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin reset query cache; return 1; end| +ERROR 0A000: RESET is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 0A000: FLUSH is not allowed in stored function or trigger +ERROR 0A000: RESET is not allowed in stored function or trigger drop function func_1; +drop procedure proc_1; prepare abc from "reset query cache"; execute abc; execute abc; execute abc; deallocate prepare abc; create procedure proc_1() reset master; -drop procedure proc_1; create function func_1() returns int begin reset master; return 1; end| +ERROR 0A000: RESET is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 0A000: FLUSH is not allowed in stored function or trigger +ERROR 0A000: RESET is not allowed in stored function or trigger drop function func_1; +drop procedure proc_1; prepare abc from "reset master"; execute abc; execute abc; @@ -1390,11 +1527,13 @@ create procedure proc_1() reset slave; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin reset slave; return 1; end| +ERROR 0A000: RESET is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 0A000: FLUSH is not allowed in stored function or trigger +ERROR 0A000: RESET is not allowed in stored function or trigger drop function func_1; +drop procedure proc_1; prepare abc from "reset slave"; execute abc; execute abc; @@ -1429,13 +1568,13 @@ call proc_1(); call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin flush hosts; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush hosts"; execute abc; execute abc; @@ -1445,13 +1584,13 @@ create procedure proc_1() flush privileges; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin flush privileges; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush privileges"; deallocate prepare abc; create procedure proc_1() flush tables with read lock; @@ -1461,9 +1600,13 @@ call proc_1(); unlock tables; call proc_1(); unlock tables; -drop procedure proc_1; create function func_1() returns int begin flush tables with read lock; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| +select func_1(), func_1(), func_1() from dual; +ERROR 0A000: FLUSH is not allowed in stored function or trigger +drop function func_1; +drop procedure proc_1; prepare abc from "flush tables with read lock"; execute abc; execute abc; @@ -1474,13 +1617,13 @@ create procedure proc_1() flush tables; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin flush tables; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush tables"; execute abc; execute abc; @@ -1491,62 +1634,70 @@ flush tables; show open tables from mysql; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 select Host, User from mysql.user limit 0; Host User select Host, Db from mysql.host limit 0; Host Db show open tables from mysql; Database Table In_use Name_locked -mysql user 0 0 mysql general_log 1 0 +mysql slow_log 1 0 mysql host 0 0 +mysql user 0 0 call proc_1(); show open tables from mysql; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 select Host, User from mysql.user limit 0; Host User select Host, Db from mysql.host limit 0; Host Db show open tables from mysql; Database Table In_use Name_locked -mysql user 0 0 mysql general_log 1 0 +mysql slow_log 1 0 mysql host 0 0 +mysql user 0 0 call proc_1(); show open tables from mysql; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 select Host, User from mysql.user limit 0; Host User select Host, Db from mysql.host limit 0; Host Db show open tables from mysql; Database Table In_use Name_locked -mysql user 0 0 mysql general_log 1 0 +mysql slow_log 1 0 mysql host 0 0 +mysql user 0 0 call proc_1(); show open tables from mysql; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 select Host, User from mysql.user limit 0; Host User select Host, Db from mysql.host limit 0; Host Db show open tables from mysql; Database Table In_use Name_locked -mysql user 0 0 mysql general_log 1 0 +mysql slow_log 1 0 mysql host 0 0 +mysql user 0 0 flush tables; -drop procedure proc_1; create function func_1() returns int begin flush tables; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; flush tables; select Host, User from mysql.user limit 0; Host User @@ -1554,62 +1705,69 @@ select Host, Db from mysql.host limit 0; Host Db show open tables from mysql; Database Table In_use Name_locked -mysql user 0 0 mysql general_log 1 0 +mysql slow_log 1 0 mysql host 0 0 +mysql user 0 0 prepare abc from "flush tables"; execute abc; show open tables from mysql; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 select Host, User from mysql.user limit 0; Host User select Host, Db from mysql.host limit 0; Host Db show open tables from mysql; Database Table In_use Name_locked -mysql user 0 0 mysql general_log 1 0 +mysql slow_log 1 0 mysql host 0 0 +mysql user 0 0 execute abc; show open tables from mysql; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 select Host, User from mysql.user limit 0; Host User select Host, Db from mysql.host limit 0; Host Db show open tables from mysql; Database Table In_use Name_locked -mysql user 0 0 mysql general_log 1 0 +mysql slow_log 1 0 mysql host 0 0 +mysql user 0 0 execute abc; show open tables from mysql; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 select Host, User from mysql.user limit 0; Host User select Host, Db from mysql.host limit 0; Host Db show open tables from mysql; Database Table In_use Name_locked -mysql user 0 0 mysql general_log 1 0 +mysql slow_log 1 0 mysql host 0 0 +mysql user 0 0 flush tables; deallocate prepare abc; create procedure proc_1() flush logs; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin flush logs; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush logs"; execute abc; execute abc; @@ -1619,13 +1777,13 @@ create procedure proc_1() flush status; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin flush status; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush status"; execute abc; execute abc; @@ -1635,39 +1793,39 @@ create procedure proc_1() flush slave; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin flush slave; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush slave"; execute abc; execute abc; execute abc; deallocate prepare abc; create procedure proc_1() flush master; -drop procedure proc_1; create function func_1() returns int begin flush master; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush master"; deallocate prepare abc; create procedure proc_1() flush des_key_file; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin flush des_key_file; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush des_key_file"; execute abc; execute abc; @@ -1677,13 +1835,13 @@ create procedure proc_1() flush user_resources; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; create function func_1() returns int begin flush user_resources; return 1; end| ERROR 0A000: FLUSH is not allowed in stored function or trigger +create function func_1() returns int begin call proc_1(); return 1; end| select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist +ERROR 0A000: FLUSH is not allowed in stored function or trigger drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist +drop procedure proc_1; prepare abc from "flush user_resources"; execute abc; execute abc; @@ -1763,18 +1921,6 @@ Db Name Definer Type Execute at Interval value Interval field Starts Ends Status execute abc; Db Name Definer Type Execute at Interval value Interval field Starts Ends Status deallocate prepare abc; -create procedure proc_1() show scheduler status; -drop procedure proc_1; -create function func_1() returns int begin show scheduler status; return 1; end| -ERROR 0A000: Not allowed to return a result set from a function -select func_1(), func_1(), func_1() from dual; -ERROR 42000: FUNCTION test.func_1 does not exist -drop function func_1; -ERROR 42000: FUNCTION test.func_1 does not exist -prepare abc from "show scheduler status"; -ERROR HY000: This command is not supported in the prepared statement protocol yet -deallocate prepare abc; -ERROR HY000: Unknown prepared statement handler (abc) given to DEALLOCATE PREPARE drop procedure if exists a; create procedure a() select 42; create procedure proc_1(a char(2)) show create procedure a; @@ -1952,11 +2098,11 @@ ERROR HY000: No paths allowed for shared library drop procedure proc_1; create procedure proc_1() install plugin my_plug soname 'some_plugin.so'; call proc_1(); -ERROR HY000: Can't open shared library '/work/mysql-5.1-runtime/mysql-test/lib/mysql/some_plugin.so' (errno: 0 cannot open shared object file: No such file or directory) +ERROR HY000: Can't open shared library call proc_1(); -ERROR HY000: Can't open shared library '/work/mysql-5.1-runtime/mysql-test/lib/mysql/some_plugin.so' (errno: 22 cannot open shared object file: No such file or directory) +ERROR HY000: Can't open shared library call proc_1(); -ERROR HY000: Can't open shared library '/work/mysql-5.1-runtime/mysql-test/lib/mysql/some_plugin.so' (errno: 22 cannot open shared object file: No such file or directory) +ERROR HY000: Can't open shared library drop procedure proc_1; create function func_1() returns int begin install plugin my_plug soname '/tmp/plugin'; return 1; end| ERROR HY000: Explicit or implicit commit is not allowed in stored function or trigger. @@ -2086,7 +2232,7 @@ drop user pstest_xyz@localhost; deallocate prepare abc; drop event if exists xyz; create function func_1() returns int begin create event xyz on schedule at now() do select 123; return 1; end| -ERROR 0A000: Not allowed to return a result set from a function +ERROR HY000: Recursivity of EVENT DDL statements is forbidden when body is present select func_1(), func_1(), func_1() from dual; ERROR 42000: FUNCTION test.func_1 does not exist drop function func_1; diff --git a/mysql-test/r/ps_11bugs.result b/mysql-test/r/ps_11bugs.result index c849c25d646..ebe161f46b3 100644 --- a/mysql-test/r/ps_11bugs.result +++ b/mysql-test/r/ps_11bugs.result @@ -130,3 +130,36 @@ prepare st_18492 from 'select * from t1 where 3 in (select (1+1) union select 1) execute st_18492; a drop table t1; +create table t1 (a int, b varchar(4)); +create table t2 (a int, b varchar(4), primary key(a)); +prepare stmt1 from 'insert into t1 (a, b) values (?, ?)'; +prepare stmt2 from 'insert into t2 (a, b) values (?, ?)'; +set @intarg= 11; +set @varchararg= '2222'; +execute stmt1 using @intarg, @varchararg; +execute stmt2 using @intarg, @varchararg; +set @intarg= 12; +execute stmt1 using @intarg, @UNDEFINED; +execute stmt2 using @intarg, @UNDEFINED; +set @intarg= 13; +execute stmt1 using @UNDEFINED, @varchararg; +execute stmt2 using @UNDEFINED, @varchararg; +ERROR 23000: Column 'a' cannot be null +set @intarg= 14; +set @nullarg= Null; +execute stmt1 using @UNDEFINED, @nullarg; +execute stmt2 using @nullarg, @varchararg; +ERROR 23000: Column 'a' cannot be null +select * from t1; +a b +11 2222 +12 NULL +NULL 2222 +NULL NULL +select * from t2; +a b +11 2222 +12 NULL +drop table t1; +drop table t2; +End of 5.0 tests. diff --git a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result index 96289305da1..d5996ee8163 100644 --- a/mysql-test/r/query_cache.result +++ b/mysql-test/r/query_cache.result @@ -934,8 +934,7 @@ abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzab zyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcbazyxwvutsrqponmlkjihgfedcba flush query cache; drop table t1, t2; -set GLOBAL query_cache_size=1355776 -#; +set GLOBAL query_cache_size=1355776; flush status; CREATE TABLE t1 ( `date` datetime NOT NULL default '0000-00-00 00:00:00', diff --git a/mysql-test/r/query_cache_notembedded.result b/mysql-test/r/query_cache_notembedded.result index 4226738725a..8e5df012cfb 100644 --- a/mysql-test/r/query_cache_notembedded.result +++ b/mysql-test/r/query_cache_notembedded.result @@ -326,7 +326,7 @@ insert into t1 values(3); set i_var = sleep(3); return 0; end;| - select f1(); +select f1(); select sleep(4); sleep(4) 0 diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result index cfdee6e630e..04923c9e24c 100644 --- a/mysql-test/r/range.result +++ b/mysql-test/r/range.result @@ -665,6 +665,16 @@ OR ((pk4 =1) AND (((pk1 IN ( 7, 2, 1 ))) OR (pk1 =522)) AND ((pk2 IN ( 0, 2635)) pk1 pk2 pk3 pk4 filler 2621 2635 1000015 0 filler drop table t1, t2; +create table t1(a char(2), key(a(1))); +insert into t1 values ('x'), ('xx'); +explain select a from t1 where a > 'x'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 2 NULL 2 Using where +select a from t1 where a > 'x'; +a +xx +drop table t1; +End of 4.1 tests CREATE TABLE t1 ( id int(11) NOT NULL auto_increment, status varchar(20), diff --git a/mysql-test/r/rename.result b/mysql-test/r/rename.result index 345270231ef..51c2ce3a1b9 100644 --- a/mysql-test/r/rename.result +++ b/mysql-test/r/rename.result @@ -43,7 +43,7 @@ Note 1051 Unknown table 't4' CREATE TABLE t1 (a int); CREATE TABLE t3 (a int); FLUSH TABLES WITH READ LOCK; - RENAME TABLE t1 TO t2, t3 to t4; +RENAME TABLE t1 TO t2, t3 to t4; show tables; Tables_in_test t1 diff --git a/mysql-test/r/rpl_err_ignoredtable.result b/mysql-test/r/rpl_err_ignoredtable.result index 27db9c0372c..f211d5d9a2f 100644 --- a/mysql-test/r/rpl_err_ignoredtable.result +++ b/mysql-test/r/rpl_err_ignoredtable.result @@ -26,7 +26,7 @@ create table t2 (a int primary key); insert into t2 values(1); create table t3 (id int); insert into t3 values(connection_id()); - update t2 set a = a + 1 + get_lock('crash_lock%20C', 10); +update t2 set a = a + 1 + get_lock('crash_lock%20C', 10); select (@id := id) - id from t3; (@id := id) - id 0 diff --git a/mysql-test/r/rpl_master_pos_wait.result b/mysql-test/r/rpl_master_pos_wait.result index 81d9043c8ce..951e944fddc 100644 --- a/mysql-test/r/rpl_master_pos_wait.result +++ b/mysql-test/r/rpl_master_pos_wait.result @@ -12,7 +12,7 @@ id select_type table type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 select master_pos_wait(_latin1'master-bin.999999',0,2) AS `master_pos_wait('master-bin.999999',0,2)` - select master_pos_wait('master-bin.999999',0); +select master_pos_wait('master-bin.999999',0); stop slave sql_thread; master_pos_wait('master-bin.999999',0) NULL diff --git a/mysql-test/r/rpl_ndb_sp003.result b/mysql-test/r/rpl_ndb_sp003.result index 94f320f387b..d7922c61b52 100644 --- a/mysql-test/r/rpl_ndb_sp003.result +++ b/mysql-test/r/rpl_ndb_sp003.result @@ -21,7 +21,7 @@ END| SELECT get_lock("test", 200); get_lock("test", 200) 1 - CALL test.p1(); +CALL test.p1(); CALL test.p2(); SELECT release_lock("test"); release_lock("test") diff --git a/mysql-test/r/rpl_row_basic_7ndb.result b/mysql-test/r/rpl_row_basic_7ndb.result index 8c77a82f02b..5519e0dcd0c 100644 --- a/mysql-test/r/rpl_row_basic_7ndb.result +++ b/mysql-test/r/rpl_row_basic_7ndb.result @@ -389,9 +389,9 @@ INSERT INTO t8 VALUES (99,99,99); INSERT INTO t8 VALUES (99,22,33); ERROR 23000: Duplicate entry '99' for key 'PRIMARY' INSERT INTO t8 VALUES (11,99,33); -ERROR 23000: Duplicate entry '11' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' INSERT INTO t8 VALUES (11,22,99); -ERROR 23000: Duplicate entry '11' for key 'PRIMARY' +ERROR 23000: Duplicate entry '' for key '*UNKNOWN*' SELECT * FROM t8 ORDER BY a; a b c 99 99 99 diff --git a/mysql-test/r/rpl_row_sp003.result b/mysql-test/r/rpl_row_sp003.result index 01e352c3d46..df3e2a7ceed 100644 --- a/mysql-test/r/rpl_row_sp003.result +++ b/mysql-test/r/rpl_row_sp003.result @@ -21,7 +21,7 @@ END| SELECT get_lock("test", 200); get_lock("test", 200) 1 - CALL test.p1(); +CALL test.p1(); CALL test.p2(); SELECT release_lock("test"); release_lock("test") diff --git a/mysql-test/r/rpl_stm_000001.result b/mysql-test/r/rpl_stm_000001.result index ef4226e07b5..3b4cd05f640 100644 --- a/mysql-test/r/rpl_stm_000001.result +++ b/mysql-test/r/rpl_stm_000001.result @@ -44,7 +44,7 @@ create table t2(id int); insert into t2 values(connection_id()); create temporary table t3(n int); insert into t3 select get_lock('crash_lock%20C', 1) from t2; - update t1 set n = n + get_lock('crash_lock%20C', 2); +update t1 set n = n + get_lock('crash_lock%20C', 2); select (@id := id) - id from t2; (@id := id) - id 0 diff --git a/mysql-test/r/rpl_trigger.result b/mysql-test/r/rpl_trigger.result index bd6d6e63d57..50bcd071d23 100644 --- a/mysql-test/r/rpl_trigger.result +++ b/mysql-test/r/rpl_trigger.result @@ -74,8 +74,6 @@ get_lock("bug12480",2) 1 create table t1 (a datetime,b datetime, c datetime); drop function if exists bug12480; -Warnings: -Note 1305 FUNCTION bug12480 does not exist create function bug12480() returns datetime begin set @a=get_lock("bug12480",2); diff --git a/mysql-test/r/show_check.result b/mysql-test/r/show_check.result index b473bbac923..7a1ef7cedcf 100644 --- a/mysql-test/r/show_check.result +++ b/mysql-test/r/show_check.result @@ -148,12 +148,14 @@ flush tables; show open tables; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 create table t1(n int); insert into t1 values (1); show open tables; Database Table In_use Name_locked -test t1 0 0 mysql general_log 1 0 +mysql slow_log 1 0 +test t1 0 0 drop table t1; create table t1 (a int not null, b VARCHAR(10), INDEX (b) ) AVG_ROW_LENGTH=10 CHECKSUM=1 COMMENT="test" ENGINE=MYISAM MIN_ROWS=10 MAX_ROWS=100 PACK_KEYS=1 DELAY_KEY_WRITE=1 ROW_FORMAT=fixed; show create table t1; @@ -566,21 +568,23 @@ SELECT 1 FROM mysql.db, mysql.proc, mysql.user, mysql.time_zone, mysql.time_zone 1 SHOW OPEN TABLES; Database Table In_use Name_locked -mysql db 0 0 +mysql proc 0 0 test urkunde 0 0 mysql time_zone 0 0 -mysql general_log 1 0 +mysql db 0 0 test txt1 0 0 -mysql proc 0 0 +mysql slow_log 1 0 test tyt2 0 0 +mysql general_log 1 0 mysql user 0 0 mysql time_zone_name 0 0 SHOW OPEN TABLES FROM mysql; Database Table In_use Name_locked -mysql db 0 0 +mysql proc 0 0 mysql time_zone 0 0 +mysql db 0 0 +mysql slow_log 1 0 mysql general_log 1 0 -mysql proc 0 0 mysql user 0 0 mysql time_zone_name 0 0 SHOW OPEN TABLES FROM mysql LIKE 'u%'; @@ -594,14 +598,16 @@ test tyt2 0 0 mysql time_zone_name 0 0 SHOW OPEN TABLES LIKE '%o%'; Database Table In_use Name_locked +mysql proc 0 0 mysql time_zone 0 0 +mysql slow_log 1 0 mysql general_log 1 0 -mysql proc 0 0 mysql time_zone_name 0 0 FLUSH TABLES; SHOW OPEN TABLES; Database Table In_use Name_locked mysql general_log 1 0 +mysql slow_log 1 0 DROP TABLE txt1; DROP TABLE tyt2; DROP TABLE urkunde; @@ -672,6 +678,21 @@ SHOW TABLES FROM no_such_database; ERROR 42000: Unknown database 'no_such_database' SHOW COLUMNS FROM no_such_table; ERROR 42S02: Table 'test.no_such_table' doesn't exist +flush status; +show status like 'slow_queries'; +Variable_name Value +Slow_queries 0 +show tables; +Tables_in_test +show status like 'slow_queries'; +Variable_name Value +Slow_queries 1 +select 1 from information_schema.tables limit 1; +1 +1 +show status like 'slow_queries'; +Variable_name Value +Slow_queries 2 End of 5.0 tests. SHOW AUTHORS; create database mysqltest; diff --git a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result index a2d783dbcbe..d955b69bde2 100644 --- a/mysql-test/r/sp-error.result +++ b/mysql-test/r/sp-error.result @@ -1226,6 +1226,30 @@ END; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF NOT EXISTS bug14702() BEGIN END' at line 1 +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT); +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a; +ERROR HY000: View's SELECT contains a 'INTO' clause +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file"; +ERROR HY000: View's SELECT contains a 'INTO' clause +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file"; +ERROR HY000: View's SELECT contains a 'INTO' clause +CREATE PROCEDURE bug20953() +CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE(); +ERROR HY000: View's SELECT contains a 'PROCEDURE' clause +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1; +ERROR HY000: View's SELECT contains a subquery in the FROM clause +CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i; +ERROR HY000: View's SELECT contains a variable or parameter +CREATE PROCEDURE bug20953() +BEGIN +DECLARE i INT; +CREATE VIEW v AS SELECT i; +END | +ERROR HY000: View's SELECT contains a variable or parameter +PREPARE stmt FROM "CREATE VIEW v AS SELECT ?"; +ERROR HY000: View's SELECT contains a variable or parameter +DROP TABLE t1; End of 5.0 tests drop function if exists bug16164; create function bug16164() returns int @@ -1234,9 +1258,9 @@ show authors; return 42; end| ERROR 0A000: Not allowed to return a result set from a function -drop function if exists bug20701| -create function bug20701() returns varchar(25) binary return "test"| +drop function if exists bug20701; +create function bug20701() returns varchar(25) binary return "test"; ERROR 42000: This version of MySQL doesn't yet support 'return value collation' -create function bug20701() returns varchar(25) return "test"| -drop function bug20701| +create function bug20701() returns varchar(25) return "test"; +drop function bug20701; End of 5.1 tests diff --git a/mysql-test/r/sp-threads.result b/mysql-test/r/sp-threads.result index c516d7a643f..953830ecc87 100644 --- a/mysql-test/r/sp-threads.result +++ b/mysql-test/r/sp-threads.result @@ -31,7 +31,7 @@ create procedure bug9486() update t1, t2 set val= 1 where id1=id2; call bug9486(); lock tables t2 write; - call bug9486(); +call bug9486(); show processlist; Id User Host db Command Time State Info # root localhost test Sleep # NULL @@ -77,7 +77,7 @@ select * from t1; end| use test; lock table t1 write; - call p2(); +call p2(); use test; drop procedure p1; create procedure p1() select * from t1; diff --git a/mysql-test/r/sp-vars.result b/mysql-test/r/sp-vars.result index d41d98113a1..8b59fa371cc 100644 --- a/mysql-test/r/sp-vars.result +++ b/mysql-test/r/sp-vars.result @@ -4,6 +4,7 @@ DROP FUNCTION IF EXISTS sp_vars_check_ret1; DROP FUNCTION IF EXISTS sp_vars_check_ret2; DROP FUNCTION IF EXISTS sp_vars_check_ret3; DROP FUNCTION IF EXISTS sp_vars_check_ret4; +DROP FUNCTION IF EXISTS sp_vars_div_zero; SET @@sql_mode = 'ansi'; CREATE PROCEDURE sp_vars_check_dflt() BEGIN @@ -88,6 +89,12 @@ CREATE FUNCTION sp_vars_check_ret4() RETURNS DECIMAL(64, 2) BEGIN RETURN 12 * 10 + 34 + 0.1234; END| +CREATE FUNCTION sp_vars_div_zero() RETURNS INTEGER +BEGIN +DECLARE div_zero INTEGER; +SELECT 1/0 INTO div_zero; +RETURN div_zero; +END| --------------------------------------------------------------- Calling the routines, created in ANSI mode. @@ -172,6 +179,9 @@ sp_vars_check_ret4() 154.12 Warnings: Note 1265 Data truncated for column 'sp_vars_check_ret4()' at row 1 +SELECT sp_vars_div_zero(); +sp_vars_div_zero() +NULL SET @@sql_mode = 'traditional'; --------------------------------------------------------------- @@ -257,12 +267,16 @@ sp_vars_check_ret4() 154.12 Warnings: Note 1265 Data truncated for column 'sp_vars_check_ret4()' at row 1 +SELECT sp_vars_div_zero(); +sp_vars_div_zero() +NULL DROP PROCEDURE sp_vars_check_dflt; DROP PROCEDURE sp_vars_check_assignment; DROP FUNCTION sp_vars_check_ret1; DROP FUNCTION sp_vars_check_ret2; DROP FUNCTION sp_vars_check_ret3; DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; CREATE PROCEDURE sp_vars_check_dflt() BEGIN DECLARE v1 TINYINT DEFAULT 1e200; @@ -346,6 +360,12 @@ CREATE FUNCTION sp_vars_check_ret4() RETURNS DECIMAL(64, 2) BEGIN RETURN 12 * 10 + 34 + 0.1234; END| +CREATE FUNCTION sp_vars_div_zero() RETURNS INTEGER +BEGIN +DECLARE div_zero INTEGER; +SELECT 1/0 INTO div_zero; +RETURN div_zero; +END| --------------------------------------------------------------- Calling the routines, created in TRADITIONAL mode. @@ -366,6 +386,8 @@ sp_vars_check_ret4() 154.12 Warnings: Note 1265 Data truncated for column 'sp_vars_check_ret4()' at row 1 +SELECT sp_vars_div_zero(); +ERROR 22012: Division by 0 SET @@sql_mode = 'ansi'; DROP PROCEDURE sp_vars_check_dflt; DROP PROCEDURE sp_vars_check_assignment; @@ -373,6 +395,7 @@ DROP FUNCTION sp_vars_check_ret1; DROP FUNCTION sp_vars_check_ret2; DROP FUNCTION sp_vars_check_ret3; DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; --------------------------------------------------------------- BIT data type tests diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 79e32b921cc..aeccfd9c951 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -5470,5 +5470,161 @@ CAD CHF DROP FUNCTION bug21493| DROP TABLE t3,t4| +drop function if exists func_20028_a| +drop function if exists func_20028_b| +drop function if exists func_20028_c| +drop procedure if exists proc_20028_a| +drop procedure if exists proc_20028_b| +drop procedure if exists proc_20028_c| +drop table if exists table_20028| +create table table_20028 (i int)| +SET @save_sql_mode=@@sql_mode| +SET sql_mode=''| +create function func_20028_a() returns integer +begin +declare temp integer; +select i into temp from table_20028 limit 1; +return ifnull(temp, 0); +end| +create function func_20028_b() returns integer +begin +return func_20028_a(); +end| +create function func_20028_c() returns integer +begin +declare div_zero integer; +set SQL_MODE='TRADITIONAL'; +select 1/0 into div_zero; +return div_zero; +end| +create procedure proc_20028_a() +begin +declare temp integer; +select i into temp from table_20028 limit 1; +end| +create procedure proc_20028_b() +begin +call proc_20028_a(); +end| +create procedure proc_20028_c() +begin +declare div_zero integer; +set SQL_MODE='TRADITIONAL'; +select 1/0 into div_zero; +end| +select func_20028_a()| +func_20028_a() +0 +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +select func_20028_b()| +func_20028_b() +0 +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +select func_20028_c()| +ERROR 22012: Division by 0 +call proc_20028_a()| +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +call proc_20028_b()| +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +call proc_20028_c()| +ERROR 22012: Division by 0 +SET sql_mode='TRADITIONAL'| +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| +create function func_20028_a() returns integer +begin +declare temp integer; +select i into temp from table_20028 limit 1; +return ifnull(temp, 0); +end| +create function func_20028_b() returns integer +begin +return func_20028_a(); +end| +create function func_20028_c() returns integer +begin +declare div_zero integer; +set SQL_MODE=''; +select 1/0 into div_zero; +return div_zero; +end| +create procedure proc_20028_a() +begin +declare temp integer; +select i into temp from table_20028 limit 1; +end| +create procedure proc_20028_b() +begin +call proc_20028_a(); +end| +create procedure proc_20028_c() +begin +declare div_zero integer; +set SQL_MODE=''; +select 1/0 into div_zero; +end| +select func_20028_a()| +func_20028_a() +0 +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +select func_20028_b()| +func_20028_b() +0 +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +select func_20028_c()| +func_20028_c() +NULL +call proc_20028_a()| +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +call proc_20028_b()| +Warnings: +Warning 1329 No data - zero rows fetched, selected, or processed +call proc_20028_c()| +SET @@sql_mode=@save_sql_mode| +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| +drop table table_20028| +drop procedure if exists proc_21462_a| +drop procedure if exists proc_21462_b| +create procedure proc_21462_a() +begin +select "Called A"; +end| +create procedure proc_21462_b(x int) +begin +select "Called B"; +end| +call proc_21462_a| +Called A +Called A +call proc_21462_a()| +Called A +Called A +call proc_21462_a(1)| +ERROR 42000: Incorrect number of arguments for PROCEDURE test.proc_21462_a; expected 0, got 1 +call proc_21462_b| +ERROR 42000: Incorrect number of arguments for PROCEDURE test.proc_21462_b; expected 1, got 0 +call proc_21462_b()| +ERROR 42000: Incorrect number of arguments for PROCEDURE test.proc_21462_b; expected 1, got 0 +call proc_21462_b(1)| +Called B +Called B +drop procedure proc_21462_a| +drop procedure proc_21462_b| End of 5.0 tests drop table t1,t2; diff --git a/mysql-test/r/sp_notembedded.result b/mysql-test/r/sp_notembedded.result index 564b8031c35..0b1fa565d28 100644 --- a/mysql-test/r/sp_notembedded.result +++ b/mysql-test/r/sp_notembedded.result @@ -74,8 +74,7 @@ flush status| flush query cache| delete from t1| drop procedure bug3583| -drop table t1; -#| +drop table t1| drop procedure if exists bug6807| create procedure bug6807() begin diff --git a/mysql-test/r/ssl_des.result b/mysql-test/r/ssl_des.result new file mode 100644 index 00000000000..cd8bf52139e --- /dev/null +++ b/mysql-test/r/ssl_des.result @@ -0,0 +1,2159 @@ +SHOW STATUS LIKE 'Ssl_cipher'; +Variable_name Value +Ssl_cipher DHE-RSA-AES256-SHA +drop table if exists t1,t2,t3,t4; +CREATE TABLE t1 ( +Period smallint(4) unsigned zerofill DEFAULT '0000' NOT NULL, +Varor_period smallint(4) unsigned DEFAULT '0' NOT NULL +); +INSERT INTO t1 VALUES (9410,9412); +select period from t1; +period +9410 +select * from t1; +Period Varor_period +9410 9412 +select t1.* from t1; +Period Varor_period +9410 9412 +CREATE TABLE t2 ( +auto int not null auto_increment, +fld1 int(6) unsigned zerofill DEFAULT '000000' NOT NULL, +companynr tinyint(2) unsigned zerofill DEFAULT '00' NOT NULL, +fld3 char(30) DEFAULT '' NOT NULL, +fld4 char(35) DEFAULT '' NOT NULL, +fld5 char(35) DEFAULT '' NOT NULL, +fld6 char(4) DEFAULT '' NOT NULL, +UNIQUE fld1 (fld1), +KEY fld3 (fld3), +PRIMARY KEY (auto) +); +select t2.fld3 from t2 where companynr = 58 and fld3 like "%imaginable%"; +fld3 +imaginable +select fld3 from t2 where fld3 like "%cultivation" ; +fld3 +cultivation +select t2.fld3,companynr from t2 where companynr = 57+1 order by fld3; +fld3 companynr +concoct 58 +druggists 58 +engrossing 58 +Eurydice 58 +exclaimers 58 +ferociousness 58 +hopelessness 58 +Huey 58 +imaginable 58 +judges 58 +merging 58 +ostrich 58 +peering 58 +Phelps 58 +presumes 58 +Ruth 58 +sentences 58 +Shylock 58 +straggled 58 +synergy 58 +thanking 58 +tying 58 +unlocks 58 +select fld3,companynr from t2 where companynr = 58 order by fld3; +fld3 companynr +concoct 58 +druggists 58 +engrossing 58 +Eurydice 58 +exclaimers 58 +ferociousness 58 +hopelessness 58 +Huey 58 +imaginable 58 +judges 58 +merging 58 +ostrich 58 +peering 58 +Phelps 58 +presumes 58 +Ruth 58 +sentences 58 +Shylock 58 +straggled 58 +synergy 58 +thanking 58 +tying 58 +unlocks 58 +select fld3 from t2 order by fld3 desc limit 10; +fld3 +youthfulness +yelped +Wotan +workers +Witt +witchcraft +Winsett +Willy +willed +wildcats +select fld3 from t2 order by fld3 desc limit 5; +fld3 +youthfulness +yelped +Wotan +workers +Witt +select fld3 from t2 order by fld3 desc limit 5,5; +fld3 +witchcraft +Winsett +Willy +willed +wildcats +select t2.fld3 from t2 where fld3 = 'honeysuckle'; +fld3 +honeysuckle +select t2.fld3 from t2 where fld3 LIKE 'honeysuckl_'; +fld3 +honeysuckle +select t2.fld3 from t2 where fld3 LIKE 'hon_ysuckl_'; +fld3 +honeysuckle +select t2.fld3 from t2 where fld3 LIKE 'honeysuckle%'; +fld3 +honeysuckle +select t2.fld3 from t2 where fld3 LIKE 'h%le'; +fld3 +honeysuckle +select t2.fld3 from t2 where fld3 LIKE 'honeysuckle_'; +fld3 +select t2.fld3 from t2 where fld3 LIKE 'don_t_find_me_please%'; +fld3 +explain select t2.fld3 from t2 where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +explain select fld3 from t2 ignore index (fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select fld3 from t2 use index (fld1) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select fld3 from t2 use index (fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +explain select fld3 from t2 use index (fld1,fld3) where fld3 = 'honeysuckle'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref fld3 fld3 30 const 1 Using where; Using index +explain select fld3 from t2 ignore index (fld3,not_used); +ERROR HY000: Key 'not_used' doesn't exist in table 't2' +explain select fld3 from t2 use index (not_used); +ERROR HY000: Key 'not_used' doesn't exist in table 't2' +select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3; +fld3 +honeysuckle +honoring +explain select t2.fld3 from t2 where fld3 >= 'honeysuckle' and fld3 <= 'honoring' order by fld3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld3 fld3 30 NULL 2 Using where; Using index +select fld1,fld3 from t2 where fld3="Colombo" or fld3 = "nondecreasing" order by fld3; +fld1 fld3 +148504 Colombo +068305 Colombo +000000 nondecreasing +select fld1,fld3 from t2 where companynr = 37 and fld3 = 'appendixes'; +fld1 fld3 +232605 appendixes +1232605 appendixes +1232606 appendixes +1232607 appendixes +1232608 appendixes +1232609 appendixes +select fld1 from t2 where fld1=250501 or fld1="250502"; +fld1 +250501 +250502 +explain select fld1 from t2 where fld1=250501 or fld1="250502"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld1 fld1 4 NULL 2 Using where; Using index +select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; +fld1 +250501 +250502 +250505 +250601 +explain select fld1 from t2 where fld1=250501 or fld1=250502 or fld1 >= 250505 and fld1 <= 250601 or fld1 between 250501 and 250502; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 range fld1 fld1 4 NULL 4 Using where; Using index +select fld1,fld3 from t2 where companynr = 37 and fld3 like 'f%'; +fld1 fld3 +218401 faithful +018007 fanatic +228311 fated +018017 featherweight +218022 feed +088303 feminine +058004 Fenton +038017 fetched +018054 fetters +208101 fiftieth +238007 filial +013606 fingerings +218008 finishers +038205 firearm +188505 fitting +202301 Fitzpatrick +238008 fixedly +012001 flanking +018103 flint +018104 flopping +188007 flurried +013602 foldout +226205 foothill +232102 forgivably +228306 forthcoming +186002 freakish +208113 freest +231315 freezes +036002 funereal +226209 furnishings +198006 furthermore +select fld3 from t2 where fld3 like "L%" and fld3 = "ok"; +fld3 +select fld3 from t2 where (fld3 like "C%" and fld3 = "Chantilly"); +fld3 +Chantilly +select fld1,fld3 from t2 where fld1 like "25050%"; +fld1 fld3 +250501 poisoning +250502 Iraqis +250503 heaving +250504 population +250505 bomb +select fld1,fld3 from t2 where fld1 like "25050_"; +fld1 fld3 +250501 poisoning +250502 Iraqis +250503 heaving +250504 population +250505 bomb +select distinct companynr from t2; +companynr +00 +37 +36 +50 +58 +29 +40 +53 +65 +41 +34 +68 +select distinct companynr from t2 order by companynr; +companynr +00 +29 +34 +36 +37 +40 +41 +50 +53 +58 +65 +68 +select distinct companynr from t2 order by companynr desc; +companynr +68 +65 +58 +53 +50 +41 +40 +37 +36 +34 +29 +00 +select distinct t2.fld3,period from t2,t1 where companynr=37 and fld3 like "O%"; +fld3 period +obliterates 9410 +offload 9410 +opaquely 9410 +organizer 9410 +overestimating 9410 +overlay 9410 +select distinct fld3 from t2 where companynr = 34 order by fld3; +fld3 +absentee +accessed +ahead +alphabetic +Asiaticizations +attitude +aye +bankruptcies +belays +Blythe +bomb +boulevard +bulldozes +cannot +caressing +charcoal +checksumming +chess +clubroom +colorful +cosy +creator +crying +Darius +diffusing +duality +Eiffel +Epiphany +Ernestine +explorers +exterminated +famine +forked +Gershwins +heaving +Hodges +Iraqis +Italianization +Lagos +landslide +libretto +Majorca +mastering +narrowed +occurred +offerers +Palestine +Peruvianizes +pharmaceutic +poisoning +population +Pygmalion +rats +realest +recording +regimented +retransmitting +reviver +rouses +scars +sicker +sleepwalk +stopped +sugars +translatable +uncles +unexpected +uprisings +versatility +vest +select distinct fld3 from t2 limit 10; +fld3 +abates +abiding +Abraham +abrogating +absentee +abut +accessed +accruing +accumulating +accuracies +select distinct fld3 from t2 having fld3 like "A%" limit 10; +fld3 +abates +abiding +Abraham +abrogating +absentee +abut +accessed +accruing +accumulating +accuracies +select distinct substring(fld3,1,3) from t2 where fld3 like "A%"; +substring(fld3,1,3) +aba +abi +Abr +abs +abu +acc +acq +acu +Ade +adj +Adl +adm +Ado +ads +adv +aer +aff +afi +afl +afo +agi +ahe +aim +air +Ald +alg +ali +all +alp +alr +ama +ame +amm +ana +and +ane +Ang +ani +Ann +Ant +api +app +aqu +Ara +arc +Arm +arr +Art +Asi +ask +asp +ass +ast +att +aud +Aug +aut +ave +avo +awe +aye +Azt +select distinct substring(fld3,1,3) as a from t2 having a like "A%" order by a limit 10; +a +aba +abi +Abr +abs +abu +acc +acq +acu +Ade +adj +select distinct substring(fld3,1,3) from t2 where fld3 like "A%" limit 10; +substring(fld3,1,3) +aba +abi +Abr +abs +abu +acc +acq +acu +Ade +adj +select distinct substring(fld3,1,3) as a from t2 having a like "A%" limit 10; +a +aba +abi +Abr +abs +abu +acc +acq +acu +Ade +adj +create table t3 ( +period int not null, +name char(32) not null, +companynr int not null, +price double(11,0), +price2 double(11,0), +key (period), +key (name) +); +create temporary table tmp engine = myisam select * from t3; +insert into t3 select * from tmp; +insert into tmp select * from t3; +insert into t3 select * from tmp; +insert into tmp select * from t3; +insert into t3 select * from tmp; +insert into tmp select * from t3; +insert into t3 select * from tmp; +insert into tmp select * from t3; +insert into t3 select * from tmp; +insert into tmp select * from t3; +insert into t3 select * from tmp; +insert into tmp select * from t3; +insert into t3 select * from tmp; +insert into tmp select * from t3; +insert into t3 select * from tmp; +insert into tmp select * from t3; +insert into t3 select * from tmp; +alter table t3 add t2nr int not null auto_increment primary key first; +drop table tmp; +SET SQL_BIG_TABLES=1; +select distinct concat(fld3," ",fld3) as namn from t2,t3 where t2.fld1=t3.t2nr order by namn limit 10; +namn +Abraham Abraham +abrogating abrogating +admonishing admonishing +Adolph Adolph +afield afield +aging aging +ammonium ammonium +analyzable analyzable +animals animals +animized animized +SET SQL_BIG_TABLES=0; +select distinct concat(fld3," ",fld3) from t2,t3 where t2.fld1=t3.t2nr order by fld3 limit 10; +concat(fld3," ",fld3) +Abraham Abraham +abrogating abrogating +admonishing admonishing +Adolph Adolph +afield afield +aging aging +ammonium ammonium +analyzable analyzable +animals animals +animized animized +select distinct fld5 from t2 limit 10; +fld5 +neat +Steinberg +jarring +tinily +balled +persist +attainments +fanatic +measures +rightfulness +select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10; +fld3 count(*) +affixed 1 +and 1 +annoyers 1 +Anthony 1 +assayed 1 +assurers 1 +attendants 1 +bedlam 1 +bedpost 1 +boasted 1 +SET SQL_BIG_TABLES=1; +select distinct fld3,count(*) from t2 group by companynr,fld3 limit 10; +fld3 count(*) +affixed 1 +and 1 +annoyers 1 +Anthony 1 +assayed 1 +assurers 1 +attendants 1 +bedlam 1 +bedpost 1 +boasted 1 +SET SQL_BIG_TABLES=0; +select distinct fld3,repeat("a",length(fld3)),count(*) from t2 group by companynr,fld3 limit 100,10; +fld3 repeat("a",length(fld3)) count(*) +circus aaaaaa 1 +cited aaaaa 1 +Colombo aaaaaaa 1 +congresswoman aaaaaaaaaaaaa 1 +contrition aaaaaaaaaa 1 +corny aaaaa 1 +cultivation aaaaaaaaaaa 1 +definiteness aaaaaaaaaaaa 1 +demultiplex aaaaaaaaaaa 1 +disappointing aaaaaaaaaaaaa 1 +select distinct companynr,rtrim(space(512+companynr)) from t3 order by 1,2; +companynr rtrim(space(512+companynr)) +37 +78 +101 +154 +311 +447 +512 +select distinct fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by fld3; +fld3 +explain select t3.t2nr,fld3 from t2,t3 where t2.companynr = 34 and t2.fld1=t3.t2nr order by t3.t2nr,fld3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL fld1 NULL NULL NULL 1199 Using where; Using temporary; Using filesort +1 SIMPLE t3 eq_ref PRIMARY PRIMARY 4 test.t2.fld1 1 Using where; Using index +explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL period NULL NULL NULL 41810 Using temporary; Using filesort +1 SIMPLE t3 ref period period 4 test.t1.period 4181 +explain select * from t3 as t1,t3 where t1.period=t3.period order by t3.period limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t3 index period period 4 NULL 41810 +1 SIMPLE t1 ref period period 4 test.t3.period 4181 +explain select * from t3 as t1,t3 where t1.period=t3.period order by t1.period limit 10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index period period 4 NULL 41810 +1 SIMPLE t3 ref period period 4 test.t1.period 4181 +select period from t1; +period +9410 +select period from t1 where period=1900; +period +select fld3,period from t1,t2 where fld1 = 011401 order by period; +fld3 period +breaking 9410 +select fld3,period from t2,t3 where t2.fld1 = 011401 and t2.fld1=t3.t2nr and t3.period=1001; +fld3 period +breaking 1001 +explain select fld3,period from t2,t3 where t2.fld1 = 011401 and t3.t2nr=t2.fld1 and 1001 = t3.period; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 const fld1 fld1 4 const 1 +1 SIMPLE t3 const PRIMARY,period PRIMARY 4 const 1 +select fld3,period from t2,t1 where companynr*10 = 37*10; +fld3 period +breaking 9410 +Romans 9410 +intercepted 9410 +bewilderingly 9410 +astound 9410 +admonishing 9410 +sumac 9410 +flanking 9410 +combed 9410 +subjective 9410 +scatterbrain 9410 +Eulerian 9410 +Kane 9410 +overlay 9410 +perturb 9410 +goblins 9410 +annihilates 9410 +Wotan 9410 +snatching 9410 +concludes 9410 +laterally 9410 +yelped 9410 +grazing 9410 +Baird 9410 +celery 9410 +misunderstander 9410 +handgun 9410 +foldout 9410 +mystic 9410 +succumbed 9410 +Nabisco 9410 +fingerings 9410 +aging 9410 +afield 9410 +ammonium 9410 +boat 9410 +intelligibility 9410 +Augustine 9410 +teethe 9410 +dreaded 9410 +scholastics 9410 +audiology 9410 +wallet 9410 +parters 9410 +eschew 9410 +quitter 9410 +neat 9410 +Steinberg 9410 +jarring 9410 +tinily 9410 +balled 9410 +persist 9410 +attainments 9410 +fanatic 9410 +measures 9410 +rightfulness 9410 +capably 9410 +impulsive 9410 +starlet 9410 +terminators 9410 +untying 9410 +announces 9410 +featherweight 9410 +pessimist 9410 +daughter 9410 +decliner 9410 +lawgiver 9410 +stated 9410 +readable 9410 +attrition 9410 +cascade 9410 +motors 9410 +interrogate 9410 +pests 9410 +stairway 9410 +dopers 9410 +testicle 9410 +Parsifal 9410 +leavings 9410 +postulation 9410 +squeaking 9410 +contrasted 9410 +leftover 9410 +whiteners 9410 +erases 9410 +Punjab 9410 +Merritt 9410 +Quixotism 9410 +sweetish 9410 +dogging 9410 +scornfully 9410 +bellow 9410 +bills 9410 +cupboard 9410 +sureties 9410 +puddings 9410 +fetters 9410 +bivalves 9410 +incurring 9410 +Adolph 9410 +pithed 9410 +Miles 9410 +trimmings 9410 +tragedies 9410 +skulking 9410 +flint 9410 +flopping 9410 +relaxing 9410 +offload 9410 +suites 9410 +lists 9410 +animized 9410 +multilayer 9410 +standardizes 9410 +Judas 9410 +vacuuming 9410 +dentally 9410 +humanness 9410 +inch 9410 +Weissmuller 9410 +irresponsibly 9410 +luckily 9410 +culled 9410 +medical 9410 +bloodbath 9410 +subschema 9410 +animals 9410 +Micronesia 9410 +repetitions 9410 +Antares 9410 +ventilate 9410 +pityingly 9410 +interdependent 9410 +Graves 9410 +neonatal 9410 +chafe 9410 +honoring 9410 +realtor 9410 +elite 9410 +funereal 9410 +abrogating 9410 +sorters 9410 +Conley 9410 +lectured 9410 +Abraham 9410 +Hawaii 9410 +cage 9410 +hushes 9410 +Simla 9410 +reporters 9410 +Dutchman 9410 +descendants 9410 +groupings 9410 +dissociate 9410 +coexist 9410 +Beebe 9410 +Taoism 9410 +Connally 9410 +fetched 9410 +checkpoints 9410 +rusting 9410 +galling 9410 +obliterates 9410 +traitor 9410 +resumes 9410 +analyzable 9410 +terminator 9410 +gritty 9410 +firearm 9410 +minima 9410 +Selfridge 9410 +disable 9410 +witchcraft 9410 +betroth 9410 +Manhattanize 9410 +imprint 9410 +peeked 9410 +swelling 9410 +interrelationships 9410 +riser 9410 +Gandhian 9410 +peacock 9410 +bee 9410 +kanji 9410 +dental 9410 +scarf 9410 +chasm 9410 +insolence 9410 +syndicate 9410 +alike 9410 +imperial 9410 +convulsion 9410 +railway 9410 +validate 9410 +normalizes 9410 +comprehensive 9410 +chewing 9410 +denizen 9410 +schemer 9410 +chronicle 9410 +Kline 9410 +Anatole 9410 +partridges 9410 +brunch 9410 +recruited 9410 +dimensions 9410 +Chicana 9410 +announced 9410 +praised 9410 +employing 9410 +linear 9410 +quagmire 9410 +western 9410 +relishing 9410 +serving 9410 +scheduling 9410 +lore 9410 +eventful 9410 +arteriole 9410 +disentangle 9410 +cured 9410 +Fenton 9410 +avoidable 9410 +drains 9410 +detectably 9410 +husky 9410 +impelling 9410 +undoes 9410 +evened 9410 +squeezes 9410 +destroyer 9410 +rudeness 9410 +beaner 9410 +boorish 9410 +Everhart 9410 +encompass 9410 +mushrooms 9410 +Alison 9410 +externally 9410 +pellagra 9410 +cult 9410 +creek 9410 +Huffman 9410 +Majorca 9410 +governing 9410 +gadfly 9410 +reassigned 9410 +intentness 9410 +craziness 9410 +psychic 9410 +squabbled 9410 +burlesque 9410 +capped 9410 +extracted 9410 +DiMaggio 9410 +exclamation 9410 +subdirectory 9410 +Gothicism 9410 +feminine 9410 +metaphysically 9410 +sanding 9410 +Miltonism 9410 +freakish 9410 +index 9410 +straight 9410 +flurried 9410 +denotative 9410 +coming 9410 +commencements 9410 +gentleman 9410 +gifted 9410 +Shanghais 9410 +sportswriting 9410 +sloping 9410 +navies 9410 +leaflet 9410 +shooter 9410 +Joplin 9410 +babies 9410 +assails 9410 +admiring 9410 +swaying 9410 +Goldstine 9410 +fitting 9410 +Norwalk 9410 +analogy 9410 +deludes 9410 +cokes 9410 +Clayton 9410 +exhausts 9410 +causality 9410 +sating 9410 +icon 9410 +throttles 9410 +communicants 9410 +dehydrate 9410 +priceless 9410 +publicly 9410 +incidentals 9410 +commonplace 9410 +mumbles 9410 +furthermore 9410 +cautioned 9410 +parametrized 9410 +registration 9410 +sadly 9410 +positioning 9410 +babysitting 9410 +eternal 9410 +hoarder 9410 +congregates 9410 +rains 9410 +workers 9410 +sags 9410 +unplug 9410 +garage 9410 +boulder 9410 +specifics 9410 +Teresa 9410 +Winsett 9410 +convenient 9410 +buckboards 9410 +amenities 9410 +resplendent 9410 +sews 9410 +participated 9410 +Simon 9410 +certificates 9410 +Fitzpatrick 9410 +Evanston 9410 +misted 9410 +textures 9410 +save 9410 +count 9410 +rightful 9410 +chaperone 9410 +Lizzy 9410 +clenched 9410 +effortlessly 9410 +accessed 9410 +beaters 9410 +Hornblower 9410 +vests 9410 +indulgences 9410 +infallibly 9410 +unwilling 9410 +excrete 9410 +spools 9410 +crunches 9410 +overestimating 9410 +ineffective 9410 +humiliation 9410 +sophomore 9410 +star 9410 +rifles 9410 +dialysis 9410 +arriving 9410 +indulge 9410 +clockers 9410 +languages 9410 +Antarctica 9410 +percentage 9410 +ceiling 9410 +specification 9410 +regimented 9410 +ciphers 9410 +pictures 9410 +serpents 9410 +allot 9410 +realized 9410 +mayoral 9410 +opaquely 9410 +hostess 9410 +fiftieth 9410 +incorrectly 9410 +decomposition 9410 +stranglings 9410 +mixture 9410 +electroencephalography 9410 +similarities 9410 +charges 9410 +freest 9410 +Greenberg 9410 +tinting 9410 +expelled 9410 +warm 9410 +smoothed 9410 +deductions 9410 +Romano 9410 +bitterroot 9410 +corset 9410 +securing 9410 +environing 9410 +cute 9410 +Crays 9410 +heiress 9410 +inform 9410 +avenge 9410 +universals 9410 +Kinsey 9410 +ravines 9410 +bestseller 9410 +equilibrium 9410 +extents 9410 +relatively 9410 +pressure 9410 +critiques 9410 +befouled 9410 +rightfully 9410 +mechanizing 9410 +Latinizes 9410 +timesharing 9410 +Aden 9410 +embassies 9410 +males 9410 +shapelessly 9410 +mastering 9410 +Newtonian 9410 +finishers 9410 +abates 9410 +teem 9410 +kiting 9410 +stodgy 9410 +feed 9410 +guitars 9410 +airships 9410 +store 9410 +denounces 9410 +Pyle 9410 +Saxony 9410 +serializations 9410 +Peruvian 9410 +taxonomically 9410 +kingdom 9410 +stint 9410 +Sault 9410 +faithful 9410 +Ganymede 9410 +tidiness 9410 +gainful 9410 +contrary 9410 +Tipperary 9410 +tropics 9410 +theorizers 9410 +renew 9410 +already 9410 +terminal 9410 +Hegelian 9410 +hypothesizer 9410 +warningly 9410 +journalizing 9410 +nested 9410 +Lars 9410 +saplings 9410 +foothill 9410 +labeled 9410 +imperiously 9410 +reporters 9410 +furnishings 9410 +precipitable 9410 +discounts 9410 +excises 9410 +Stalin 9410 +despot 9410 +ripeness 9410 +Arabia 9410 +unruly 9410 +mournfulness 9410 +boom 9410 +slaughter 9410 +Sabine 9410 +handy 9410 +rural 9410 +organizer 9410 +shipyard 9410 +civics 9410 +inaccuracy 9410 +rules 9410 +juveniles 9410 +comprised 9410 +investigations 9410 +stabilizes 9410 +seminaries 9410 +Hunter 9410 +sporty 9410 +test 9410 +weasels 9410 +CERN 9410 +tempering 9410 +afore 9410 +Galatean 9410 +techniques 9410 +error 9410 +veranda 9410 +severely 9410 +Cassites 9410 +forthcoming 9410 +guides 9410 +vanish 9410 +lied 9410 +sawtooth 9410 +fated 9410 +gradually 9410 +widens 9410 +preclude 9410 +evenhandedly 9410 +percentage 9410 +disobedience 9410 +humility 9410 +gleaning 9410 +petted 9410 +bloater 9410 +minion 9410 +marginal 9410 +apiary 9410 +measures 9410 +precaution 9410 +repelled 9410 +primary 9410 +coverings 9410 +Artemia 9410 +navigate 9410 +spatial 9410 +Gurkha 9410 +meanwhile 9410 +Melinda 9410 +Butterfield 9410 +Aldrich 9410 +previewing 9410 +glut 9410 +unaffected 9410 +inmate 9410 +mineral 9410 +impending 9410 +meditation 9410 +ideas 9410 +miniaturizes 9410 +lewdly 9410 +title 9410 +youthfulness 9410 +creak 9410 +Chippewa 9410 +clamored 9410 +freezes 9410 +forgivably 9410 +reduce 9410 +McGovern 9410 +Nazis 9410 +epistle 9410 +socializes 9410 +conceptions 9410 +Kevin 9410 +uncovering 9410 +chews 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +appendixes 9410 +raining 9410 +infest 9410 +compartment 9410 +minting 9410 +ducks 9410 +roped 9410 +waltz 9410 +Lillian 9410 +repressions 9410 +chillingly 9410 +noncritical 9410 +lithograph 9410 +spongers 9410 +parenthood 9410 +posed 9410 +instruments 9410 +filial 9410 +fixedly 9410 +relives 9410 +Pandora 9410 +watering 9410 +ungrateful 9410 +secures 9410 +poison 9410 +dusted 9410 +encompasses 9410 +presentation 9410 +Kantian 9410 +select fld3,period,price,price2 from t2,t3 where t2.fld1=t3.t2nr and period >= 1001 and period <= 1002 and t2.companynr = 37 order by fld3,period, price; +fld3 period price price2 +admonishing 1002 28357832 8723648 +analyzable 1002 28357832 8723648 +annihilates 1001 5987435 234724 +Antares 1002 28357832 8723648 +astound 1001 5987435 234724 +audiology 1001 5987435 234724 +Augustine 1002 28357832 8723648 +Baird 1002 28357832 8723648 +bewilderingly 1001 5987435 234724 +breaking 1001 5987435 234724 +Conley 1001 5987435 234724 +dentally 1002 28357832 8723648 +dissociate 1002 28357832 8723648 +elite 1001 5987435 234724 +eschew 1001 5987435 234724 +Eulerian 1001 5987435 234724 +flanking 1001 5987435 234724 +foldout 1002 28357832 8723648 +funereal 1002 28357832 8723648 +galling 1002 28357832 8723648 +Graves 1001 5987435 234724 +grazing 1001 5987435 234724 +groupings 1001 5987435 234724 +handgun 1001 5987435 234724 +humility 1002 28357832 8723648 +impulsive 1002 28357832 8723648 +inch 1001 5987435 234724 +intelligibility 1001 5987435 234724 +jarring 1001 5987435 234724 +lawgiver 1001 5987435 234724 +lectured 1002 28357832 8723648 +Merritt 1002 28357832 8723648 +neonatal 1001 5987435 234724 +offload 1002 28357832 8723648 +parters 1002 28357832 8723648 +pityingly 1002 28357832 8723648 +puddings 1002 28357832 8723648 +Punjab 1001 5987435 234724 +quitter 1002 28357832 8723648 +realtor 1001 5987435 234724 +relaxing 1001 5987435 234724 +repetitions 1001 5987435 234724 +resumes 1001 5987435 234724 +Romans 1002 28357832 8723648 +rusting 1001 5987435 234724 +scholastics 1001 5987435 234724 +skulking 1002 28357832 8723648 +stated 1002 28357832 8723648 +suites 1002 28357832 8723648 +sureties 1001 5987435 234724 +testicle 1002 28357832 8723648 +tinily 1002 28357832 8723648 +tragedies 1001 5987435 234724 +trimmings 1001 5987435 234724 +vacuuming 1001 5987435 234724 +ventilate 1001 5987435 234724 +wallet 1001 5987435 234724 +Weissmuller 1002 28357832 8723648 +Wotan 1002 28357832 8723648 +select t2.fld1,fld3,period,price,price2 from t2,t3 where t2.fld1>= 18201 and t2.fld1 <= 18811 and t2.fld1=t3.t2nr and period = 1001 and t2.companynr = 37; +fld1 fld3 period price price2 +018201 relaxing 1001 5987435 234724 +018601 vacuuming 1001 5987435 234724 +018801 inch 1001 5987435 234724 +018811 repetitions 1001 5987435 234724 +create table t4 ( +companynr tinyint(2) unsigned zerofill NOT NULL default '00', +companyname char(30) NOT NULL default '', +PRIMARY KEY (companynr), +UNIQUE KEY companyname(companyname) +) ENGINE=MyISAM MAX_ROWS=50 PACK_KEYS=1 COMMENT='companynames'; +select STRAIGHT_JOIN t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; +companynr companyname +00 Unknown +29 company 1 +34 company 2 +36 company 3 +37 company 4 +40 company 5 +41 company 6 +50 company 11 +53 company 7 +58 company 8 +65 company 9 +68 company 10 +select SQL_SMALL_RESULT t2.companynr,companyname from t4,t2 where t2.companynr=t4.companynr group by t2.companynr; +companynr companyname +00 Unknown +29 company 1 +34 company 2 +36 company 3 +37 company 4 +40 company 5 +41 company 6 +50 company 11 +53 company 7 +58 company 8 +65 company 9 +68 company 10 +select * from t1,t1 t12; +Period Varor_period Period Varor_period +9410 9412 9410 9412 +select t2.fld1,t22.fld1 from t2,t2 t22 where t2.fld1 >= 250501 and t2.fld1 <= 250505 and t22.fld1 >= 250501 and t22.fld1 <= 250505; +fld1 fld1 +250501 250501 +250502 250501 +250503 250501 +250504 250501 +250505 250501 +250501 250502 +250502 250502 +250503 250502 +250504 250502 +250505 250502 +250501 250503 +250502 250503 +250503 250503 +250504 250503 +250505 250503 +250501 250504 +250502 250504 +250503 250504 +250504 250504 +250505 250504 +250501 250505 +250502 250505 +250503 250505 +250504 250505 +250505 250505 +insert into t2 (fld1, companynr) values (999999,99); +select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; +companynr companyname +99 NULL +select count(*) from t2 left join t4 using (companynr) where t4.companynr is not null; +count(*) +1199 +explain select t2.companynr,companyname from t2 left join t4 using (companynr) where t4.companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1200 +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 Using where; Not exists +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 +1 SIMPLE t2 ALL NULL NULL NULL NULL 1200 Using where; Not exists +select companynr,companyname from t2 left join t4 using (companynr) where companynr is null; +companynr companyname +select count(*) from t2 left join t4 using (companynr) where companynr is not null; +count(*) +1200 +explain select companynr,companyname from t2 left join t4 using (companynr) where companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +delete from t2 where fld1=999999; +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 and t4.companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +1 SIMPLE t4 eq_ref PRIMARY PRIMARY 1 test.t2.companynr 1 +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 and companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where t2.companynr > 0 or t2.companynr < 0 or t4.companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select t2.companynr,companyname from t4 left join t2 using (companynr) where ifnull(t2.companynr,1)>0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr is null; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 +explain select companynr,companyname from t4 left join t2 using (companynr) where companynr > 0 or companynr < 0 or companynr > 0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL PRIMARY NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 +explain select companynr,companyname from t4 left join t2 using (companynr) where ifnull(companynr,1)>0; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 ALL NULL NULL NULL NULL 12 Using where +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 +select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; +companynr companynr +37 36 +41 40 +explain select distinct t2.companynr,t4.companynr from t2,t4 where t2.companynr=t4.companynr+1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t4 index NULL PRIMARY 1 NULL 12 Using index; Using temporary +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +select t2.fld1,t2.companynr,fld3,period from t3,t2 where t2.fld1 = 38208 and t2.fld1=t3.t2nr and period = 1008 or t2.fld1 = 38008 and t2.fld1 =t3.t2nr and period = 1008; +fld1 companynr fld3 period +038008 37 reporters 1008 +038208 37 Selfridge 1008 +select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t2.fld1 = 38208 or t2.fld1 = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009; +fld1 companynr fld3 period +038008 37 reporters 1008 +038208 37 Selfridge 1008 +select t2.fld1,t2.companynr,fld3,period from t3,t2 where (t3.t2nr = 38208 or t3.t2nr = 38008) and t2.fld1=t3.t2nr and period>=1008 and period<=1009; +fld1 companynr fld3 period +038008 37 reporters 1008 +038208 37 Selfridge 1008 +select period from t1 where (((period > 0) or period < 10000 or (period = 1900)) and (period=1900 and period <= 1901) or (period=1903 and (period=1903)) and period>=1902) or ((period=1904 or period=1905) or (period=1906 or period>1907)) or (period=1908 and period = 1909); +period +9410 +select period from t1 where ((period > 0 and period < 1) or (((period > 0 and period < 100) and (period > 10)) or (period > 10)) or (period > 0 and (period > 5 or period > 6))); +period +9410 +select a.fld1 from t2 as a,t2 b where ((a.fld1 = 250501 and a.fld1=b.fld1) or a.fld1=250502 or a.fld1=250503 or (a.fld1=250505 and a.fld1<=b.fld1 and b.fld1>=a.fld1)) and a.fld1=b.fld1; +fld1 +250501 +250502 +250503 +250505 +select fld1 from t2 where fld1 in (250502,98005,98006,250503,250605,250606) and fld1 >=250502 and fld1 not in (250605,250606); +fld1 +250502 +250503 +select fld1 from t2 where fld1 between 250502 and 250504; +fld1 +250502 +250503 +250504 +select fld3 from t2 where (((fld3 like "_%L%" ) or (fld3 like "%ok%")) and ( fld3 like "L%" or fld3 like "G%")) and fld3 like "L%" ; +fld3 +label +labeled +labeled +landslide +laterally +leaflet +lewdly +Lillian +luckily +select count(*) from t1; +count(*) +1 +select companynr,count(*),sum(fld1) from t2 group by companynr; +companynr count(*) sum(fld1) +00 82 10355753 +29 95 14473298 +34 70 17788966 +36 215 22786296 +37 588 83602098 +40 37 6618386 +41 52 12816335 +50 11 1595438 +53 4 793210 +58 23 2254293 +65 10 2284055 +68 12 3097288 +select companynr,count(*) from t2 group by companynr order by companynr desc limit 5; +companynr count(*) +68 12 +65 10 +58 23 +53 4 +50 11 +select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; +count(*) min(fld4) max(fld4) sum(fld1) avg(fld1) std(fld1) variance(fld1) +70 absentee vest 17788966 254128.0857 3272.5940 10709871.3069 +explain extended select count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 where companynr = 34 and fld4<>""; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 Using where +Warnings: +Note 1003 select count(0) AS `count(*)`,min(`test`.`t2`.`fld4`) AS `min(fld4)`,max(`test`.`t2`.`fld4`) AS `max(fld4)`,sum(`test`.`t2`.`fld1`) AS `sum(fld1)`,avg(`test`.`t2`.`fld1`) AS `avg(fld1)`,std(`test`.`t2`.`fld1`) AS `std(fld1)`,variance(`test`.`t2`.`fld1`) AS `variance(fld1)` from `test`.`t2` where ((`test`.`t2`.`companynr` = 34) and (`test`.`t2`.`fld4` <> _latin1'')) +select companynr,count(*),min(fld4),max(fld4),sum(fld1),avg(fld1),std(fld1),variance(fld1) from t2 group by companynr limit 3; +companynr count(*) min(fld4) max(fld4) sum(fld1) avg(fld1) std(fld1) variance(fld1) +00 82 Anthony windmills 10355753 126289.6707 115550.9757 13352027981.7087 +29 95 abut wetness 14473298 152350.5053 8368.5480 70032594.9026 +34 70 absentee vest 17788966 254128.0857 3272.5940 10709871.3069 +select companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10; +companynr t2nr count(price) sum(price) min(price) max(price) avg(price) +37 1 1 5987435 5987435 5987435 5987435.0000 +37 2 1 28357832 28357832 28357832 28357832.0000 +37 3 1 39654943 39654943 39654943 39654943.0000 +37 11 1 5987435 5987435 5987435 5987435.0000 +37 12 1 28357832 28357832 28357832 28357832.0000 +37 13 1 39654943 39654943 39654943 39654943.0000 +37 21 1 5987435 5987435 5987435 5987435.0000 +37 22 1 28357832 28357832 28357832 28357832.0000 +37 23 1 39654943 39654943 39654943 39654943.0000 +37 31 1 5987435 5987435 5987435 5987435.0000 +select /*! SQL_SMALL_RESULT */ companynr,t2nr,count(price),sum(price),min(price),max(price),avg(price) from t3 where companynr = 37 group by companynr,t2nr limit 10; +companynr t2nr count(price) sum(price) min(price) max(price) avg(price) +37 1 1 5987435 5987435 5987435 5987435.0000 +37 2 1 28357832 28357832 28357832 28357832.0000 +37 3 1 39654943 39654943 39654943 39654943.0000 +37 11 1 5987435 5987435 5987435 5987435.0000 +37 12 1 28357832 28357832 28357832 28357832.0000 +37 13 1 39654943 39654943 39654943 39654943.0000 +37 21 1 5987435 5987435 5987435 5987435.0000 +37 22 1 28357832 28357832 28357832 28357832.0000 +37 23 1 39654943 39654943 39654943 39654943.0000 +37 31 1 5987435 5987435 5987435 5987435.0000 +select companynr,count(price),sum(price),min(price),max(price),avg(price) from t3 group by companynr ; +companynr count(price) sum(price) min(price) max(price) avg(price) +37 12543 309394878010 5987435 39654943 24666736.6667 +78 8362 414611089292 726498 98439034 49582766.0000 +101 4181 3489454238 834598 834598 834598.0000 +154 4181 4112197254950 983543950 983543950 983543950.0000 +311 4181 979599938 234298 234298 234298.0000 +447 4181 9929180954 2374834 2374834 2374834.0000 +512 4181 3288532102 786542 786542 786542.0000 +select distinct mod(companynr,10) from t4 group by companynr; +mod(companynr,10) +0 +9 +4 +6 +7 +1 +3 +8 +5 +select distinct 1 from t4 group by companynr; +1 +1 +select count(distinct fld1) from t2; +count(distinct fld1) +1199 +select companynr,count(distinct fld1) from t2 group by companynr; +companynr count(distinct fld1) +00 82 +29 95 +34 70 +36 215 +37 588 +40 37 +41 52 +50 11 +53 4 +58 23 +65 10 +68 12 +select companynr,count(*) from t2 group by companynr; +companynr count(*) +00 82 +29 95 +34 70 +36 215 +37 588 +40 37 +41 52 +50 11 +53 4 +58 23 +65 10 +68 12 +select companynr,count(distinct concat(fld1,repeat(65,1000))) from t2 group by companynr; +companynr count(distinct concat(fld1,repeat(65,1000))) +00 82 +29 95 +34 70 +36 215 +37 588 +40 37 +41 52 +50 11 +53 4 +58 23 +65 10 +68 12 +select companynr,count(distinct concat(fld1,repeat(65,200))) from t2 group by companynr; +companynr count(distinct concat(fld1,repeat(65,200))) +00 82 +29 95 +34 70 +36 215 +37 588 +40 37 +41 52 +50 11 +53 4 +58 23 +65 10 +68 12 +select companynr,count(distinct floor(fld1/100)) from t2 group by companynr; +companynr count(distinct floor(fld1/100)) +00 47 +29 35 +34 14 +36 69 +37 108 +40 16 +41 11 +50 9 +53 1 +58 1 +65 1 +68 1 +select companynr,count(distinct concat(repeat(65,1000),floor(fld1/100))) from t2 group by companynr; +companynr count(distinct concat(repeat(65,1000),floor(fld1/100))) +00 47 +29 35 +34 14 +36 69 +37 108 +40 16 +41 11 +50 9 +53 1 +58 1 +65 1 +68 1 +select sum(fld1),fld3 from t2 where fld3="Romans" group by fld1 limit 10; +sum(fld1) fld3 +11402 Romans +select name,count(*) from t3 where name='cloakroom' group by name; +name count(*) +cloakroom 4181 +select name,count(*) from t3 where name='cloakroom' and price>10 group by name; +name count(*) +cloakroom 4181 +select count(*) from t3 where name='cloakroom' and price2=823742; +count(*) +4181 +select name,count(*) from t3 where name='cloakroom' and price2=823742 group by name; +name count(*) +cloakroom 4181 +select name,count(*) from t3 where name >= "extramarital" and price <= 39654943 group by name; +name count(*) +extramarital 4181 +gazer 4181 +gems 4181 +Iranizes 4181 +spates 4181 +tucked 4181 +violinist 4181 +select t2.fld3,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name; +fld3 count(*) +spates 4181 +select companynr|0,companyname from t4 group by 1; +companynr|0 companyname +0 Unknown +29 company 1 +34 company 2 +36 company 3 +37 company 4 +40 company 5 +41 company 6 +50 company 11 +53 company 7 +58 company 8 +65 company 9 +68 company 10 +select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by t2.companynr order by companyname; +companynr companyname count(*) +29 company 1 95 +68 company 10 12 +50 company 11 11 +34 company 2 70 +36 company 3 215 +37 company 4 588 +40 company 5 37 +41 company 6 52 +53 company 7 4 +58 company 8 23 +65 company 9 10 +00 Unknown 82 +select t2.fld1,count(*) from t2,t3 where t2.fld1=158402 and t3.name=t2.fld3 group by t3.name; +fld1 count(*) +158402 4181 +select sum(Period)/count(*) from t1; +sum(Period)/count(*) +9410.0000 +select companynr,count(price) as "count",sum(price) as "sum" ,abs(sum(price)/count(price)-avg(price)) as "diff",(0+count(price))*companynr as func from t3 group by companynr; +companynr count sum diff func +37 12543 309394878010 0.0000 464091 +78 8362 414611089292 0.0000 652236 +101 4181 3489454238 0.0000 422281 +154 4181 4112197254950 0.0000 643874 +311 4181 979599938 0.0000 1300291 +447 4181 9929180954 0.0000 1868907 +512 4181 3288532102 0.0000 2140672 +select companynr,sum(price)/count(price) as avg from t3 group by companynr having avg > 70000000 order by avg; +companynr avg +154 983543950.0000 +select companynr,count(*) from t2 group by companynr order by 2 desc; +companynr count(*) +37 588 +36 215 +29 95 +00 82 +34 70 +41 52 +40 37 +58 23 +68 12 +50 11 +65 10 +53 4 +select companynr,count(*) from t2 where companynr > 40 group by companynr order by 2 desc; +companynr count(*) +41 52 +58 23 +68 12 +50 11 +65 10 +53 4 +select t2.fld4,t2.fld1,count(price),sum(price),min(price),max(price),avg(price) from t3,t2 where t3.companynr = 37 and t2.fld1 = t3.t2nr group by fld1,t2.fld4; +fld4 fld1 count(price) sum(price) min(price) max(price) avg(price) +teethe 000001 1 5987435 5987435 5987435 5987435.0000 +dreaded 011401 1 5987435 5987435 5987435 5987435.0000 +scholastics 011402 1 28357832 28357832 28357832 28357832.0000 +audiology 011403 1 39654943 39654943 39654943 39654943.0000 +wallet 011501 1 5987435 5987435 5987435 5987435.0000 +parters 011701 1 5987435 5987435 5987435 5987435.0000 +eschew 011702 1 28357832 28357832 28357832 28357832.0000 +quitter 011703 1 39654943 39654943 39654943 39654943.0000 +neat 012001 1 5987435 5987435 5987435 5987435.0000 +Steinberg 012003 1 39654943 39654943 39654943 39654943.0000 +balled 012301 1 5987435 5987435 5987435 5987435.0000 +persist 012302 1 28357832 28357832 28357832 28357832.0000 +attainments 012303 1 39654943 39654943 39654943 39654943.0000 +capably 012501 1 5987435 5987435 5987435 5987435.0000 +impulsive 012602 1 28357832 28357832 28357832 28357832.0000 +starlet 012603 1 39654943 39654943 39654943 39654943.0000 +featherweight 012701 1 5987435 5987435 5987435 5987435.0000 +pessimist 012702 1 28357832 28357832 28357832 28357832.0000 +daughter 012703 1 39654943 39654943 39654943 39654943.0000 +lawgiver 013601 1 5987435 5987435 5987435 5987435.0000 +stated 013602 1 28357832 28357832 28357832 28357832.0000 +readable 013603 1 39654943 39654943 39654943 39654943.0000 +testicle 013801 1 5987435 5987435 5987435 5987435.0000 +Parsifal 013802 1 28357832 28357832 28357832 28357832.0000 +leavings 013803 1 39654943 39654943 39654943 39654943.0000 +squeaking 013901 1 5987435 5987435 5987435 5987435.0000 +contrasted 016001 1 5987435 5987435 5987435 5987435.0000 +leftover 016201 1 5987435 5987435 5987435 5987435.0000 +whiteners 016202 1 28357832 28357832 28357832 28357832.0000 +erases 016301 1 5987435 5987435 5987435 5987435.0000 +Punjab 016302 1 28357832 28357832 28357832 28357832.0000 +Merritt 016303 1 39654943 39654943 39654943 39654943.0000 +sweetish 018001 1 5987435 5987435 5987435 5987435.0000 +dogging 018002 1 28357832 28357832 28357832 28357832.0000 +scornfully 018003 1 39654943 39654943 39654943 39654943.0000 +fetters 018012 1 28357832 28357832 28357832 28357832.0000 +bivalves 018013 1 39654943 39654943 39654943 39654943.0000 +skulking 018021 1 5987435 5987435 5987435 5987435.0000 +flint 018022 1 28357832 28357832 28357832 28357832.0000 +flopping 018023 1 39654943 39654943 39654943 39654943.0000 +Judas 018032 1 28357832 28357832 28357832 28357832.0000 +vacuuming 018033 1 39654943 39654943 39654943 39654943.0000 +medical 018041 1 5987435 5987435 5987435 5987435.0000 +bloodbath 018042 1 28357832 28357832 28357832 28357832.0000 +subschema 018043 1 39654943 39654943 39654943 39654943.0000 +interdependent 018051 1 5987435 5987435 5987435 5987435.0000 +Graves 018052 1 28357832 28357832 28357832 28357832.0000 +neonatal 018053 1 39654943 39654943 39654943 39654943.0000 +sorters 018061 1 5987435 5987435 5987435 5987435.0000 +epistle 018062 1 28357832 28357832 28357832 28357832.0000 +Conley 018101 1 5987435 5987435 5987435 5987435.0000 +lectured 018102 1 28357832 28357832 28357832 28357832.0000 +Abraham 018103 1 39654943 39654943 39654943 39654943.0000 +cage 018201 1 5987435 5987435 5987435 5987435.0000 +hushes 018202 1 28357832 28357832 28357832 28357832.0000 +Simla 018402 1 28357832 28357832 28357832 28357832.0000 +reporters 018403 1 39654943 39654943 39654943 39654943.0000 +coexist 018601 1 5987435 5987435 5987435 5987435.0000 +Beebe 018602 1 28357832 28357832 28357832 28357832.0000 +Taoism 018603 1 39654943 39654943 39654943 39654943.0000 +Connally 018801 1 5987435 5987435 5987435 5987435.0000 +fetched 018802 1 28357832 28357832 28357832 28357832.0000 +checkpoints 018803 1 39654943 39654943 39654943 39654943.0000 +gritty 018811 1 5987435 5987435 5987435 5987435.0000 +firearm 018812 1 28357832 28357832 28357832 28357832.0000 +minima 019101 1 5987435 5987435 5987435 5987435.0000 +Selfridge 019102 1 28357832 28357832 28357832 28357832.0000 +disable 019103 1 39654943 39654943 39654943 39654943.0000 +witchcraft 019201 1 5987435 5987435 5987435 5987435.0000 +betroth 030501 1 5987435 5987435 5987435 5987435.0000 +Manhattanize 030502 1 28357832 28357832 28357832 28357832.0000 +imprint 030503 1 39654943 39654943 39654943 39654943.0000 +swelling 031901 1 5987435 5987435 5987435 5987435.0000 +interrelationships 036001 1 5987435 5987435 5987435 5987435.0000 +riser 036002 1 28357832 28357832 28357832 28357832.0000 +bee 038001 1 5987435 5987435 5987435 5987435.0000 +kanji 038002 1 28357832 28357832 28357832 28357832.0000 +dental 038003 1 39654943 39654943 39654943 39654943.0000 +railway 038011 1 5987435 5987435 5987435 5987435.0000 +validate 038012 1 28357832 28357832 28357832 28357832.0000 +normalizes 038013 1 39654943 39654943 39654943 39654943.0000 +Kline 038101 1 5987435 5987435 5987435 5987435.0000 +Anatole 038102 1 28357832 28357832 28357832 28357832.0000 +partridges 038103 1 39654943 39654943 39654943 39654943.0000 +recruited 038201 1 5987435 5987435 5987435 5987435.0000 +dimensions 038202 1 28357832 28357832 28357832 28357832.0000 +Chicana 038203 1 39654943 39654943 39654943 39654943.0000 +select t3.companynr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 group by companynr,fld3; +companynr fld3 sum(price) +512 boat 786542 +512 capably 786542 +512 cupboard 786542 +512 decliner 786542 +512 descendants 786542 +512 dopers 786542 +512 erases 786542 +512 Micronesia 786542 +512 Miles 786542 +512 skies 786542 +select t2.companynr,count(*),min(fld3),max(fld3),sum(price),avg(price) from t2,t3 where t3.companynr >= 30 and t3.companynr <= 58 and t3.t2nr = t2.fld1 and 1+1=2 group by t2.companynr; +companynr count(*) min(fld3) max(fld3) sum(price) avg(price) +00 1 Omaha Omaha 5987435 5987435.0000 +36 1 dubbed dubbed 28357832 28357832.0000 +37 83 Abraham Wotan 1908978016 22999735.1325 +50 2 scribbled tapestry 68012775 34006387.5000 +select t3.companynr+0,t3.t2nr,fld3,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 37 group by 1,t3.t2nr,fld3,fld3,fld3,fld3,fld3 order by fld1; +t3.companynr+0 t2nr fld3 sum(price) +37 1 Omaha 5987435 +37 11401 breaking 5987435 +37 11402 Romans 28357832 +37 11403 intercepted 39654943 +37 11501 bewilderingly 5987435 +37 11701 astound 5987435 +37 11702 admonishing 28357832 +37 11703 sumac 39654943 +37 12001 flanking 5987435 +37 12003 combed 39654943 +37 12301 Eulerian 5987435 +37 12302 dubbed 28357832 +37 12303 Kane 39654943 +37 12501 annihilates 5987435 +37 12602 Wotan 28357832 +37 12603 snatching 39654943 +37 12701 grazing 5987435 +37 12702 Baird 28357832 +37 12703 celery 39654943 +37 13601 handgun 5987435 +37 13602 foldout 28357832 +37 13603 mystic 39654943 +37 13801 intelligibility 5987435 +37 13802 Augustine 28357832 +37 13803 teethe 39654943 +37 13901 scholastics 5987435 +37 16001 audiology 5987435 +37 16201 wallet 5987435 +37 16202 parters 28357832 +37 16301 eschew 5987435 +37 16302 quitter 28357832 +37 16303 neat 39654943 +37 18001 jarring 5987435 +37 18002 tinily 28357832 +37 18003 balled 39654943 +37 18012 impulsive 28357832 +37 18013 starlet 39654943 +37 18021 lawgiver 5987435 +37 18022 stated 28357832 +37 18023 readable 39654943 +37 18032 testicle 28357832 +37 18033 Parsifal 39654943 +37 18041 Punjab 5987435 +37 18042 Merritt 28357832 +37 18043 Quixotism 39654943 +37 18051 sureties 5987435 +37 18052 puddings 28357832 +37 18053 tapestry 39654943 +37 18061 trimmings 5987435 +37 18062 humility 28357832 +37 18101 tragedies 5987435 +37 18102 skulking 28357832 +37 18103 flint 39654943 +37 18201 relaxing 5987435 +37 18202 offload 28357832 +37 18402 suites 28357832 +37 18403 lists 39654943 +37 18601 vacuuming 5987435 +37 18602 dentally 28357832 +37 18603 humanness 39654943 +37 18801 inch 5987435 +37 18802 Weissmuller 28357832 +37 18803 irresponsibly 39654943 +37 18811 repetitions 5987435 +37 18812 Antares 28357832 +37 19101 ventilate 5987435 +37 19102 pityingly 28357832 +37 19103 interdependent 39654943 +37 19201 Graves 5987435 +37 30501 neonatal 5987435 +37 30502 scribbled 28357832 +37 30503 chafe 39654943 +37 31901 realtor 5987435 +37 36001 elite 5987435 +37 36002 funereal 28357832 +37 38001 Conley 5987435 +37 38002 lectured 28357832 +37 38003 Abraham 39654943 +37 38011 groupings 5987435 +37 38012 dissociate 28357832 +37 38013 coexist 39654943 +37 38101 rusting 5987435 +37 38102 galling 28357832 +37 38103 obliterates 39654943 +37 38201 resumes 5987435 +37 38202 analyzable 28357832 +37 38203 terminator 39654943 +select sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1= t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008; +sum(price) +234298 +select t2.fld1,sum(price) from t3,t2 where t2.fld1 = t3.t2nr and t3.companynr = 512 and t3.t2nr = 38008 and t2.fld1 = 38008 or t2.fld1 = t3.t2nr and t3.t2nr = 38008 and t2.fld1 = 38008 or t3.t2nr = t2.fld1 and t2.fld1 = 38008 group by t2.fld1; +fld1 sum(price) +038008 234298 +explain select fld3 from t2 where 1>2 or 2>3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE +explain select fld3 from t2 where fld1=fld1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ALL NULL NULL NULL NULL 1199 +select companynr,fld1 from t2 HAVING fld1=250501 or fld1=250502; +companynr fld1 +34 250501 +34 250502 +select companynr,fld1 from t2 WHERE fld1>=250501 HAVING fld1<=250502; +companynr fld1 +34 250501 +34 250502 +select companynr,count(*) as count,sum(fld1) as sum from t2 group by companynr having count > 40 and sum/count >= 120000; +companynr count sum +00 82 10355753 +29 95 14473298 +34 70 17788966 +37 588 83602098 +41 52 12816335 +select companynr from t2 group by companynr having count(*) > 40 and sum(fld1)/count(*) >= 120000 ; +companynr +00 +29 +34 +37 +41 +select t2.companynr,companyname,count(*) from t2,t4 where t2.companynr=t4.companynr group by companyname having t2.companynr >= 40; +companynr companyname count(*) +68 company 10 12 +50 company 11 11 +40 company 5 37 +41 company 6 52 +53 company 7 4 +58 company 8 23 +65 company 9 10 +select count(*) from t2; +count(*) +1199 +select count(*) from t2 where fld1 < 098024; +count(*) +387 +select min(fld1) from t2 where fld1>= 098024; +min(fld1) +98024 +select max(fld1) from t2 where fld1>= 098024; +max(fld1) +1232609 +select count(*) from t3 where price2=76234234; +count(*) +4181 +select count(*) from t3 where companynr=512 and price2=76234234; +count(*) +4181 +explain select min(fld1),max(fld1),count(*) from t2; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away +select min(fld1),max(fld1),count(*) from t2; +min(fld1) max(fld1) count(*) +0 1232609 1199 +select min(t2nr),max(t2nr) from t3 where t2nr=2115 and price2=823742; +min(t2nr) max(t2nr) +2115 2115 +select count(*),min(t2nr),max(t2nr) from t3 where name='spates' and companynr=78; +count(*) min(t2nr) max(t2nr) +4181 4 41804 +select t2nr,count(*) from t3 where name='gems' group by t2nr limit 20; +t2nr count(*) +9 1 +19 1 +29 1 +39 1 +49 1 +59 1 +69 1 +79 1 +89 1 +99 1 +109 1 +119 1 +129 1 +139 1 +149 1 +159 1 +169 1 +179 1 +189 1 +199 1 +select max(t2nr) from t3 where price=983543950; +max(t2nr) +41807 +select t1.period from t3 = t1 limit 1; +period +1001 +select t1.period from t1 as t1 limit 1; +period +9410 +select t1.period as "Nuvarande period" from t1 as t1 limit 1; +Nuvarande period +9410 +select period as ok_period from t1 limit 1; +ok_period +9410 +select period as ok_period from t1 group by ok_period limit 1; +ok_period +9410 +select 1+1 as summa from t1 group by summa limit 1; +summa +2 +select period as "Nuvarande period" from t1 group by "Nuvarande period" limit 1; +Nuvarande period +9410 +show tables; +Tables_in_test +t1 +t2 +t3 +t4 +show tables from test like "s%"; +Tables_in_test (s%) +show tables from test like "t?"; +Tables_in_test (t?) +show full columns from t2; +Field Type Collation Null Key Default Extra Privileges Comment +auto int(11) NULL NO PRI NULL auto_increment # +fld1 int(6) unsigned zerofill NULL NO UNI 000000 # +companynr tinyint(2) unsigned zerofill NULL NO 00 # +fld3 char(30) latin1_swedish_ci NO MUL # +fld4 char(35) latin1_swedish_ci NO # +fld5 char(35) latin1_swedish_ci NO # +fld6 char(4) latin1_swedish_ci NO # +show full columns from t2 from test like 'f%'; +Field Type Collation Null Key Default Extra Privileges Comment +fld1 int(6) unsigned zerofill NULL NO UNI 000000 # +fld3 char(30) latin1_swedish_ci NO MUL # +fld4 char(35) latin1_swedish_ci NO # +fld5 char(35) latin1_swedish_ci NO # +fld6 char(4) latin1_swedish_ci NO # +show full columns from t2 from test like 's%'; +Field Type Collation Null Key Default Extra Privileges Comment +show keys from t2; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment +t2 0 PRIMARY 1 auto A 1199 NULL NULL BTREE +t2 0 fld1 1 fld1 A 1199 NULL NULL BTREE +t2 1 fld3 1 fld3 A NULL NULL NULL BTREE +drop table t4, t3, t2, t1; +CREATE TABLE t1 ( +cont_nr int(11) NOT NULL auto_increment, +ver_nr int(11) NOT NULL default '0', +aufnr int(11) NOT NULL default '0', +username varchar(50) NOT NULL default '', +hdl_nr int(11) NOT NULL default '0', +eintrag date NOT NULL default '0000-00-00', +st_klasse varchar(40) NOT NULL default '', +st_wert varchar(40) NOT NULL default '', +st_zusatz varchar(40) NOT NULL default '', +st_bemerkung varchar(255) NOT NULL default '', +kunden_art varchar(40) NOT NULL default '', +mcbs_knr int(11) default NULL, +mcbs_aufnr int(11) NOT NULL default '0', +schufa_status char(1) default '?', +bemerkung text, +wirknetz text, +wf_igz int(11) NOT NULL default '0', +tarifcode varchar(80) default NULL, +recycle char(1) default NULL, +sim varchar(30) default NULL, +mcbs_tpl varchar(30) default NULL, +emp_nr int(11) NOT NULL default '0', +laufzeit int(11) default NULL, +hdl_name varchar(30) default NULL, +prov_hdl_nr int(11) NOT NULL default '0', +auto_wirknetz varchar(50) default NULL, +auto_billing varchar(50) default NULL, +touch timestamp NOT NULL, +kategorie varchar(50) default NULL, +kundentyp varchar(20) NOT NULL default '', +sammel_rech_msisdn varchar(30) NOT NULL default '', +p_nr varchar(9) NOT NULL default '', +suffix char(3) NOT NULL default '', +PRIMARY KEY (cont_nr), +KEY idx_aufnr(aufnr), +KEY idx_hdl_nr(hdl_nr), +KEY idx_st_klasse(st_klasse), +KEY ver_nr(ver_nr), +KEY eintrag_idx(eintrag), +KEY emp_nr_idx(emp_nr), +KEY wf_igz(wf_igz), +KEY touch(touch), +KEY hdl_tag(eintrag,hdl_nr), +KEY prov_hdl_nr(prov_hdl_nr), +KEY mcbs_aufnr(mcbs_aufnr), +KEY kundentyp(kundentyp), +KEY p_nr(p_nr,suffix) +) ENGINE=MyISAM; +INSERT INTO t1 VALUES (3359356,405,3359356,'Mustermann Musterfrau',52500,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1485525,2122316,'+','','N',1909160,'MobilComSuper92000D2',NULL,NULL,'MS9ND2',3,24,'MobilCom Shop Koeln',52500,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); +INSERT INTO t1 VALUES (3359357,468,3359357,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1503580,2139699,'+','','P',1909171,'MobilComSuper9D1T10SFreisprech(Akquise)',NULL,NULL,'MS9NS1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); +INSERT INTO t1 VALUES (3359358,407,3359358,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1501358,2137473,'N','','N',1909159,'MobilComSuper92000D2',NULL,NULL,'MS9ND2',325,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); +INSERT INTO t1 VALUES (3359359,468,3359359,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1507831,2143894,'+','','P',1909162,'MobilComSuper9D1T10SFreisprech(Akquise)',NULL,NULL,'MS9NS1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); +INSERT INTO t1 VALUES (3359360,0,0,'Mustermann Musterfrau',29674907,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1900169997,2414578,'+',NULL,'N',1909148,'',NULL,NULL,'RV99066_2',20,NULL,'POS',29674907,NULL,NULL,20010202105916,'Mobilfunk','','','97317481','007'); +INSERT INTO t1 VALUES (3359361,406,3359361,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag storniert','','(7001-84):Storno, Kd. möchte nicht mehr','privat',NULL,0,'+','','P',1909150,'MobilComSuper92000D1(Akquise)',NULL,NULL,'MS9ND1',325,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); +INSERT INTO t1 VALUES (3359362,406,3359362,'Mustermann Musterfrau',7001,'2000-05-20','workflow','Auftrag erledigt','Originalvertrag eingegangen und geprüft','','privat',1509984,2145874,'+','','P',1909154,'MobilComSuper92000D1(Akquise)',NULL,NULL,'MS9ND1',327,24,'MobilCom Intern',7003,NULL,'auto',20010202105916,'Mobilfunk','PP','','',''); +SELECT ELT(FIELD(kundentyp,'PP','PPA','PG','PGA','FK','FKA','FP','FPA','K','KA','V','VA',''), 'Privat (Private Nutzung)','Privat (Private Nutzung) Sitz im Ausland','Privat (geschaeftliche Nutzung)','Privat (geschaeftliche Nutzung) Sitz im Ausland','Firma (Kapitalgesellschaft)','Firma (Kapitalgesellschaft) Sitz im Ausland','Firma (Personengesellschaft)','Firma (Personengesellschaft) Sitz im Ausland','oeff. rechtl. Koerperschaft','oeff. rechtl. Koerperschaft Sitz im Ausland','Eingetragener Verein','Eingetragener Verein Sitz im Ausland','Typ unbekannt') AS Kundentyp ,kategorie FROM t1 WHERE hdl_nr < 2000000 AND kategorie IN ('Prepaid','Mobilfunk') AND st_klasse = 'Workflow' GROUP BY kundentyp ORDER BY kategorie; +Kundentyp kategorie +Privat (Private Nutzung) Mobilfunk +Warnings: +Warning 1052 Column 'kundentyp' in group statement is ambiguous +drop table t1; +SHOW STATUS LIKE 'Ssl_cipher'; +Variable_name Value +Ssl_cipher DHE-RSA-AES256-SHA diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index e57cc44ddd4..ecd9762dd24 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -2717,8 +2717,7 @@ select (1,2,3) = (select * from t1); ERROR 21000: Operand should contain 3 column(s) select (select * from t1) = (1,2,3); ERROR 21000: Operand should contain 2 column(s) -drop table t1 -#; +drop table t1; CREATE TABLE `t1` ( `itemid` bigint(20) unsigned NOT NULL auto_increment, `sessionid` bigint(20) unsigned default NULL, diff --git a/mysql-test/r/synchronization.result b/mysql-test/r/synchronization.result index 697eb064998..4543a829494 100644 --- a/mysql-test/r/synchronization.result +++ b/mysql-test/r/synchronization.result @@ -1,6 +1,6 @@ drop table if exists t1; CREATE TABLE t1 (x1 int); - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -8,7 +8,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -16,7 +16,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -24,7 +24,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -32,7 +32,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -40,7 +40,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -48,7 +48,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -56,7 +56,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -64,7 +64,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -72,7 +72,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -80,7 +80,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -88,7 +88,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -96,7 +96,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -104,7 +104,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -112,7 +112,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -120,7 +120,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -128,7 +128,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -136,7 +136,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -144,7 +144,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x1 x2 int; +ALTER TABLE t1 CHANGE x1 x2 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table @@ -152,7 +152,7 @@ t2 CREATE TABLE `t2` ( `xx` int(11) DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t2; - ALTER TABLE t1 CHANGE x2 x1 int; +ALTER TABLE t1 CHANGE x2 x1 int; CREATE TABLE t2 LIKE t1; SHOW CREATE TABLE t2; Table Create Table diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index 5f027195e2e..52123885772 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -1073,10 +1073,11 @@ SELECT @x; NULL SET @x=2; UPDATE t1 SET i1 = @x; -ERROR 22012: Division by 0 +Warnings: +Error 1365 Division by 0 SELECT @x; @x -2 +NULL SET SQL_MODE=''; SET @x=3; INSERT INTO t1 VALUES (@x); @@ -1085,10 +1086,12 @@ SELECT @x; NULL SET @x=4; UPDATE t1 SET i1 = @x; -ERROR 22012: Division by 0 +Warnings: +Error 1365 Division by 0 +Error 1365 Division by 0 SELECT @x; @x -4 +NULL SET @@sql_mode=@save_sql_mode; DROP TRIGGER t1_ai; DROP TRIGGER t1_au; @@ -1174,6 +1177,59 @@ ERROR HY000: String '1234567890abcdefghij1234567890abcdefghij1234567890abcdefghi DROP TABLE t1; DROP TABLE t2; drop table if exists t1; +drop table if exists t2; +drop table if exists t3; +drop table if exists t4; +SET @save_sql_mode=@@sql_mode; +SET sql_mode='TRADITIONAL'| +create table t1 (id int(10) not null primary key, v int(10) )| +create table t2 (id int(10) not null primary key, v int(10) )| +create table t3 (id int(10) not null primary key, v int(10) )| +create table t4 (c int)| +create trigger t4_bi before insert on t4 for each row set @t4_bi_called:=1| +create trigger t4_bu before update on t4 for each row set @t4_bu_called:=1| +insert into t1 values(10, 10)| +set @a:=1/0| +Warnings: +Error 1365 Division by 0 +select 1/0 from t1| +1/0 +NULL +Warnings: +Error 1365 Division by 0 +create trigger t1_bi before insert on t1 for each row set @a:=1/0| +insert into t1 values(20, 20)| +Warnings: +Error 1365 Division by 0 +drop trigger t1_bi| +create trigger t1_bi before insert on t1 for each row +begin +insert into t2 values (new.id, new.v); +update t2 set v=v+1 where id= new.id; +replace t3 values (new.id, 0); +update t2, t3 set t2.v=new.v, t3.v=new.v where t2.id=t3.id; +create temporary table t5 select * from t1; +delete from t5; +insert into t5 select * from t1; +insert into t4 values (0); +set @check= (select count(*) from t5); +update t4 set c= @check; +drop temporary table t5; +set @a:=1/0; +end| +set @check=0, @t4_bi_called=0, @t4_bu_called=0| +insert into t1 values(30, 30)| +Warnings: +Error 1365 Division by 0 +select @check, @t4_bi_called, @t4_bu_called| +@check @t4_bi_called @t4_bu_called +2 1 1 +SET @@sql_mode=@save_sql_mode; +drop table t1; +drop table t2; +drop table t3; +drop table t4; +drop table if exists t1; create table t1 (i int, j int key); insert into t1 values (1,1), (2,2), (3,3); create trigger t1_bu before update on t1 for each row diff --git a/mysql-test/r/type_newdecimal.result b/mysql-test/r/type_newdecimal.result index 0b6bdfda6bc..595c15afcc2 100644 --- a/mysql-test/r/type_newdecimal.result +++ b/mysql-test/r/type_newdecimal.result @@ -978,8 +978,6 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM DEFAULT CHARSET=latin1 drop table t1; drop procedure if exists wg2; -Warnings: -Note 1305 PROCEDURE wg2 does not exist create procedure wg2() begin declare v int default 1; diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index 53497fd528b..8382f521b84 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -215,6 +215,7 @@ select @@version; select @@global.version; @@global.version # +End of 4.1 tests set @first_var= NULL; create table t1 select @first_var; show create table t1; @@ -301,3 +302,11 @@ select @var; @var 3 drop table t1; +insert into city 'blah'; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''blah'' at line 1 +SHOW COUNT(*) WARNINGS; +@@session.warning_count +1 +SHOW COUNT(*) ERRORS; +@@session.error_count +1 diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index c599d9e84fd..3220e08c7d7 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -12,6 +12,9 @@ create table t1 (a int, b int); insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); create view v1 (c,d) as select a,b+@@global.max_user_connections from t1; ERROR HY000: View's SELECT contains a variable or parameter +create view v1 (c,d) as select a,b from t1 +where a = @@global.max_user_connections; +ERROR HY000: View's SELECT contains a variable or parameter create view v1 (c) as select b+1 from t1; select c from v1; c @@ -596,11 +599,6 @@ ERROR HY000: View 'test.v1' references invalid table(s) or column(s) or function drop view v1; create view v1 (a,a) as select 'a','a'; ERROR 42S21: Duplicate column name 'a' -drop procedure if exists p1; -create procedure p1 () begin declare v int; create view v1 as select v; end;// -call p1(); -ERROR HY000: View's SELECT contains a variable or parameter -drop procedure p1; create table t1 (col1 int,col2 char(22)); insert into t1 values(5,'Hello, world of views'); create view v1 as select * from t1; @@ -886,6 +884,8 @@ ERROR HY000: View's SELECT contains a 'INTO' clause create table t1 (a int); create view v1 as select a from t1 procedure analyse(); ERROR HY000: View's SELECT contains a 'PROCEDURE' clause +create view v1 as select 1 from (select 1) as d1; +ERROR HY000: View's SELECT contains a subquery in the FROM clause drop table t1; create table t1 (s1 int, primary key (s1)); create view v1 as select * from t1; @@ -1980,7 +1980,7 @@ v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VI drop view v1; drop table t1; set sql_mode='strict_all_tables'; -CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL) ENGINE = INNODB; +CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL); CREATE VIEW v1 (vcol1) AS SELECT col1 FROM t1; CREATE VIEW v2 (vcol1) AS SELECT col1 FROM t1 WHERE col2 > 2; INSERT INTO t1 (col1) VALUES(12); @@ -2032,7 +2032,7 @@ f3 f1 1 3 drop view v1; drop table t1; -CREATE TABLE t1 (f1 char) ENGINE = innodb; +CREATE TABLE t1 (f1 char); INSERT INTO t1 VALUES ('A'); CREATE VIEW v1 AS SELECT * FROM t1; INSERT INTO t1 VALUES('B'); @@ -2956,6 +2956,20 @@ View Create View v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`pk` AS `pk` from (`t1` join `t2` on(((`t2`.`fk` = `t1`.`pk`) and (`t2`.`ver` = (select max(`t`.`ver`) AS `MAX(t.ver)` from `t2` `t` where (`t`.`org` = `t2`.`org`)))))) DROP VIEW v1; DROP TABLE t1, t2; +DROP FUNCTION IF EXISTS f1; +DROP VIEW IF EXISTS v1; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1); +CREATE VIEW v1 AS SELECT MAX(i) FROM t1; +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW +SET NEW.i = (SELECT * FROM v1) + 1; +INSERT INTO t1 VALUES (1); +CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1); +UPDATE t1 SET i= f1(); +DROP FUNCTION f1; +DROP VIEW v1; +DROP TABLE t1; CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL); CREATE VIEW v1 AS SELECT id, val FROM t1 WHERE val >= 1 AND val <= 5 WITH CHECK OPTION; INSERT INTO v1 (val) VALUES (2); @@ -2966,6 +2980,40 @@ UPDATE v1 SET val=6 WHERE id=2; ERROR HY000: CHECK OPTION failed 'test.v1' DROP VIEW v1; DROP TABLE t1; +DROP VIEW IF EXISTS v1, v2; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT); +CREATE VIEW v1 AS SELECT j FROM t1; +CREATE VIEW v2 AS SELECT * FROM t1; +INSERT INTO t1 (j) VALUES (1); +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1 +INSERT INTO v1 (j) VALUES (2); +# LAST_INSERT_ID() should not change. +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +1 +INSERT INTO v2 (j) VALUES (3); +# LAST_INSERT_ID() should be updated. +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3 +INSERT INTO v1 (j) SELECT j FROM t1; +# LAST_INSERT_ID() should not change. +SELECT LAST_INSERT_ID(); +LAST_INSERT_ID() +3 +SELECT * FROM t1; +i j +1 1 +2 2 +3 3 +4 1 +5 2 +6 3 +DROP VIEW v1, v2; +DROP TABLE t1; End of 5.0 tests. DROP DATABASE IF EXISTS `d-1`; CREATE DATABASE `d-1`; diff --git a/mysql-test/std_data/server-cert-des.pem b/mysql-test/std_data/server-cert-des.pem new file mode 100644 index 00000000000..3b93d865d5b --- /dev/null +++ b/mysql-test/std_data/server-cert-des.pem @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIICljCCAX4CAQEwDQYJKoZIhvcNAQEEBQAwUTELMAkGA1UEBhMCU0UxEDAOBgNV +BAgTB1VwcHNhbGExETAPBgNVBAoTCE15U1FMIEFCMRAwDgYDVQQLEwdTdXBwb3J0 +MQswCQYDVQQDEwJDQTAeFw0wNjA4MjgxMTA4NTlaFw0wOTA1MjQxMTA4NTlaMFUx +CzAJBgNVBAYTAlNFMRAwDgYDVQQIEwdVcHBzYWxhMREwDwYDVQQKEwhNeVNRTCBB +QjEQMA4GA1UECxMHU3VwcG9ydDEPMA0GA1UEAxMGc2VydmVyMIGfMA0GCSqGSIb3 +DQEBAQUAA4GNADCBiQKBgQDEiOVZcWYzZe7I8xhhUwCzvmkZifAXeMTH+8XKGLHX +NWF3FLduAmeAad9oOZgBKb+oWTdRDWXqwu6nYYUBfrUpaY27/wLkgWRgewL3LZnw +W2FjhNsjx3gI2NK+Pix47q9d+a+5T4AW5+lK499l0K0k2cvyFdIerhDW8R0t8Uru +twIDAQABMA0GCSqGSIb3DQEBBAUAA4IBAQC2LQcqLg52RbelWrKutlJ5E6rzugnJ +ZAlbN9sM98O2xFiIGDA3tb5j9LAEjE0E+RqdptEYnvy9b3szhLYXtIILZTkClf9r +Uwu1nUYPTyp+9ZYCa4fovOU5h1Ogv+9UZPds/LPDwWEn8K+lvscB4X57wJyuoEck +1Mu41OA6h77181MydSdgZo0oquJDWhdCsYHXVFVs0F6naMm2uPMCTDiQVlhHJuTO +VQMNIwxRFtvsv2tpsXsaP/8sT32d5CFebfxxSVnqQvJ4ZdIrphl6L43XU01rsEcE +K8KYujZQ6SKws+HVcGqsr7TPgJfJE6D+5RazvvIQISPvx4eduebqzqdC +-----END CERTIFICATE----- diff --git a/mysql-test/std_data/server-key-des.pem b/mysql-test/std_data/server-key-des.pem new file mode 100644 index 00000000000..b35d4ab223b --- /dev/null +++ b/mysql-test/std_data/server-key-des.pem @@ -0,0 +1,18 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,D2BE7598C7E3BDA5 + +1W3qPgw5ut80OhaAGVZZe/tfFiBAlwpX1SohdApWj+QYP+dK/mdEBhgI3BXTFNLW +pJqDTzGlKtft7hHN6QDFEdZMKxej5+2iLu14V62o+5yQgUoqswoXcmmqJCJ7AvyJ +yMBmGAzxRFlQsT8lf6o5TS1/efBvjvWhh3NG2Zq2LpyhWRRqA3kNhzktzt2WjDZe +ZkKmZJJnArr/Aw7jEBC4sH+nmgxoR18GzDddRG12hv1AWyHc3+VisTBpyNzeBy17 +rxuQtqLzkAJmId723ddw83RVNSvBUUS3G0rx5O3HPobvZK89UqVxcXtIgc11WTVU +N3DbcJq5it43Loo0W3gAngtESDm2E3rTadrmdUSDGv2wQ5dNFl6cQ1f397Sdd/WC +A0grn1tKjJ6COp80Ymdyvn+stjv/+Rl1/KHSeG0lNeZxqjPPOJ7NHaKv7qjYsJ6W +LT35/Xc3oCo5qk9FOlq/0tGjHxf6RcFr5U7k5ILKZs+RmvJ4Sv/VYShLfLTcfGbJ +wBNfRKvcHZBQJQBb1+s/kRrjFFtvhrUwLz4+c9kskp+t4qRVYywUAnGGGsMs/GPm +wYsLQZO6Bs5/taaVUyaJQW015J7FGGv+/7/A1dIhu73S/Xl/YcFbX/CMEVq2Lxxd +hZdFIuaZ7LE+0MDQWsvYMYPDPLDH11diczb/jeKBdLPOzk/FUqVx3Fin1PpcaBxY +b+7oZJhYdg/rAWDeQ/nji9qnEG8waK6x1hdkYPOrqqWQPfgM/LPsSrgWeuTSdx2B +Ixi01UlBb5UP4K7UrjyddPobmcVjXaQLNe7zaq0+OS3UnIG85GtHrQ== +-----END RSA PRIVATE KEY----- diff --git a/mysql-test/t/connect.test b/mysql-test/t/connect.test index 5ee3d64e56f..2e66c24d877 100644 --- a/mysql-test/t/connect.test +++ b/mysql-test/t/connect.test @@ -59,6 +59,7 @@ flush privileges; connect (con10,localhost,test,gambling2,); connect (con5,localhost,test,gambling2,mysql); +connection con5; set password=""; --error 1372 set password='gambling3'; diff --git a/mysql-test/t/crash_commit_before.test b/mysql-test/t/crash_commit_before.test index a10cf254a83..757817915dd 100644 --- a/mysql-test/t/crash_commit_before.test +++ b/mysql-test/t/crash_commit_before.test @@ -20,6 +20,9 @@ SET SESSION debug="d,crash_commit_before"; --error 2013 COMMIT; +# Turn on reconnect +--enable_reconnect + # Call script that will poll the server waiting for it to be back online again --source include/wait_until_connected_again.inc diff --git a/mysql-test/t/csv.test b/mysql-test/t/csv.test index f70b5b40766..82102a6078e 100644 --- a/mysql-test/t/csv.test +++ b/mysql-test/t/csv.test @@ -1295,7 +1295,7 @@ SELECT fld3 FROM t2; # DROP TABLE t1; -ALTER TABLE t2 RENAME t1 +ALTER TABLE t2 RENAME t1; # # Drop and recreate diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 7ee7c9d00cb..65ee82fff23 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1233,17 +1233,21 @@ drop table if exists t1; # Bug#19960: Inconsistent results when joining # InnoDB tables using partial UTF8 indexes # +--disable_warnings CREATE TABLE t1 ( colA int(11) NOT NULL, colB varchar(255) character set utf8 NOT NULL, PRIMARY KEY (colA) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +--enable_warnings INSERT INTO t1 (colA, colB) VALUES (1, 'foo'), (2, 'foo bar'); +--disable_warnings CREATE TABLE t2 ( colA int(11) NOT NULL, colB varchar(255) character set utf8 NOT NULL, KEY bad (colA,colB(3)) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; +--enable_warnings INSERT INTO t2 (colA, colB) VALUES (1, 'foo'),(2, 'foo bar'); SELECT * FROM t1 JOIN t2 ON t1.colA=t2.colA AND t1.colB=t2.colB WHERE t1.colA < 3; diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index cd8036fd836..8e15bad7aed 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -9,29 +9,20 @@ # Do not use any TAB characters for whitespace. # ############################################################################## -#events_bugs : BUG#17619 2006-02-21 andrey Race conditions -#events_stress : BUG#17619 2006-02-21 andrey Race conditions -#events : BUG#17619 2006-02-21 andrey Race conditions -#events_scheduling : BUG#19170 2006-04-26 andrey Test case of 19170 fails on some platforms. Has to be checked. +user_limits : Bug#23921 random failure of user_limits.test + im_options : Bug#20294 2006-07-24 stewart Instance manager test im_options fails randomly -#im_life_cycle : Bug#20368 2006-06-10 alik im_life_cycle test fails -im_daemon_life_cycle : BUG#22379 2006-09-15 ingo im_daemon_life_cycle.test fails on merge of 5.1 -> 5.1-engines -im_instance_conf : BUG#20294 2006-09-16 ingo Instance manager test im_instance_conf fails randomly concurrent_innodb : BUG#21579 2006-08-11 mleich innodb_concurrent random failures with varying differences ndb_autodiscover : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog ndb_autodiscover2 : BUG#18952 2006-02-16 jmiller Needs to be fixed w.r.t binlog -#ndb_binlog_ignore_db : BUG#21279 2006-07-25 ingo Randomly throws a warning ndb_load : BUG#17233 2006-05-04 tomas failed load data from infile causes mysqld dbug_assert, binlog not flushed partition_03ndb : BUG#16385 2006-03-24 mikael Partitions: crash when updating a range partitioned NDB table -ps : BUG#21524 2006-08-08 pgalbraith 'ps' test fails in --ps-protocol test AMD64 bit ps_7ndb : BUG#18950 2006-02-16 jmiller create table like does not obtain LOCK_open rpl_ndb_2innodb : BUG#19227 2006-04-20 pekka pk delete apparently not replicated rpl_ndb_2myisam : BUG#19227 Seems to pass currently -#rpl_ndb_commit_afterflush : BUG#19328 2006-05-04 tomas Slave timeout with COM_REGISTER_SLAVE error causing stop rpl_ndb_dd_partitions : BUG#19259 2006-04-21 rpl_ndb_dd_partitions fails on s/AMD #rpl_ndb_ddl : BUG#18946 result file needs update + test needs to checked rpl_ndb_innodb2ndb : Bug #19710 Cluster replication to partition table fails on DELETE FROM statement -#rpl_ndb_log : BUG#18947 2006-03-21 tomas CRBR: order in binlog of create table and insert (on different table) not determ rpl_ndb_myisam2ndb : Bug #19710 Cluster replication to partition table fails on DELETE FROM statement rpl_row_blob_innodb : BUG#18980 2006-04-10 kent Test fails randomly rpl_sp : BUG#16456 2006-02-16 jmiller @@ -39,8 +30,5 @@ rpl_multi_engine : BUG#22583 2006-09-23 lars # the below testcase have been reworked to avoid the bug, test contains comment, keep bug open #ndb_binlog_ddl_multi : BUG#18976 2006-04-10 kent CRBR: multiple binlog, second binlog may miss schema log events -#rpl_ndb_idempotent : BUG#21298 2006-07-27 msvensson -#rpl_row_basic_7ndb : BUG#21298 2006-07-27 msvensson -#rpl_truncate_7ndb : BUG#21298 2006-07-27 msvensson ndb_binlog_discover : bug#21806 2006-08-24 ndb_autodiscover3 : bug#21806 diff --git a/mysql-test/t/func_compress.test b/mysql-test/t/func_compress.test index eeb5d509b94..68f07f258bf 100644 --- a/mysql-test/t/func_compress.test +++ b/mysql-test/t/func_compress.test @@ -56,7 +56,19 @@ insert into t1 values(NULL), (compress('a')); select uncompress(a), uncompressed_length(a) from t1; drop table t1; -# End of 4.1 tests +# +# Bug #23254: problem with compress(NULL) +# + +create table t1(a blob); +insert into t1 values ('0'), (NULL), ('0'); +--disable_result_log +select compress(a), compress(a) from t1; +--enable_result_log +select compress(a) is null from t1; +drop table t1; + +--echo End of 4.1 tests # # Bug #18539: uncompress(d) is null: impossible? diff --git a/mysql-test/t/func_date_add.test b/mysql-test/t/func_date_add.test index e01fce30577..b575eeececa 100644 --- a/mysql-test/t/func_date_add.test +++ b/mysql-test/t/func_date_add.test @@ -64,4 +64,17 @@ insert into t1 values (date_add('2000-01-04', INTERVAL NULL DAY)); select * from t1; drop table t1; -# End of 4.1 tests +--echo End of 4.1 tests + +# +# Bug#21811 +# +# Make sure we end up with an appropriate +# date format (DATE) after addition operation +# +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 DAY; +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 MONTH; +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 YEAR; +SELECT CAST('2006-09-26' AS DATE) + INTERVAL 1 WEEK; + +--echo End of 5.0 tests diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index c2035132d06..db3536c6d36 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -98,7 +98,7 @@ select ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'withou select distinct ifnull(group_concat(concat(t1.id, ':', t1.name)), 'shortname') as 'with distinct: cutoff at length of shortname' from t1; drop table t1; -# check zero rows +# check zero rows (bug#836) create table t1(id int); create table t2(id int); insert into t1 values(0),(1); diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index d49a4fed9d2..d331c363926 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -447,6 +447,49 @@ show create table t1; drop table t1; # +# Bug #11655: Wrong time is returning from nested selects - maximum time exists +# +# check if SEC_TO_TIME() handles out-of-range values correctly +SELECT SEC_TO_TIME(3300000); +SELECT SEC_TO_TIME(3300000)+0; +SELECT SEC_TO_TIME(3600 * 4294967296); + +# check if TIME_TO_SEC() handles out-of-range values correctly +SELECT TIME_TO_SEC('916:40:00'); + +# check if ADDTIME() handles out-of-range values correctly +SELECT ADDTIME('500:00:00', '416:40:00'); +SELECT ADDTIME('916:40:00', '416:40:00'); + +# check if SUBTIME() handles out-of-range values correctly +SELECT SUBTIME('916:40:00', '416:40:00'); +SELECT SUBTIME('-916:40:00', '416:40:00'); + +# check if MAKETIME() handles out-of-range values correctly +SELECT MAKETIME(916,0,0); +SELECT MAKETIME(4294967296, 0, 0); +SELECT MAKETIME(-4294967296, 0, 0); +SELECT MAKETIME(0, 4294967296, 0); +SELECT MAKETIME(0, 0, 4294967296); +SELECT MAKETIME(CAST(-1 AS UNSIGNED), 0, 0); + +# check if EXTRACT() handles out-of-range values correctly +SELECT EXTRACT(HOUR FROM '100000:02:03'); + +# check if we get proper warnings if both input string truncation +# and out-of-range value occur +CREATE TABLE t1(f1 TIME); +INSERT INTO t1 VALUES('916:00:00 a'); +SELECT * FROM t1; +DROP TABLE t1; + +# +# Bug #20927: sec_to_time treats big unsigned as signed +# +# check if SEC_TO_TIME() handles BIGINT UNSIGNED values correctly +SELECT SEC_TO_TIME(CAST(-1 AS UNSIGNED)); + +# # 21913: DATE_FORMAT() Crashes mysql server if I use it through # mysql-connector-j driver. # @@ -464,7 +507,6 @@ DROP TABLE testBug8868; SET NAMES DEFAULT; - # # Bug #19844 time_format in Union truncates values # @@ -483,24 +525,6 @@ union union (select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H); -# -# 21913: DATE_FORMAT() Crashes mysql server if I use it through -# mysql-connector-j driver. -# - -SET NAMES latin1; -SET character_set_results = NULL; -SHOW VARIABLES LIKE 'character_set_results'; - -CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32) CHARACTER SET BINARY); -INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd'); - -SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868; - -DROP TABLE testBug8868; - -SET NAMES DEFAULT; - --echo End of 4.1 tests explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1, diff --git a/mysql-test/t/im_daemon_life_cycle.imtest b/mysql-test/t/im_daemon_life_cycle.imtest index 55e52f4e464..8679f21a7cd 100644 --- a/mysql-test/t/im_daemon_life_cycle.imtest +++ b/mysql-test/t/im_daemon_life_cycle.imtest @@ -8,6 +8,9 @@ --source include/im_check_env.inc +# Turn on reconnect, not on by default anymore +--enable_reconnect + ########################################################################### # Kill the IM main process and check that the IM Angel will restart the main @@ -17,6 +20,12 @@ ########################################################################### +# Wait for IM to start accepting connections. + +--exec $MYSQL_TEST_DIR/t/wait_for_socket.sh $EXE_MYSQL $IM_PATH_SOCK $IM_USERNAME $IM_PASSWORD '' 30 + +########################################################################### + # # BUG#12751: Instance Manager: client hangs # diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 222b9652fca..4ae88736b98 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -934,7 +934,46 @@ SELECT MAX(table_name) FROM information_schema.tables; SELECT table_name from information_schema.tables WHERE table_name=(SELECT MAX(table_name) FROM information_schema.tables); +# +# Bug #23037: Bug in field "Default" of query "SHOW COLUMNS FROM table" +# +# Note, MyISAM/InnoDB can't take more that 65532 chars, because the row +# size is limited to 65535 bytes (BLOBs not counted) +# +--disable_warnings +DROP TABLE IF EXISTS bug23037; +DROP FUNCTION IF EXISTS get_value; +--enable_warnings +--disable_query_log +DELIMITER |; +CREATE FUNCTION get_value() + RETURNS TEXT + DETERMINISTIC +BEGIN + DECLARE col1, col2, col3, col4, col6 CHAR(255); + DECLARE default_val VARCHAR(65532); + DECLARE done INT DEFAULT 0; + DECLARE cur1 CURSOR FOR SHOW COLUMNS FROM bug23037; + DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1; + OPEN cur1; + FETCH cur1 INTO col1, col2, col3, col4, default_val, col6; + CLOSE cur1; + RETURN default_val; +end| +DELIMITER ;| + +let $body=`SELECT REPEAT('A', 65532)`; +eval CREATE TABLE bug23037(fld1 VARCHAR(65532) CHARACTER SET latin1 DEFAULT "$body"); +--enable_query_log + +SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037'; + +SELECT MD5(get_value()); + +SELECT COLUMN_NAME, MD5(COLUMN_DEFAULT), LENGTH(COLUMN_DEFAULT), COLUMN_DEFAULT=get_value() FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='bug23037'; +DROP TABLE bug23037; +DROP FUNCTION get_value; --echo End of 5.0 tests. # # Show engines diff --git a/mysql-test/t/init_file.test b/mysql-test/t/init_file.test index 6b5e032fd99..31a6ef5a541 100644 --- a/mysql-test/t/init_file.test +++ b/mysql-test/t/init_file.test @@ -4,7 +4,7 @@ # # See mysql-test/std_data/init_file.dat and # mysql-test/t/init_file-master.opt for the actual test -# +# --echo ok --echo end of 4.1 tests diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index 9c9e68f931f..765da1ee18d 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -244,7 +244,10 @@ DROP DATABASE mysqltest_1; # Bug #17264: MySQL Server freeze # connection locker; +# Disable warnings to allow test to run also without InnoDB +--disable_warnings create table t1 (f1 int(12) unsigned not null auto_increment, primary key(f1)) engine=innodb; +--enable_warnings lock tables t1 write; connection writer; --sleep 2 diff --git a/mysql-test/t/log_tables.test b/mysql-test/t/log_tables.test index d9e17129799..f1ff91a6d1d 100644 --- a/mysql-test/t/log_tables.test +++ b/mysql-test/t/log_tables.test @@ -314,6 +314,89 @@ use mysql; lock tables general_log read local, help_category read local; unlock tables; +# +# Bug #17544 Cannot do atomic log rotate and +# Bug #21785 Server crashes after rename of the log table +# + +use mysql; +# Should result in error +--error ER_CANT_RENAME_LOG_TABLE +RENAME TABLE general_log TO renamed_general_log; +--error ER_CANT_RENAME_LOG_TABLE +RENAME TABLE slow_log TO renamed_slow_log; + +#check rotate logs +truncate table general_log; +--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID +select * from general_log; + +truncate table slow_log; +--replace_column 1 TIMESTAMP 2 USER_HOST +select * from slow_log; + +create table general_log_new like general_log; +rename table general_log TO renamed_general_log, general_log_new TO general_log; + +create table slow_log_new like slow_log; +rename table slow_log TO renamed_slow_log, slow_log_new TO slow_log; + +# check that rename checks more then first table in the list +--error ER_CANT_RENAME_LOG_TABLE +rename table general_log TO general_log_new, renamed_general_log TO general_log, slow_log to renamed_slow_log; + +# now check the content of tables +--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID +select * from general_log; +--replace_column 1 TIMESTAMP 2 USER_HOST 3 THREAD_ID +select * from renamed_general_log; + +# the content of the slow log is empty, but we will try a select anyway +--replace_column 1 TIMESTAMP 2 USER_HOST +select * from slow_log; +--replace_column 1 TIMESTAMP 2 USER_HOST +select * from renamed_slow_log; + +# check that we can do whatever we want with disabled log +set global general_log='OFF'; +RENAME TABLE general_log TO general_log2; + +set global slow_query_log='OFF'; +RENAME TABLE slow_log TO slow_log2; + +# this should fail +--error ER_CANT_ACTIVATE_LOG +set global general_log='ON'; +--error ER_CANT_ACTIVATE_LOG +set global slow_query_log='ON'; + +RENAME TABLE general_log2 TO general_log; +RENAME TABLE slow_log2 TO slow_log; + +# this should work +set global general_log='ON'; +set global slow_query_log='ON'; +# now check flush logs +flush logs; +flush logs; +drop table renamed_general_log, renamed_slow_log; +use test; + +# +# Bug #21966 Strange warnings on repair of the log tables +# + +use mysql; +# check that no warning occurs on repair of the log tables +repair table general_log; +repair table slow_log; +# check that no warning occurs on "create like" for the log tables +create table general_log_new like general_log; +create table slow_log_new like slow_log; +show tables like "%log%"; +drop table slow_log_new, general_log_new; +use test; + # kill all connections disconnect con1; disconnect con2; diff --git a/mysql-test/t/mysql.test b/mysql-test/t/mysql.test index f3296e6f706..c06e52e2d78 100644 --- a/mysql-test/t/mysql.test +++ b/mysql-test/t/mysql.test @@ -153,4 +153,74 @@ drop table t1; --exec echo "SELECT '\';';" >> $MYSQLTEST_VARDIR/tmp/bug20103.sql --exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug20103.sql 2>&1 +# +# Bug#17583: mysql drops connection when stdout is not writable +# +create table t17583 (a int); +insert into t17583 (a) values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +insert into t17583 select a from t17583; +# Close to the minimal data needed to exercise bug. +select count(*) from t17583; +--exec echo "select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; select count(*) from t17583; " |$MYSQL test >&- +drop table t17583; + +# +# Bug#20984: Reproducible MySQL client segmentation fault +# + additional tests for the "com_connect" function in mysql +# +# +--echo Test connect without db- or host-name => reconnect +--exec $MYSQL test -e "\r" 2>&1 +--exec $MYSQL test -e "connect" 2>&1 + +--echo Test connect with dbname only => new dbname, old hostname +--exec $MYSQL test -e "\r test" 2>&1 +--exec $MYSQL test -e "connect test" 2>&1 +--exec $MYSQL test -e "\rtest" 2>&1 +--error 1 +--exec $MYSQL test -e "connecttest" 2>&1 + +--echo Test connect with _invalid_ dbname only => new invalid dbname, old hostname +--error 1 +--exec $MYSQL test -e "\r invalid" 2>&1 +--error 1 +--exec $MYSQL test -e "connect invalid" 2>&1 + +--echo Test connect with dbname + hostname +--exec $MYSQL test -e "\r test localhost" 2>&1 +--exec $MYSQL test -e "connect test localhost" 2>&1 + +--echo Test connect with dbname + _invalid_ hostname +# Mask the errno of the error message +--replace_regex /\([0-9]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r test invalid_hostname" 2>&1 +--replace_regex /\([0-9]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "connect test invalid_hostname" 2>&1 + +--echo The commands reported in the bug report +--replace_regex /\([0-9]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r\r\n\r\n cyril\ has\ found\ a\ bug\ :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 2>&1 + +#--replace_regex /\([0-9]*\)/(errno)/ +#--error 1 +#--exec echo '\r\r\n\r\n cyril\ has\ found\ a\ bug\ :)XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' | $MYSQL 2>&1 + +--echo Too long dbname +--error 1 +--exec $MYSQL test -e "\r test_really_long_dbnamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx localhost" 2>&1 + +--echo Too long hostname +--replace_regex /\([0-9]*\)/(errno)/ +--error 1 +--exec $MYSQL test -e "\r test cyrils_superlonghostnameXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" 2>&1 + --echo End of 5.0 tests diff --git a/mysql-test/t/mysqldump-max.test b/mysql-test/t/mysqldump-max.test index fbea84808b4..359c4ea5793 100644 --- a/mysql-test/t/mysqldump-max.test +++ b/mysql-test/t/mysqldump-max.test @@ -3,14 +3,9 @@ --source include/have_innodb.inc --source include/have_archive.inc ---disable-warnings -drop table if exists t1; -drop table if exists t2; -drop table if exists t3; -drop table if exists t4; -drop table if exists t5; -drop table if exists t6; ---enable-warnings +--disable_warnings +drop table if exists t1, t2, t3, t4, t5, t6; +--enable_warnings create table t1 (id int(8), name varchar(32)); create table t2 (id int(8), name varchar(32)) ENGINE="MyISAM"; diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 327b071afeb..1f1c8a44dbe 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -1415,6 +1415,21 @@ DROP TABLE `t1`; --enable_warnings --echo # +--echo # Bug #19745: mysqldump --xml produces invalid xml +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (f1 int(10), data MEDIUMBLOB); +INSERT INTO t1 VALUES(1,0xff00fef0); + +--exec $MYSQL_DUMP --xml --hex-blob --skip-create-options test t1 + +DROP TABLE t1; + +--echo # --echo # End of 5.0 tests --echo # diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test index 25f8d63d0b2..3c20b38722f 100644 --- a/mysql-test/t/mysqltest.test +++ b/mysql-test/t/mysqltest.test @@ -317,7 +317,6 @@ select 3 from t1 ; # #select 3 from t1 ; -# End of 4.1 tests --error 1 --exec echo "disable_abort_on_error; enable_abort_on_error; error 1064; select 3 from t1; select 3 from t1;" | $MYSQL_TEST 2>&1 @@ -360,18 +359,80 @@ select 3 from t1 ; # Missing delimiter # The comment will be "sucked into" the sleep command since # delimiter is missing until after "show status" ---system echo "sleep 4" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo "# A comment" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo "show status;" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql +--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql +sleep 4 +# A comment +show status; +EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 # # Missing delimiter until eof # The comment will be "sucked into" the sleep command since -# delimiter is missing ---system echo "sleep 7" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo "# Another comment" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql +# delimiter is missing +--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql +sleep 7 +# Another comment +EOF +--error 1 +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 + +# +# Missing delimiter until "disable_query_log" +# +--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql +disconnect default + +# +# comment +# comment 3 +disable_query_log; +EOF +--error 1 +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 + +# +# Missing delimiter until "disable_query_log" +# +--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql +disconnect default + +# +# comment + +# comment 3 +disable_query_log; +EOF +--error 1 +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 + +# +# Missing delimiter until eof +# +--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql +disconnect default + +# +# comment +# comment2 + +# comment 3 +--disable_query_log +EOF +--error 1 +--exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 + +# +# Missing delimiter until eof +# +--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql +disconnect default # comment +# comment part2 + +# comment 3 +--disable_query_log +EOF --error 1 --exec $MYSQL_TEST < $MYSQLTEST_VARDIR/tmp/mysqltest.sql 2>&1 @@ -388,6 +449,67 @@ select 3 from t1 ; --sleep 1 # Wait for insert delayed to be executed. --sleep 1 # Wait for insert delayed to be executed. +# ---------------------------------------------------------------------------- +# Test error +# ---------------------------------------------------------------------------- + +# Missing argument +--error 1 +--exec echo "error;" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "--error" | $MYSQL_TEST 2>&1 + +# First char must be uppercase 'S' or 'E' or [0-9] +--error 1 +--exec echo "--error s99999" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "--error e99999" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "--error 9eeeee" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "--error 1sssss" | $MYSQL_TEST 2>&1 + +# First char 'S' but too long +--error 1 +--exec echo "--error S999999" | $MYSQL_TEST 2>&1 + +# First char 'S' but lowercase char found +--error 1 +--exec echo "--error S99a99" | $MYSQL_TEST 2>&1 + +# First char 'S' but too short +--error 1 +--exec echo "--error S9999" | $MYSQL_TEST 2>&1 + +# First char 'E' but not found in error array +--error 1 +--exec echo "--error E9999" | $MYSQL_TEST 2>&1 + +# First char [0-9] but contains chars +--error 1 +--exec echo "--error 999e9" | $MYSQL_TEST 2>&1 +--error 1 +--exec echo "--error 9b" | $MYSQL_TEST 2>&1 + +# Multiple errorcodes separated by ',' +--error 1,1,1,1 +#--error 9,ER_PARSE_ERROR +#--error ER_PARSE_ERROR +#--error 9,ER_PARSE_ERROR,9,ER_PARSE_ERROR +#--error 9, ER_PARSE_ERROR, 9, ER_PARSE_ERROR +#--error 9,S00000,9,ER_PARSE_ERROR +#--error 9,S00000,9,ER_PARSE_ERROR,ER_PARSE_ERROR,ER_PARSE_ERROR,9,10,11,12 +--error 9,S00000,9 +--error 9,S00000,9,9,10,11,12 +--error 9 ,10 +--error 9 , 10 +--error 9 , 10 +--error 9 , 10 + +# Too many errorcodes specified +--error 1 +--exec echo "--error 1,2,3,4,5,6,7,8,9,10,11" | $MYSQL_TEST 2>&1 + # ---------------------------------------------------------------------------- # Test echo command @@ -610,6 +732,7 @@ echo $var3_var3; # Fix win paths --replace_result \\ / +# Source a nonexisting file --error 1 --exec echo "source non_existingFile;" | $MYSQL_TEST 2>&1 @@ -627,13 +750,16 @@ echo $var3_var3; # Test execution of source in a while loop +--write_file $MYSQLTEST_VARDIR/tmp/sourced.inc +echo here is the sourced script; +EOF --disable_query_log let $outer= 2; # Number of outer loops while ($outer) { eval SELECT '$outer = outer loop variable after while' AS ""; - --source include/sourced.inc + --source $MYSQLTEST_VARDIR/tmp/sourced.inc eval SELECT '$outer = outer loop variable before dec' AS ""; dec $outer; @@ -661,11 +787,12 @@ let $num= 9; while ($num) { SELECT 'In loop' AS ""; - --source include/sourced1.inc + --source $MYSQLTEST_VARDIR/tmp/sourced.inc dec $num; } --enable_abort_on_error --enable_query_log +--remove_file $MYSQLTEST_VARDIR/tmp/sourced.inc # ---------------------------------------------------------------------------- # Test sleep command @@ -817,10 +944,150 @@ while (!$i) } # Exceed max nesting level +--write_file $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc +let $1 = 10; +while ($1) +{ +while ($1) +{ +while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + while ($1) +{ + echo $1; + dec $1; +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +} +EOF # Fix win path ---replace_result \\ / +--replace_result \\ / $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --error 1 ---exec echo "source include/mysqltest_while.inc;" | $MYSQL_TEST 2>&1 +--exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc;" | $MYSQL_TEST 2>&1 +--remove_file $MYSQLTEST_VARDIR/tmp/mysqltest_while.inc --error 1 --exec echo "while \$i;" | $MYSQL_TEST 2>&1 --error 1 @@ -925,12 +1192,6 @@ select "a" as col1, "c" as col2; --error 1 --exec echo "connect (con2,);" | $MYSQL_TEST 2>&1 --error 1 ---exec echo "connect (con2,localhost);" | $MYSQL_TEST 2>&1 ---error 1 ---exec echo "connect (con2, localhost, root);" | $MYSQL_TEST 2>&1 ---error 1 ---exec echo "connect (con2, localhost, root,);" | $MYSQL_TEST 2>&1 ---error 1 --exec echo "connect (con2,localhost,root,,illegal_db);" | $MYSQL_TEST 2>&1 --error 1 --exec echo "connect (con1,localhost,root,,,illegal_port,);" | $MYSQL_TEST 2>&1 @@ -938,13 +1199,15 @@ select "a" as col1, "c" as col2; --exec echo "connect (con1,localhost,root,,,,,SMTP POP);" | $MYSQL_TEST 2>&1 # Repeat connect/disconnect ---system echo "let \$i=100;" > $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo "while (\$i)" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo "{" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo " connect (test_con1,localhost,root,,); " >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo " disconnect test_con1; " >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo " dec \$i; " >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql ---system echo "}" >> $MYSQLTEST_VARDIR/tmp/mysqltest.sql +--write_file $MYSQLTEST_VARDIR/tmp/mysqltest.sql +let $i=100; +while ($i) +{ + connect (test_con1,localhost,root,,); + disconnect test_con1; + dec $i; +} +EOF --exec echo "source $MYSQLTEST_VARDIR/tmp/mysqltest.sql; echo OK;" | $MYSQL_TEST 2>&1 # Repeat connect/disconnect, exceed max number of connections @@ -1149,8 +1412,6 @@ query sleep; --error 1065 query ; ---echo End of 5.0 tests - # test for replace_regex --replace_regex /at/b/ select "at" as col1, "c" as col2; @@ -1189,4 +1450,117 @@ insert into t1 values (2,4); select * from t1; drop table t1; ---echo End of 5.1 tests +# ---------------------------------------------------------------------------- +# test for remove_file +# ---------------------------------------------------------------------------- + +--error 1 +--exec echo "remove_file ;" | $MYSQL_TEST 2>&1 + +--error 1 +remove_file non_existing_file; + +# ---------------------------------------------------------------------------- +# test for write_file +# ---------------------------------------------------------------------------- +--error 1 +--exec echo "write_file ;" | $MYSQL_TEST 2>&1 + +--error 1 +--exec echo "write_file filename ;" | $MYSQL_TEST 2>&1 + +--error 1 +--exec echo "write_file filename \";" | $MYSQL_TEST 2>&1 + +write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +Content for test_file1 +EOF +file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; + +write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp END_DELIMITER; +Content for test_file1 contains EOF +END_DELIMITER +file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; + +# ---------------------------------------------------------------------------- +# test for file_exist +# ---------------------------------------------------------------------------- +--error 1 +--exec echo "file_exists ;" | $MYSQL_TEST 2>&1 + +--error 0,1 +remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +--error 1 +file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +write_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +Content for test_file1 +EOF +file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/test_file1.tmp; +--error 1 +file_exists $MYSQLTEST_VARDIR/tmp/test_file1.tmp; + + +# ---------------------------------------------------------------------------- +# test for copy_file +# ---------------------------------------------------------------------------- +--write_file $MYSQLTEST_VARDIR/tmp/file1.tmp +file1 +EOF + +copy_file $MYSQLTEST_VARDIR/tmp/file1.tmp $MYSQLTEST_VARDIR/tmp/file2.tmp; +file_exists $MYSQLTEST_VARDIR/tmp/file2.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/file1.tmp; +remove_file $MYSQLTEST_VARDIR/tmp/file2.tmp; + +--error 1 +--exec echo "copy_file ;" | $MYSQL_TEST 2>&1 + +--error 1 +--exec echo "copy_file from_file;" | $MYSQL_TEST 2>&1 + +# ---------------------------------------------------------------------------- +# test for perl +# ---------------------------------------------------------------------------- +--perl +print "hello\n"; +EOF + +--perl EOF +print "hello\n"; +EOF + +--perl DELIMITER +print "hello\n"; +DELIMITER + +--error 1 +--exec echo "perl TOO_LONG_DELIMITER ;" | $MYSQL_TEST 2>&1 + +perl; +print "hello\n"; +EOF + +perl; + # Print "hello" + print "hello\n"; +EOF + +# ---------------------------------------------------------------------------- +# test for die +# ---------------------------------------------------------------------------- + +--error 1 +--exec echo "die test of die;" | $MYSQL_TEST 2>&1 + + +# ---------------------------------------------------------------------------- +# test for exit +# ---------------------------------------------------------------------------- + +--exec echo "echo Some output; exit; echo Not this;" | $MYSQL_TEST 2>&1 + + +--echo End of tests diff --git a/mysql-test/t/ndb_basic.test b/mysql-test/t/ndb_basic.test index 7bbc580c9ad..bbe5d263e36 100644 --- a/mysql-test/t/ndb_basic.test +++ b/mysql-test/t/ndb_basic.test @@ -550,6 +550,7 @@ index(a12345678901234567890123456789a1234567890) ) engine=ndb; show tables; insert into t1 values (1,1),(2,1),(3,1),(4,1),(5,2),(6,1),(7,1); +--replace_column 9 # explain select * from t1 where a12345678901234567890123456789a1234567890=2; select * from t1 where a12345678901234567890123456789a1234567890=2; drop table t1; diff --git a/mysql-test/t/ndb_blob.test b/mysql-test/t/ndb_blob.test index d6e0edc89f0..fb0536f0d10 100644 --- a/mysql-test/t/ndb_blob.test +++ b/mysql-test/t/ndb_blob.test @@ -65,6 +65,7 @@ select length(@x0),length(@b2),length(@d2) from dual; insert into t1 values(1,@b1,111,@d1); insert into t1 values(2,@b2,222,@d2); commit; +--replace_column 9 # explain select * from t1 where a = 1; # pk read @@ -108,6 +109,7 @@ select count(*) from t1; replace t1 set a=1,b=@b1,c=111,d=@d1; replace t1 set a=2,b=@b2,c=222,d=@d2; commit; +--replace_column 9 # explain select * from t1 where a = 1; # pk read @@ -150,6 +152,7 @@ select count(*) from t1; insert into t1 values(1,@b1,111,@d1); insert into t1 values(2,@b2,222,@d2); commit; +--replace_column 9 # explain select * from t1 where c = 111; # hash key read @@ -190,6 +193,7 @@ insert into t1 values(7,'b7',777,'dd7'); insert into t1 values(8,'b8',888,'dd8'); insert into t1 values(9,'b9',999,'dd9'); commit; +--replace_column 9 # explain select * from t1; # table scan read @@ -210,6 +214,7 @@ select count(*) from t1; insert into t1 values(1,@b1,111,@d1); insert into t1 values(2,@b2,222,@d2); commit; +--replace_column 9 # explain select * from t1; # table scan read @@ -239,6 +244,7 @@ insert into t1 values(7,'b7',777,'dd7'); insert into t1 values(8,'b8',888,'dd8'); insert into t1 values(9,'b9',999,'dd9'); commit; +--replace_column 9 # explain select * from t1 where c >= 100 order by a; # range scan read @@ -260,6 +266,7 @@ select count(*) from t1; insert into t1 values(1,@b1,111,@d1); insert into t1 values(2,@b2,222,@d2); commit; +--replace_column 9 # explain select * from t1 where c >= 100 order by a; # range scan read diff --git a/mysql-test/t/ndb_charset.test b/mysql-test/t/ndb_charset.test index 5941e5750db..a429ee5e1dc 100644 --- a/mysql-test/t/ndb_charset.test +++ b/mysql-test/t/ndb_charset.test @@ -159,8 +159,9 @@ insert into t1 values(5, 'aaa'); insert into t1 values(6, 'AAA'); # 6 select * from t1 order by p; -# plan -explain select * from t1 where a = 'zZz' order by p; +# plan too flaky +#--replace_column 9 # +#explain select * from t1 where a = 'zZz' order by p; # 2 select * from t1 where a = 'aAa' order by p; # 2 @@ -187,8 +188,9 @@ insert into t1 values(5, 'aaa'); insert into t1 values(6, 'AAA'); # 6 select * from t1 order by p; -# plan -explain select * from t1 where a = 'zZz' order by p; +# plan too flaky +#--replace_column 9 # +#explain select * from t1 where a = 'zZz' order by p; # 6 select * from t1 where a = 'aAa' order by p; # 6 diff --git a/mysql-test/t/ndb_condition_pushdown.test b/mysql-test/t/ndb_condition_pushdown.test index f5ffc08e8c9..ab56430ac1d 100644 --- a/mysql-test/t/ndb_condition_pushdown.test +++ b/mysql-test/t/ndb_condition_pushdown.test @@ -456,6 +456,7 @@ select * from t3,t4 where t4.attr1 > 1 and t4.attr2 = t3.attr2 and t4.attr3 < 5 set engine_condition_pushdown = on; # Test all types and compare operators +--replace_column 9 # explain select auto from t1 where string = "aaaa" and @@ -511,6 +512,7 @@ time_field = '01:01:01' and date_time = '1901-01-01 01:01:01' order by auto; +--replace_column 9 # explain select auto from t1 where string != "aaaa" and @@ -566,6 +568,7 @@ time_field != '01:01:01' and date_time != '1901-01-01 01:01:01' order by auto; +--replace_column 9 # explain select auto from t1 where string > "aaaa" and @@ -621,6 +624,7 @@ time_field > '01:01:01' and date_time > '1901-01-01 01:01:01' order by auto; +--replace_column 9 # explain select auto from t1 where string >= "aaaa" and @@ -676,6 +680,7 @@ time_field >= '01:01:01' and date_time >= '1901-01-01 01:01:01' order by auto; +--replace_column 9 # explain select auto from t1 where string < "dddd" and @@ -731,6 +736,7 @@ time_field < '04:04:04' and date_time < '1904-04-04 04:04:04' order by auto; +--replace_column 9 # explain select auto from t1 where string <= "dddd" and @@ -790,6 +796,7 @@ order by auto; create index medium_index on t1(medium); # Test all types and compare operators +--replace_column 9 # explain select auto from t1 where string = "aaaa" and @@ -845,6 +852,7 @@ time_field = '01:01:01' and date_time = '1901-01-01 01:01:01' order by auto; +--replace_column 9 # explain select auto from t1 where string != "aaaa" and @@ -900,6 +908,7 @@ time_field != '01:01:01' and date_time != '1901-01-01 01:01:01' order by auto; +--replace_column 9 # explain select auto from t1 where string > "aaaa" and @@ -955,6 +964,7 @@ time_field > '01:01:01' and date_time > '1901-01-01 01:01:01' order by auto; +--replace_column 9 # explain select auto from t1 where string >= "aaaa" and @@ -1010,6 +1020,7 @@ time_field >= '01:01:01' and date_time >= '1901-01-01 01:01:01' order by auto; +--replace_column 9 # explain select auto from t1 where string < "dddd" and @@ -1065,6 +1076,7 @@ time_field < '04:04:04' and date_time < '1904-04-04 04:04:04' order by auto; +--replace_column 9 # explain select auto from t1 where string <= "dddd" and @@ -1121,6 +1133,7 @@ date_time <= '1904-04-04 04:04:04' order by auto; # Test LIKE/NOT LIKE +--replace_column 9 # explain select auto from t1 where string like "b%" and @@ -1136,6 +1149,7 @@ bin like concat(0xBB, '%') and vbin like concat(0xBB, '%') order by auto; +--replace_column 9 # explain select auto from t1 where string not like "b%" and @@ -1152,6 +1166,7 @@ vbin not like concat(0xBB, '%') order by auto; # BETWEEN +--replace_column 9 # explain select auto from t1 where (string between "aaaa" and "cccc") and @@ -1201,6 +1216,7 @@ select auto from t1 where (date_time between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') order by auto; +--replace_column 9 # explain select auto from t1 where ("aaaa" between string and string) and @@ -1251,6 +1267,7 @@ select auto from t1 where order by auto; # NOT BETWEEN +--replace_column 9 # explain select auto from t1 where (string not between "aaaa" and "cccc") and @@ -1300,6 +1317,7 @@ select auto from t1 where (date_time not between '1901-01-01 01:01:01' and '1903-03-03 03:03:03') order by auto; +--replace_column 9 # explain select auto from t1 where ("aaaa" not between string and string) and @@ -1350,6 +1368,7 @@ select auto from t1 where order by auto; # IN +--replace_column 9 # explain select auto from t1 where string in("aaaa","cccc") and @@ -1399,6 +1418,7 @@ time_field in('01:01:01','03:03:03') and date_time in('1901-01-01 01:01:01','1903-03-03 03:03:03') order by auto; +--replace_column 9 # explain select auto from t1 where "aaaa" in(string) and @@ -1449,6 +1469,7 @@ select auto from t1 where order by auto; # NOT IN +--replace_column 9 # explain select auto from t1 where string not in("aaaa","cccc") and @@ -1498,6 +1519,7 @@ time_field not in('01:01:01','03:03:03') and date_time not in('1901-01-01 01:01:01','1903-03-03 03:03:03') order by auto; +--replace_column 9 # explain select auto from t1 where "aaaa" not in(string) and @@ -1607,35 +1629,44 @@ date_time = '1901-01-01 01:01:01'; select count(*) from t1; # Various tests +--replace_column 9 # explain select * from t2 where attr3 is null or attr1 > 2 and pk1= 3 order by pk1; select * from t2 where attr3 is null or attr1 > 2 and pk1= 3 order by pk1; +--replace_column 9 # explain select * from t2 where attr3 is not null and attr1 > 2 order by pk1; select * from t2 where attr3 is not null and attr1 > 2 order by pk1; +--replace_column 9 # explain select * from t3 where attr2 > 9223372036854775803 and attr3 != 3 order by pk1; select * from t3 where attr2 > 9223372036854775803 and attr3 != 3 order by pk1; +--replace_column 9 # explain select * from t2,t3 where t2.attr1 < 1 and t2.attr2 = t3.attr2 and t3.attr1 < 5 order by t2.pk1; select * from t2,t3 where t2.attr1 < 1 and t2.attr2 = t3.attr2 and t3.attr1 < 5 order by t2.pk1; +--replace_column 9 # explain select * from t4 where attr1 < 5 and attr2 > 9223372036854775803 and attr3 != 3 order by t4.pk1; select * from t4 where attr1 < 5 and attr2 > 9223372036854775803 and attr3 != 3 order by t4.pk1; +--replace_column 9 # explain select * from t3,t4 where t4.attr1 > 1 and t4.attr2 = t3.attr2 and t4.attr3 < 5 order by t4.pk1; select * from t3,t4 where t4.attr1 > 1 and t4.attr2 = t3.attr2 and t4.attr3 < 5 order by t4.pk1; # Some tests that are currently not supported and should not push condition +--replace_column 9 # explain select auto from t1 where string = "aaaa" collate latin1_general_ci order by auto; +--replace_column 9 # explain select * from t2 where (attr1 < 2) = (attr2 < 2) order by pk1; +--replace_column 9 # explain select * from t3 left join t4 on t4.attr2 = t3.attr2 where t4.attr1 > 1 and t4.attr3 < 5 or t4.attr1 is null order by t4.pk1; @@ -1646,6 +1677,7 @@ insert into t5 (b) values ('jonas'), ('jensing'), ('johan'); set engine_condition_pushdown = off; select * from t5 where b like '%jo%' order by a; set engine_condition_pushdown = on; +--replace_column 9 # explain select * from t5 where b like '%jo%'; select * from t5 where b like '%jo%' order by a; @@ -1654,8 +1686,10 @@ set engine_condition_pushdown = off; select auto from t1 where date_time like '1902-02-02 %' order by auto; select auto from t1 where date_time not like '1902-02-02 %' order by auto; set engine_condition_pushdown = on; +--replace_column 9 # explain select auto from t1 where date_time like '1902-02-02 %'; select auto from t1 where date_time like '1902-02-02 %' order by auto; +--replace_column 9 # explain select auto from t1 where date_time not like '1902-02-02 %'; select auto from t1 where date_time not like '1902-02-02 %' order by auto; diff --git a/mysql-test/t/ndb_dd_sql_features.test b/mysql-test/t/ndb_dd_sql_features.test index 6c27ecf397b..f46cb217ab4 100644 --- a/mysql-test/t/ndb_dd_sql_features.test +++ b/mysql-test/t/ndb_dd_sql_features.test @@ -480,6 +480,7 @@ select length(@x0),length(@b2),length(@d2) from dual; INSERT INTO test.t1 values(1,@vc1,@d1); INSERT INTO test.t1 values(2,@vc2,@d2); + --replace_column 9 # explain SELECT * from test.t1 WHERE a1 = 1; SELECT a1,length(a2),substr(a2,1+2*900,2),length(a3),substr(a3,1+3*900,3) diff --git a/mysql-test/t/ndb_index_unique.test b/mysql-test/t/ndb_index_unique.test index a40efc8a40c..94bba98662c 100644 --- a/mysql-test/t/ndb_index_unique.test +++ b/mysql-test/t/ndb_index_unique.test @@ -329,4 +329,12 @@ select a, sha1(b) from t1; drop table t1; +# bug#21873 MySQLD Crash on ALTER...ADD..UNIQUE..USING HASH statement for NDB backed table + +create table t1(id int not null) engine = NDB; + +alter table t1 add constraint uk_test unique (id) using hash; + +drop table t1; + # End of 4.1 tests diff --git a/mysql-test/t/ndb_multi.test b/mysql-test/t/ndb_multi.test index a8253b786d0..0f098c96fa8 100644 --- a/mysql-test/t/ndb_multi.test +++ b/mysql-test/t/ndb_multi.test @@ -39,12 +39,7 @@ drop table t1; create table t1 (a int) engine=ndbcluster; insert into t1 value (2); connection server1; -## Currently a retry is required remotely -#--error 1412 -#select * from t1; -#show warnings; -#flush table t1; -# Table definition change should be propagated automatically +select * from t1; select * from t1; # Connect to server2 and use the tables from there diff --git a/mysql-test/t/ndb_subquery.test b/mysql-test/t/ndb_subquery.test index 93c45c521a0..9cf6527dd98 100644 --- a/mysql-test/t/ndb_subquery.test +++ b/mysql-test/t/ndb_subquery.test @@ -18,18 +18,22 @@ insert into t1 values (1,1,1),(2,2,2),(3,3,3); insert into t2 values (1,1,1),(2,2,2),(3,3,3), (4,4,4), (5,5,5); # Use pk +--replace_column 9 # explain select * from t2 where p NOT IN (select p from t1); select * from t2 where p NOT IN (select p from t1) order by p; # Use unique index +--replace_column 9 # explain select * from t2 where p NOT IN (select u from t1); select * from t2 where p NOT IN (select u from t1) order by p; # Use ordered index +--replace_column 9 # explain select * from t2 where p NOT IN (select o from t1); select * from t2 where p NOT IN (select o from t1) order by p; # Use scan +--replace_column 9 # explain select * from t2 where p NOT IN (select p+0 from t1); select * from t2 where p NOT IN (select p+0 from t1) order by p; diff --git a/mysql-test/t/not_embedded_server-master.opt b/mysql-test/t/not_embedded_server-master.opt index 35fcc5f30c6..cef79bc8585 100644 --- a/mysql-test/t/not_embedded_server-master.opt +++ b/mysql-test/t/not_embedded_server-master.opt @@ -1 +1 @@ ---loose-to-force-a-restart +--force-restart diff --git a/mysql-test/t/not_partition.test b/mysql-test/t/not_partition.test new file mode 100644 index 00000000000..992615c06f4 --- /dev/null +++ b/mysql-test/t/not_partition.test @@ -0,0 +1,62 @@ +--disable_abort_on_error +# Run this tets only when mysqld don't has partitioning +# the statements are not expected to work, just check that we +# can't crash the server +-- require r/not_partition.require +disable_query_log; +show variables like "have_partitioning"; +enable_query_log; + + +--error ER_FEATURE_DISABLED +CREATE TABLE t1 ( + firstname VARCHAR(25) NOT NULL, + lastname VARCHAR(25) NOT NULL, + username VARCHAR(16) NOT NULL, + email VARCHAR(35), + joined DATE NOT NULL +) +PARTITION BY KEY(joined) +PARTITIONS 6; + +--error ER_FEATURE_DISABLED +ALTER TABLE t1 PARTITION BY KEY(joined) PARTITIONS 2; + +--error ER_BAD_TABLE_ERROR +drop table t1; + +--error ER_FEATURE_DISABLED +CREATE TABLE t1 ( + firstname VARCHAR(25) NOT NULL, + lastname VARCHAR(25) NOT NULL, + username VARCHAR(16) NOT NULL, + email VARCHAR(35), + joined DATE NOT NULL +) +PARTITION BY RANGE( YEAR(joined) ) ( + PARTITION p0 VALUES LESS THAN (1960), + PARTITION p1 VALUES LESS THAN (1970), + PARTITION p2 VALUES LESS THAN (1980), + PARTITION p3 VALUES LESS THAN (1990), + PARTITION p4 VALUES LESS THAN MAXVALUE +); +--error ER_BAD_TABLE_ERROR +drop table t1; + +--error ER_FEATURE_DISABLED +CREATE TABLE t1 (id INT, purchased DATE) + PARTITION BY RANGE( YEAR(purchased) ) + SUBPARTITION BY HASH( TO_DAYS(purchased) ) + SUBPARTITIONS 2 ( + PARTITION p0 VALUES LESS THAN (1990), + PARTITION p1 VALUES LESS THAN (2000), + PARTITION p2 VALUES LESS THAN MAXVALUE + ); +--error ER_BAD_TABLE_ERROR +drop table t1; + +# Create a table without partitions to test "EXPLAIN PARTITIONS" +create table t1 (a varchar(10) charset latin1 collate latin1_bin); +insert into t1 values (''),(' '),('a'),('a '),('a '); +explain partitions select * from t1 where a='a ' OR a='a'; +drop table t1; diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index 42fd0426d01..8cb5e76d85b 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -4,6 +4,7 @@ # Taken fromm the select test # -- source include/have_partition.inc + # # This test is disabled on Windows due to BUG#19107 # @@ -1286,37 +1287,51 @@ eval SET @inx_dir = 'INDEX DIRECTORY = ''$MYSQLTEST_VARDIR/master-data/tmpinx''' let $inx_directory = `select @inx_dir`; --enable_query_log ---replace_result $MYSQLTEST_VARDIR "hello" +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR eval create table t1 (a int) engine myisam partition by range (a) subpartition by hash (a) (partition p0 VALUES LESS THAN (1) $data_directory $inx_directory (SUBPARTITION subpart00, SUBPARTITION subpart01)); ---replace_result $MYSQLTEST_VARDIR "hello" ---exec ls $MYSQLTEST_VARDIR/master-data/test/t1.* || true ---replace_result $MYSQLTEST_VARDIR "hello" ---exec ls $MYSQLTEST_VARDIR/master-data/test/t1#* || true ---replace_result $MYSQLTEST_VARDIR "hello" ---exec ls $MYSQLTEST_VARDIR/master-data/tmpdata/t1#* || true ---replace_result $MYSQLTEST_VARDIR "hello" ---exec ls $MYSQLTEST_VARDIR/master-data/tmpinx/t1#* || true ---replace_result $MYSQLTEST_VARDIR "hello" - +--echo Checking if file exists before alter +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1.frm +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1.par +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p0#SP#subpart00.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p0#SP#subpart00.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p0#SP#subpart01.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p0#SP#subpart01.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/tmpdata/t1#P#p0#SP#subpart00.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/tmpdata/t1#P#p0#SP#subpart01.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/tmpinx/t1#P#p0#SP#subpart00.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/tmpinx/t1#P#p0#SP#subpart01.MYI + +--replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR eval ALTER TABLE t1 REORGANIZE PARTITION p0 INTO (partition p1 VALUES LESS THAN (1) $data_directory $inx_directory (SUBPARTITION subpart10, SUBPARTITION subpart11), partition p2 VALUES LESS THAN (2) $data_directory $inx_directory (SUBPARTITION subpart20, SUBPARTITION subpart21)); ---replace_result $MYSQLTEST_VARDIR "hello" ---exec ls $MYSQLTEST_VARDIR/master-data/test/t1.* || true ---replace_result $MYSQLTEST_VARDIR "hello" ---exec ls $MYSQLTEST_VARDIR/master-data/test/t1#* || true ---replace_result $MYSQLTEST_VARDIR "hello" ---exec ls $MYSQLTEST_VARDIR/master-data/tmpdata/t1#* || true ---replace_result $MYSQLTEST_VARDIR "hello" ---exec ls $MYSQLTEST_VARDIR/master-data/tmpinx/t1#* || true +--echo Checking if file exists after alter +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1.frm +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1.par +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p1#SP#subpart10.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p1#SP#subpart10.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p1#SP#subpart11.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p1#SP#subpart11.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p2#SP#subpart20.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p2#SP#subpart20.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p2#SP#subpart21.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/test/t1#P#p2#SP#subpart21.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/tmpdata/t1#P#p1#SP#subpart10.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/tmpdata/t1#P#p1#SP#subpart11.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/tmpdata/t1#P#p2#SP#subpart20.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/tmpdata/t1#P#p2#SP#subpart21.MYD +--file_exists $MYSQLTEST_VARDIR/master-data/tmpinx/t1#P#p1#SP#subpart10.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/tmpinx/t1#P#p1#SP#subpart11.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/tmpinx/t1#P#p2#SP#subpart20.MYI +--file_exists $MYSQLTEST_VARDIR/master-data/tmpinx/t1#P#p2#SP#subpart21.MYI drop table t1; --exec rmdir $MYSQLTEST_VARDIR/master-data/tmpdata || true diff --git a/mysql-test/t/ps-master.opt b/mysql-test/t/ps-master.opt new file mode 100644 index 00000000000..3eb98fc3d6b --- /dev/null +++ b/mysql-test/t/ps-master.opt @@ -0,0 +1 @@ +--log-slow-queries --log-long-format --log-queries-not-using-indexes diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index ac79dbc3434..e845804d6d6 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -354,14 +354,14 @@ create table t1 (a int, b int); insert into t1 (a, b) values (1,1), (1,2), (2,1), (2,2); prepare stmt from "explain select * from t1 where t1.a=2 and t1.a=t1.b and t1.b > 1 + ?"; ---replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - set @v=5; -execute stmt using @v; --replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - -set @v=0; execute stmt using @v; +set @v=0; --replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - +execute stmt using @v; set @v=5; +--replace_column 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - execute stmt using @v; drop table t1; deallocate prepare stmt; @@ -988,6 +988,7 @@ execute stmt; drop temporary table t1; deallocate prepare stmt; + # # BUG#22085: Crash on the execution of a prepared statement that # uses an IN subquery with aggregate functions in HAVING @@ -1040,7 +1041,81 @@ EXECUTE STMT USING @id,@id; DEALLOCATE PREPARE STMT; DROP TABLE t1; ---echo End of 4.1 tests +# +# BUG#21354: (COUNT(*) = 1) not working in SELECT inside prepared +# statement +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT, INDEX(i)); +INSERT INTO t1 VALUES (1); + +PREPARE stmt FROM "SELECT (COUNT(i) = 1), COUNT(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +SET @a = 1; +EXECUTE stmt USING @a; +SET @a = 0; +EXECUTE stmt USING @a; + +PREPARE stmt FROM "SELECT (AVG(i) = 1), AVG(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +SET @a = 1; +EXECUTE stmt USING @a; +SET @a = 0; +EXECUTE stmt USING @a; + +PREPARE stmt FROM "SELECT (VARIANCE(i) = 1), VARIANCE(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +SET @a = 1; +EXECUTE stmt USING @a; +SET @a = 0; +EXECUTE stmt USING @a; + +PREPARE stmt FROM "SELECT (STDDEV(i) = 1), STDDEV(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +SET @a = 1; +EXECUTE stmt USING @a; +SET @a = 0; +EXECUTE stmt USING @a; + +PREPARE stmt FROM "SELECT (BIT_OR(i) = 1), BIT_OR(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +SET @a = 1; +EXECUTE stmt USING @a; +SET @a = 0; +EXECUTE stmt USING @a; + +PREPARE stmt FROM "SELECT (BIT_AND(i) = 1), BIT_AND(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +SET @a = 1; +EXECUTE stmt USING @a; +SET @a = 0; +EXECUTE stmt USING @a; + +PREPARE stmt FROM "SELECT (BIT_XOR(i) = 1), BIT_XOR(i) FROM t1 WHERE i = ?"; +SET @a = 0; +EXECUTE stmt USING @a; +SET @a = 1; +EXECUTE stmt USING @a; +SET @a = 0; +EXECUTE stmt USING @a; + +DEALLOCATE PREPARE stmt; +DROP TABLE t1; + + +--echo End of 4.1 tests. + + + ############################# 5.0 tests start ################################ # # @@ -1437,6 +1512,39 @@ DEALLOCATE PREPARE stmt; DROP TABLE t1, t2; +# +# BUG#21856: Prepared Statments: crash if bad create +# +--disable_warnings +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +let $iterations= 100; +--disable_query_log +--disable_result_log +while ($iterations > 0) +{ + --error ER_PARSE_ERROR + PREPARE stmt FROM "CREATE PROCEDURE p1()"; + dec $iterations; +} +--enable_query_log +--enable_result_log + +# +# Bug 19764: SHOW commands end up in the slow log as table scans +# + +flush status; +prepare sq from 'show status like "slow_queries"'; +execute sq; +prepare no_index from 'select 1 from information_schema.tables limit 1'; +execute sq; +execute no_index; +execute sq; +deallocate prepare no_index; +deallocate prepare sq; + --echo End of 5.0 tests. # @@ -1447,13 +1555,15 @@ create procedure proc_1() reset query cache; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin reset query cache; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; drop function func_1; +drop procedure proc_1; prepare abc from "reset query cache"; execute abc; execute abc; @@ -1462,13 +1572,15 @@ deallocate prepare abc; create procedure proc_1() reset master; -drop procedure proc_1; delimiter |; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin reset master; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; drop function func_1; +drop procedure proc_1; prepare abc from "reset master"; execute abc; execute abc; @@ -1480,13 +1592,15 @@ create procedure proc_1() reset slave; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin reset slave; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; drop function func_1; +drop procedure proc_1; prepare abc from "reset slave"; execute abc; execute abc; @@ -1527,15 +1641,15 @@ call proc_1(); call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush hosts; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush hosts"; execute abc; execute abc; @@ -1547,15 +1661,15 @@ create procedure proc_1() flush privileges; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush privileges; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush privileges"; deallocate prepare abc; @@ -1567,11 +1681,15 @@ call proc_1(); unlock tables; call proc_1(); unlock tables; -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush tables with read lock; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG +select func_1(), func_1(), func_1() from dual; +drop function func_1; +drop procedure proc_1; prepare abc from "flush tables with read lock"; execute abc; execute abc; @@ -1584,15 +1702,15 @@ create procedure proc_1() flush tables; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush tables; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush tables"; execute abc; execute abc; @@ -1622,15 +1740,15 @@ select Host, User from mysql.user limit 0; select Host, Db from mysql.host limit 0; show open tables from mysql; flush tables; -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush tables; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; flush tables; select Host, User from mysql.user limit 0; select Host, Db from mysql.host limit 0; @@ -1659,15 +1777,15 @@ create procedure proc_1() flush logs; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush logs; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush logs"; execute abc; execute abc; @@ -1679,15 +1797,15 @@ create procedure proc_1() flush status; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush status; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush status"; execute abc; execute abc; @@ -1699,15 +1817,15 @@ create procedure proc_1() flush slave; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush slave; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush slave"; execute abc; execute abc; @@ -1716,15 +1834,15 @@ deallocate prepare abc; create procedure proc_1() flush master; -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush master; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush master"; deallocate prepare abc; @@ -1733,15 +1851,15 @@ create procedure proc_1() flush des_key_file; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush des_key_file; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush des_key_file"; execute abc; execute abc; @@ -1753,15 +1871,15 @@ create procedure proc_1() flush user_resources; call proc_1(); call proc_1(); call proc_1(); -drop procedure proc_1; delimiter |; --error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG create function func_1() returns int begin flush user_resources; return 1; end| +create function func_1() returns int begin call proc_1(); return 1; end| delimiter ;| ---error ER_SP_DOES_NOT_EXIST +--error ER_STMT_NOT_ALLOWED_IN_SF_OR_TRG select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST drop function func_1; +drop procedure proc_1; prepare abc from "flush user_resources"; execute abc; execute abc; @@ -1865,22 +1983,6 @@ execute abc; deallocate prepare abc; -create procedure proc_1() show scheduler status; -drop procedure proc_1; -delimiter |; ---error ER_SP_NO_RETSET -create function func_1() returns int begin show scheduler status; return 1; end| -delimiter ;| ---error ER_SP_DOES_NOT_EXIST -select func_1(), func_1(), func_1() from dual; ---error ER_SP_DOES_NOT_EXIST -drop function func_1; ---error ER_UNSUPPORTED_PS -prepare abc from "show scheduler status"; ---error ER_UNKNOWN_STMT_HANDLER -deallocate prepare abc; - - --disable_warnings drop procedure if exists a; --enable_warnings @@ -1997,10 +2099,13 @@ call proc_1(); call proc_1(); drop procedure proc_1; create procedure proc_1() install plugin my_plug soname 'some_plugin.so'; +--replace_regex /(Can\'t open shared library).*$/\1/ --error ER_CANT_OPEN_LIBRARY call proc_1(); +--replace_regex /(Can\'t open shared library).*$/\1/ --error ER_CANT_OPEN_LIBRARY call proc_1(); +--replace_regex /(Can\'t open shared library).*$/\1/ --error ER_CANT_OPEN_LIBRARY call proc_1(); drop procedure proc_1; @@ -2150,7 +2255,7 @@ drop event if exists xyz; #drop event xyz; #drop procedure proc_1; delimiter |; ---error ER_SP_NO_RETSET +--error ER_EVENT_RECURSIVITY_FORBIDDEN create function func_1() returns int begin create event xyz on schedule at now() do select 123; return 1; end| delimiter ;| --error ER_SP_DOES_NOT_EXIST diff --git a/mysql-test/t/ps_11bugs.test b/mysql-test/t/ps_11bugs.test index ff1c87f3bd8..515bcc03c1a 100644 --- a/mysql-test/t/ps_11bugs.test +++ b/mysql-test/t/ps_11bugs.test @@ -144,3 +144,37 @@ prepare st_18492 from 'select * from t1 where 3 in (select (1+1) union select 1) execute st_18492; drop table t1; + +# +# Bug#19356: Assertion failure with undefined @uservar in prepared statement execution +# +create table t1 (a int, b varchar(4)); +create table t2 (a int, b varchar(4), primary key(a)); + +prepare stmt1 from 'insert into t1 (a, b) values (?, ?)'; +prepare stmt2 from 'insert into t2 (a, b) values (?, ?)'; + +set @intarg= 11; +set @varchararg= '2222'; +execute stmt1 using @intarg, @varchararg; +execute stmt2 using @intarg, @varchararg; +set @intarg= 12; +execute stmt1 using @intarg, @UNDEFINED; +execute stmt2 using @intarg, @UNDEFINED; +set @intarg= 13; +execute stmt1 using @UNDEFINED, @varchararg; +--error 1048 +execute stmt2 using @UNDEFINED, @varchararg; +set @intarg= 14; +set @nullarg= Null; +execute stmt1 using @UNDEFINED, @nullarg; +--error 1048 +execute stmt2 using @nullarg, @varchararg; + +select * from t1; +select * from t2; + +drop table t1; +drop table t2; + +--echo End of 5.0 tests. diff --git a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test index c0b81796731..4c0f411c758 100644 --- a/mysql-test/t/ps_1general.test +++ b/mysql-test/t/ps_1general.test @@ -316,8 +316,8 @@ prepare stmt4 from ' show table status from test like ''t9%'' '; --replace_column 8 # 12 # 13 # 14 # # Bug#4288 execute stmt4; ---replace_column 2 # prepare stmt4 from ' show status like ''Threads_running'' '; +--replace_column 2 # execute stmt4; prepare stmt4 from ' show variables like ''sql_mode'' '; execute stmt4; diff --git a/mysql-test/t/ps_grant.test b/mysql-test/t/ps_grant.test index 4c48b4d151f..b25facdb418 100644 --- a/mysql-test/t/ps_grant.test +++ b/mysql-test/t/ps_grant.test @@ -35,7 +35,7 @@ use mysqltest; --source include/ps_create.inc --source include/ps_renew.inc --enable_query_log -eval use $DB; +use test; grant usage on mysqltest.* to second_user@localhost identified by 'looser' ; grant select on mysqltest.t9 to second_user@localhost diff --git a/mysql-test/t/query_cache.test b/mysql-test/t/query_cache.test index 2c94fe63c04..67c4c4cb20b 100644 --- a/mysql-test/t/query_cache.test +++ b/mysql-test/t/query_cache.test @@ -699,7 +699,7 @@ select a from t1; flush query cache; drop table t1, t2; -set GLOBAL query_cache_size=1355776 +set GLOBAL query_cache_size=1355776; # diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test index 1a80234e485..400e28c3e28 100644 --- a/mysql-test/t/range.test +++ b/mysql-test/t/range.test @@ -515,7 +515,17 @@ OR ((pk4 =1) AND (((pk1 IN ( 7, 2, 1 ))) OR (pk1 =522)) AND ((pk2 IN ( 0, 2635)) ) AND (pk3 >=1000000); drop table t1, t2; -# End of 4.1 tests +# +# Bug #20732: Partial index and long sjis search with '>' fails sometimes +# + +create table t1(a char(2), key(a(1))); +insert into t1 values ('x'), ('xx'); +explain select a from t1 where a > 'x'; +select a from t1 where a > 'x'; +drop table t1; + +--echo End of 4.1 tests # # Test for optimization request #10561: to use keys for diff --git a/mysql-test/t/rename.test b/mysql-test/t/rename.test index 054b1bd3403..5c750711853 100644 --- a/mysql-test/t/rename.test +++ b/mysql-test/t/rename.test @@ -43,8 +43,8 @@ select * from t3; drop table if exists t1,t2,t3,t4; # -# Test-case for Bug #2397 RENAME TABLES is not blocked by -# FLUSH TABLES WITH READ LOCK +# Bug #2397 RENAME TABLES is not blocked by +# FLUSH TABLES WITH READ LOCK # connect (con1,localhost,root,,); @@ -58,12 +58,17 @@ FLUSH TABLES WITH READ LOCK; connection con1; send RENAME TABLE t1 TO t2, t3 to t4; connection con2; -sleep 1; show tables; UNLOCK TABLES; connection con1; reap; connection con2; + +# Wait for the the tables to be renamed +# i.e the query below succeds +let $query= select * from t2, t4; +source include/wait_for_query_to_suceed.inc; + show tables; drop table t2, t4; diff --git a/mysql-test/t/rpl_dual_pos_advance-master.opt b/mysql-test/t/rpl_dual_pos_advance-master.opt index 35fcc5f30c6..cef79bc8585 100644 --- a/mysql-test/t/rpl_dual_pos_advance-master.opt +++ b/mysql-test/t/rpl_dual_pos_advance-master.opt @@ -1 +1 @@ ---loose-to-force-a-restart +--force-restart diff --git a/mysql-test/t/rpl_empty_master_crash-master.opt b/mysql-test/t/rpl_empty_master_crash-master.opt new file mode 100644 index 00000000000..cef79bc8585 --- /dev/null +++ b/mysql-test/t/rpl_empty_master_crash-master.opt @@ -0,0 +1 @@ +--force-restart diff --git a/mysql-test/t/rpl_ndb_auto_inc.test b/mysql-test/t/rpl_ndb_auto_inc.test index 0fc31de9b3a..53bb7e764f1 100644 --- a/mysql-test/t/rpl_ndb_auto_inc.test +++ b/mysql-test/t/rpl_ndb_auto_inc.test @@ -6,6 +6,7 @@ # Date: 2006-02-10 # Change: Augmented test to use with cluster ##################################### +--source include/have_ndb.inc --source include/master-slave.inc --source include/have_binlog_format_mixed_or_row.inc diff --git a/mysql-test/t/rpl_slave_status.test b/mysql-test/t/rpl_slave_status.test index a4a276b63d6..f98cc7a7d14 100644 --- a/mysql-test/t/rpl_slave_status.test +++ b/mysql-test/t/rpl_slave_status.test @@ -19,7 +19,7 @@ start slave; connection master; --disable_warnings drop table if exists t1; ---enable_warning +--enable_warnings create table t1 (n int); insert into t1 values (1); save_master_pos; diff --git a/mysql-test/t/rpl_stm_log-master.opt b/mysql-test/t/rpl_stm_log-master.opt index e0d075c3fbd..cef79bc8585 100644 --- a/mysql-test/t/rpl_stm_log-master.opt +++ b/mysql-test/t/rpl_stm_log-master.opt @@ -1 +1 @@ ---skip-external-locking +--force-restart diff --git a/mysql-test/t/rpl_trigger.test b/mysql-test/t/rpl_trigger.test index 279574a8aaa..6ec0021635a 100644 --- a/mysql-test/t/rpl_trigger.test +++ b/mysql-test/t/rpl_trigger.test @@ -70,7 +70,7 @@ select get_lock("bug12480",2); connection default; create table t1 (a datetime,b datetime, c datetime); ---ignore_warnings +--disable_warnings drop function if exists bug12480; --enable_warnings diff --git a/mysql-test/t/rpl_truncate_7ndb.test b/mysql-test/t/rpl_truncate_7ndb.test index b0d4bdfc763..1d69eee5dd0 100644 --- a/mysql-test/t/rpl_truncate_7ndb.test +++ b/mysql-test/t/rpl_truncate_7ndb.test @@ -39,6 +39,7 @@ SELECT * FROM t1 ORDER BY a,b; --echo **** On Master **** connection master; DROP TABLE t1; +let SERVER_VERSION=`select version()`; --replace_regex /\/\* xid=[0-9]+ \*\//\/* xid= *\// /table_id: [0-9]+/table_id: #/ --replace_result $SERVER_VERSION SERVER_VERSION SHOW BINLOG EVENTS; diff --git a/mysql-test/t/show_check-master.opt b/mysql-test/t/show_check-master.opt new file mode 100644 index 00000000000..3eb98fc3d6b --- /dev/null +++ b/mysql-test/t/show_check-master.opt @@ -0,0 +1 @@ +--log-slow-queries --log-long-format --log-queries-not-using-indexes diff --git a/mysql-test/t/show_check.test b/mysql-test/t/show_check.test index 553b3d9059b..7d4ad099e6f 100644 --- a/mysql-test/t/show_check.test +++ b/mysql-test/t/show_check.test @@ -501,7 +501,19 @@ SHOW TABLES FROM no_such_database; --error ER_NO_SUCH_TABLE SHOW COLUMNS FROM no_such_table; -# End of 5.0 tests. + +# +# Bug #19764: SHOW commands end up in the slow log as table scans +# +flush status; +show status like 'slow_queries'; +show tables; +show status like 'slow_queries'; +# Table scan query, to ensure that slow_queries does still get incremented +# (mysqld is started with --log-queries-not-using-indexes) +select 1 from information_schema.tables limit 1; +show status like 'slow_queries'; + --echo End of 5.0 tests. --disable_result_log diff --git a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test index e829a71c45a..456a23123d3 100644 --- a/mysql-test/t/sp-error.test +++ b/mysql-test/t/sp-error.test @@ -319,7 +319,7 @@ begin declare x int; end| ---error 1332 +--error 1332 create procedure p() begin declare c condition for 1064; @@ -1748,6 +1748,8 @@ drop function if exists bug16896; --error ER_SP_NO_AGGREGATE create aggregate function bug16896() returns int return 1; +# +# # BUG#14702: misleading error message when syntax error in CREATE # PROCEDURE # @@ -1770,6 +1772,47 @@ END; # +# BUG#20953: create proc with a create view that uses local +# vars/params should fail to create +# +# See test case for what syntax is forbidden in a view. +# +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT); + +# We do not have to drop this procedure and view because they won't be +# created. +--error ER_VIEW_SELECT_CLAUSE +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO @a; +--error ER_VIEW_SELECT_CLAUSE +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO DUMPFILE "file"; +--error ER_VIEW_SELECT_CLAUSE +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 INTO OUTFILE "file"; +--error ER_VIEW_SELECT_CLAUSE +CREATE PROCEDURE bug20953() + CREATE VIEW v AS SELECT i FROM t1 PROCEDURE ANALYSE(); +--error ER_VIEW_SELECT_DERIVED +CREATE PROCEDURE bug20953() CREATE VIEW v AS SELECT 1 FROM (SELECT 1) AS d1; +--error ER_VIEW_SELECT_VARIABLE +CREATE PROCEDURE bug20953(i INT) CREATE VIEW v AS SELECT i; +delimiter |; +--error ER_VIEW_SELECT_VARIABLE +CREATE PROCEDURE bug20953() +BEGIN + DECLARE i INT; + CREATE VIEW v AS SELECT i; +END | +delimiter ;| +--error ER_VIEW_SELECT_VARIABLE +PREPARE stmt FROM "CREATE VIEW v AS SELECT ?"; + +DROP TABLE t1; + + +# # End of 5.0 tests # --echo End of 5.0 tests @@ -1788,12 +1831,14 @@ begin show authors; return 42; end| +delimiter ;| + # # BUG#20701: BINARY keyword should be forbidden in stored routines # --disable_warnings -drop function if exists bug20701| +drop function if exists bug20701; --enable_warnings # # This was disabled in 5.1.12. See bug #20701 @@ -1801,17 +1846,19 @@ drop function if exists bug20701| # be removed. # --error ER_NOT_SUPPORTED_YET -create function bug20701() returns varchar(25) binary return "test"| -create function bug20701() returns varchar(25) return "test"| -drop function bug20701| +create function bug20701() returns varchar(25) binary return "test"; +create function bug20701() returns varchar(25) return "test"; +drop function bug20701; + + --echo End of 5.1 tests # # BUG#NNNN: New bug synopsis # #--disable_warnings -#drop procedure if exists bugNNNN| -#drop function if exists bugNNNN| +#drop procedure if exists bugNNNN; +#drop function if exists bugNNNN; #--enable_warnings #create procedure bugNNNN... #create function bugNNNN... diff --git a/mysql-test/t/sp-vars.test b/mysql-test/t/sp-vars.test index 48dbd4de7aa..7cf92dc5d0d 100644 --- a/mysql-test/t/sp-vars.test +++ b/mysql-test/t/sp-vars.test @@ -15,6 +15,7 @@ DROP FUNCTION IF EXISTS sp_vars_check_ret1; DROP FUNCTION IF EXISTS sp_vars_check_ret2; DROP FUNCTION IF EXISTS sp_vars_check_ret3; DROP FUNCTION IF EXISTS sp_vars_check_ret4; +DROP FUNCTION IF EXISTS sp_vars_div_zero; --enable_warnings @@ -49,6 +50,8 @@ SELECT sp_vars_check_ret3(); SELECT sp_vars_check_ret4(); +SELECT sp_vars_div_zero(); + # Check that changing sql_mode after creating a store procedure does not # matter. @@ -72,6 +75,8 @@ SELECT sp_vars_check_ret3(); SELECT sp_vars_check_ret4(); +SELECT sp_vars_div_zero(); + # Create the procedure in TRADITIONAL mode. Check that error will be thrown on # execution. @@ -81,6 +86,7 @@ DROP FUNCTION sp_vars_check_ret1; DROP FUNCTION sp_vars_check_ret2; DROP FUNCTION sp_vars_check_ret3; DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; --source include/sp-vars.inc @@ -110,6 +116,9 @@ SELECT sp_vars_check_ret3(); SELECT sp_vars_check_ret4(); +--error ER_DIVISION_BY_ZERO +SELECT sp_vars_div_zero(); + SET @@sql_mode = 'ansi'; # @@ -122,6 +131,7 @@ DROP FUNCTION sp_vars_check_ret1; DROP FUNCTION sp_vars_check_ret2; DROP FUNCTION sp_vars_check_ret3; DROP FUNCTION sp_vars_check_ret4; +DROP FUNCTION sp_vars_div_zero; ########################################################################### # diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index b3563e21bdd..bb18c0e5858 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -2940,11 +2940,11 @@ begin end| --disable_parsing --replace_regex /table_id: [0-9]+/table_id: #/ -show binlog events; -show storage engines; -show master status; -show slave hosts; -show slave status; +show binlog events| +show storage engines| +show master status| +show slave hosts| +show slave status| --enable_parsing call bug4902()| @@ -6419,6 +6419,170 @@ SELECT bug21493(Member_ID) FROM t3| DROP FUNCTION bug21493| DROP TABLE t3,t4| +# +# Bug#20028 Function with select return no data +# + +--disable_warnings +drop function if exists func_20028_a| +drop function if exists func_20028_b| +drop function if exists func_20028_c| +drop procedure if exists proc_20028_a| +drop procedure if exists proc_20028_b| +drop procedure if exists proc_20028_c| +drop table if exists table_20028| +--enable_warnings + +create table table_20028 (i int)| + +SET @save_sql_mode=@@sql_mode| + +SET sql_mode=''| + +create function func_20028_a() returns integer +begin + declare temp integer; + select i into temp from table_20028 limit 1; + return ifnull(temp, 0); +end| + +create function func_20028_b() returns integer +begin + return func_20028_a(); +end| + +create function func_20028_c() returns integer +begin + declare div_zero integer; + set SQL_MODE='TRADITIONAL'; + select 1/0 into div_zero; + return div_zero; +end| + +create procedure proc_20028_a() +begin + declare temp integer; + select i into temp from table_20028 limit 1; +end| + +create procedure proc_20028_b() +begin + call proc_20028_a(); +end| + +create procedure proc_20028_c() +begin + declare div_zero integer; + set SQL_MODE='TRADITIONAL'; + select 1/0 into div_zero; +end| + +select func_20028_a()| +select func_20028_b()| +--error ER_DIVISION_BY_ZERO +select func_20028_c()| +call proc_20028_a()| +call proc_20028_b()| +--error ER_DIVISION_BY_ZERO +call proc_20028_c()| + +SET sql_mode='TRADITIONAL'| + +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| + +create function func_20028_a() returns integer +begin + declare temp integer; + select i into temp from table_20028 limit 1; + return ifnull(temp, 0); +end| + +create function func_20028_b() returns integer +begin + return func_20028_a(); +end| + +create function func_20028_c() returns integer +begin + declare div_zero integer; + set SQL_MODE=''; + select 1/0 into div_zero; + return div_zero; +end| + +create procedure proc_20028_a() +begin + declare temp integer; + select i into temp from table_20028 limit 1; +end| + +create procedure proc_20028_b() +begin + call proc_20028_a(); +end| + +create procedure proc_20028_c() +begin + declare div_zero integer; + set SQL_MODE=''; + select 1/0 into div_zero; +end| + +select func_20028_a()| +select func_20028_b()| +select func_20028_c()| +call proc_20028_a()| +call proc_20028_b()| +call proc_20028_c()| + +SET @@sql_mode=@save_sql_mode| + +drop function func_20028_a| +drop function func_20028_b| +drop function func_20028_c| +drop procedure proc_20028_a| +drop procedure proc_20028_b| +drop procedure proc_20028_c| +drop table table_20028| + +# +# Bug#21462 Stored procedures with no arguments require parenthesis +# + +--disable_warnings +drop procedure if exists proc_21462_a| +drop procedure if exists proc_21462_b| +--enable_warnings + +create procedure proc_21462_a() +begin + select "Called A"; +end| + +create procedure proc_21462_b(x int) +begin + select "Called B"; +end| + +call proc_21462_a| +call proc_21462_a()| +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_a(1)| + +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_b| +-- error ER_SP_WRONG_NO_OF_ARGS +call proc_21462_b()| +call proc_21462_b(1)| + +drop procedure proc_21462_a| +drop procedure proc_21462_b| + --echo End of 5.0 tests diff --git a/mysql-test/t/sp_notembedded.test b/mysql-test/t/sp_notembedded.test index 28abf448089..6335ad55606 100644 --- a/mysql-test/t/sp_notembedded.test +++ b/mysql-test/t/sp_notembedded.test @@ -19,11 +19,11 @@ begin show grants for 'root'@'localhost'; end| --disable_parsing -show binlog events; -show storage engines; -show master status; -show slave hosts; -show slave status; +show binlog events| +show storage engines| +show master status| +show slave hosts| +show slave status| --enable_parsing call bug4902()| @@ -110,7 +110,7 @@ flush status| flush query cache| delete from t1| drop procedure bug3583| -drop table t1; +drop table t1| # # BUG#6807: Stored procedure crash if CREATE PROCEDURE ... KILL QUERY diff --git a/mysql-test/t/ssl_des-master.opt b/mysql-test/t/ssl_des-master.opt new file mode 100644 index 00000000000..0b2b8cb85ac --- /dev/null +++ b/mysql-test/t/ssl_des-master.opt @@ -0,0 +1 @@ +--loose_ssl-cert=std_data/server-cert-des.pem --loose_ssl-key=std_data/server-key-des.pem diff --git a/mysql-test/t/ssl_des.test b/mysql-test/t/ssl_des.test new file mode 100644 index 00000000000..7cf2c920ab5 --- /dev/null +++ b/mysql-test/t/ssl_des.test @@ -0,0 +1,19 @@ +# Tell the server to use a DES-encrypted cert +# then turn on ssl between the client and server +# and run a number of standard tests + +-- source include/have_openssl.inc + +# Connect by ip to avoid turning on "ssl-verify-server-cert" +connect (ssl_con,127.0.0.1,root,,,,$MASTER_MYPORT,SSL); + +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; + +# Source select test case +-- source include/common-tests.inc + +# Check ssl turned on +SHOW STATUS LIKE 'Ssl_cipher'; + + diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index 6d5082c360b..dee5b1e4fb0 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1728,7 +1728,7 @@ select (select a from t1) = (1,2); select (1,2,3) = (select * from t1); -- error 1241 select (select * from t1) = (1,2,3); -drop table t1 +drop table t1; # # Item_int_with_ref check (BUG#10020) diff --git a/mysql-test/t/system_mysql_db_fix.test b/mysql-test/t/system_mysql_db_fix.test index daba3b6ff86..3956e26e9cc 100644 --- a/mysql-test/t/system_mysql_db_fix.test +++ b/mysql-test/t/system_mysql_db_fix.test @@ -42,7 +42,7 @@ CREATE TABLE db ( KEY User (User) ) engine=MyISAM; ---enable-warnings +--enable_warnings INSERT INTO db VALUES ('%','test', '','Y','Y','Y','Y','Y','Y'); INSERT INTO db VALUES ('%','test\_%','','Y','Y','Y','Y','Y','Y'); @@ -60,7 +60,7 @@ CREATE TABLE host ( PRIMARY KEY Host (Host,Db) ) engine=MyISAM; ---enable-warnings +--enable_warnings --disable_warnings CREATE TABLE user ( @@ -79,7 +79,7 @@ CREATE TABLE user ( PRIMARY KEY Host (Host,User) ) engine=MyISAM; ---enable-warnings +--enable_warnings INSERT INTO user VALUES ('localhost','root','','Y','Y','Y','Y','Y','Y','Y','Y','Y'); INSERT INTO user VALUES ('localhost','', '','N','N','N','N','N','N','N','N','N'); diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index ccc17e55dc8..8242c614d0a 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -1274,7 +1274,6 @@ INSERT INTO t1 VALUES (@x); SELECT @x; SET @x=2; ---error ER_DIVISION_BY_ZERO UPDATE t1 SET i1 = @x; SELECT @x; @@ -1285,7 +1284,6 @@ INSERT INTO t1 VALUES (@x); SELECT @x; SET @x=4; ---error ER_DIVISION_BY_ZERO UPDATE t1 SET i1 = @x; SELECT @x; @@ -1420,6 +1418,67 @@ CREATE DEFINER=some_user_name@1234567890abcdefghij1234567890abcdefghij1234567890 DROP TABLE t1; DROP TABLE t2; +# +# Bug#20028 Function with select return no data +# + +--disable_warnings +drop table if exists t1; +drop table if exists t2; +drop table if exists t3; +drop table if exists t4; +--enable_warnings + +SET @save_sql_mode=@@sql_mode; + +delimiter |; +SET sql_mode='TRADITIONAL'| +create table t1 (id int(10) not null primary key, v int(10) )| +create table t2 (id int(10) not null primary key, v int(10) )| +create table t3 (id int(10) not null primary key, v int(10) )| +create table t4 (c int)| + +create trigger t4_bi before insert on t4 for each row set @t4_bi_called:=1| +create trigger t4_bu before update on t4 for each row set @t4_bu_called:=1| + +insert into t1 values(10, 10)| +set @a:=1/0| +select 1/0 from t1| + +create trigger t1_bi before insert on t1 for each row set @a:=1/0| + +insert into t1 values(20, 20)| + +drop trigger t1_bi| +create trigger t1_bi before insert on t1 for each row +begin + insert into t2 values (new.id, new.v); + update t2 set v=v+1 where id= new.id; + replace t3 values (new.id, 0); + update t2, t3 set t2.v=new.v, t3.v=new.v where t2.id=t3.id; + create temporary table t5 select * from t1; + delete from t5; + insert into t5 select * from t1; + insert into t4 values (0); + set @check= (select count(*) from t5); + update t4 set c= @check; + drop temporary table t5; + + set @a:=1/0; +end| + +set @check=0, @t4_bi_called=0, @t4_bu_called=0| +insert into t1 values(30, 30)| +select @check, @t4_bi_called, @t4_bu_called| + +delimiter ;| + +SET @@sql_mode=@save_sql_mode; + +drop table t1; +drop table t2; +drop table t3; +drop table t4; # # Bug#20670 "UPDATE using key and invoking trigger that modifies diff --git a/mysql-test/t/type_newdecimal.test b/mysql-test/t/type_newdecimal.test index 6bf18b30c41..1b80a15e4ff 100644 --- a/mysql-test/t/type_newdecimal.test +++ b/mysql-test/t/type_newdecimal.test @@ -1000,9 +1000,9 @@ drop table t1; # # Bug 12938 (arithmetic loop's zero) # ---disable-warnings +--disable_warnings drop procedure if exists wg2; ---enable-warnings +--enable_warnings delimiter //; create procedure wg2() begin diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index 644ca506eba..65ca1b2c1b7 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -144,6 +144,8 @@ select @@version; --replace_column 1 # select @@global.version; +--echo End of 4.1 tests + # Bug #6598: problem with cast(NULL as signed integer); # @@ -210,4 +212,10 @@ select @var:=f2 from t1 group by f1 order by f2 desc limit 1; select @var; drop table t1; -# End of 4.1 tests +# +# Bug#19024 - SHOW COUNT(*) WARNINGS not return Errors +# +--error 1064 +insert into city 'blah'; +SHOW COUNT(*) WARNINGS; +SHOW COUNT(*) ERRORS; diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 66efc86da18..d7c1ccce733 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -23,8 +23,11 @@ create table t1 (a int, b int); insert into t1 values (1,2), (1,3), (2,4), (2,5), (3,10); # view with variable --- error 1351 +-- error ER_VIEW_SELECT_VARIABLE create view v1 (c,d) as select a,b+@@global.max_user_connections from t1; +-- error ER_VIEW_SELECT_VARIABLE +create view v1 (c,d) as select a,b from t1 + where a = @@global.max_user_connections; # simple view create view v1 (c) as select b+1 from t1; @@ -487,19 +490,6 @@ drop view v1; create view v1 (a,a) as select 'a','a'; # -# SP variables inside view test -# ---disable_warnings -drop procedure if exists p1; ---enable_warnings -delimiter //; -create procedure p1 () begin declare v int; create view v1 as select v; end;// -delimiter ;// --- error 1351 -call p1(); -drop procedure p1; - -# # updatablity should be transitive # create table t1 (col1 int,col2 char(22)); @@ -820,6 +810,8 @@ create view v1 as select 5 into outfile 'ttt'; create table t1 (a int); -- error 1350 create view v1 as select a from t1 procedure analyse(); +-- error ER_VIEW_SELECT_DERIVED +create view v1 as select 1 from (select 1) as d1; drop table t1; # @@ -1801,9 +1793,7 @@ drop table t1; # underlying tables (BUG#6443) # set sql_mode='strict_all_tables'; ---disable_warnings -CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL) ENGINE = INNODB; ---enable_warnings +CREATE TABLE t1 (col1 INT NOT NULL, col2 INT NOT NULL); CREATE VIEW v1 (vcol1) AS SELECT col1 FROM t1; CREATE VIEW v2 (vcol1) AS SELECT col1 FROM t1 WHERE col2 > 2; -- error 1364 @@ -1859,9 +1849,7 @@ drop table t1; # # Test for bug #11771: wrong query_id in SELECT * FROM <view> # ---disable_warnings -CREATE TABLE t1 (f1 char) ENGINE = innodb; ---enable_warnings +CREATE TABLE t1 (f1 char); INSERT INTO t1 VALUES ('A'); CREATE VIEW v1 AS SELECT * FROM t1; @@ -2886,6 +2874,38 @@ DROP VIEW v1; DROP TABLE t1, t2; # +# Bug#19111: TRIGGERs selecting from a VIEW on the firing base table +# fail +# +# Allow to select from a view on a table being modified in a trigger +# and stored function, since plain select is allowed there. +# +--disable_warnings +DROP FUNCTION IF EXISTS f1; +DROP VIEW IF EXISTS v1; +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT); +INSERT INTO t1 VALUES (1); + +CREATE VIEW v1 AS SELECT MAX(i) FROM t1; + +# Plain 'SET NEW.i = (SELECT MAX(i) FROM t1) + 1' works, so select +# from a view should work too. +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 FOR EACH ROW + SET NEW.i = (SELECT * FROM v1) + 1; +INSERT INTO t1 VALUES (1); + +# Plain 'RETURN (SELECT MAX(i) FROM t1)' works in INSERT, so select +# from a view should work too. +CREATE FUNCTION f1() RETURNS INT RETURN (SELECT * FROM v1); +UPDATE t1 SET i= f1(); + +DROP FUNCTION f1; +DROP VIEW v1; +DROP TABLE t1; + # Bug #16813 (WITH CHECK OPTION doesn't work with UPDATE) # CREATE TABLE t1(id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, val INT UNSIGNED NOT NULL); @@ -2899,6 +2919,45 @@ UPDATE v1 SET val=6 WHERE id=2; DROP VIEW v1; DROP TABLE t1; + +# +# BUG#22584: last_insert_id not updated after inserting a record +# through a updatable view +# +# We still do not update LAST_INSERT_ID if AUTO_INCREMENT column is +# not accessible through a view. However, we do not reset the value +# of LAST_INSERT_ID, but keep it unchanged. +# +--disable_warnings +DROP VIEW IF EXISTS v1, v2; +DROP TABLE IF EXISTS t1; +--enable_warnings + +CREATE TABLE t1 (i INT AUTO_INCREMENT PRIMARY KEY, j INT); +CREATE VIEW v1 AS SELECT j FROM t1; +CREATE VIEW v2 AS SELECT * FROM t1; + +INSERT INTO t1 (j) VALUES (1); +SELECT LAST_INSERT_ID(); + +INSERT INTO v1 (j) VALUES (2); +--echo # LAST_INSERT_ID() should not change. +SELECT LAST_INSERT_ID(); + +INSERT INTO v2 (j) VALUES (3); +--echo # LAST_INSERT_ID() should be updated. +SELECT LAST_INSERT_ID(); + +INSERT INTO v1 (j) SELECT j FROM t1; +--echo # LAST_INSERT_ID() should not change. +SELECT LAST_INSERT_ID(); + +SELECT * FROM t1; + +DROP VIEW v1, v2; +DROP TABLE t1; + + --echo End of 5.0 tests. # diff --git a/mysql-test/t/wait_for_socket.sh b/mysql-test/t/wait_for_socket.sh new file mode 100755 index 00000000000..3b900fa2208 --- /dev/null +++ b/mysql-test/t/wait_for_socket.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +########################################################################### + +if [ $# -ne 6 ]; then + echo "Usage: wait_for_socket.sh <executable path> <socket path> <username> <password> <db> <timeout>" + exit 0 +fi + +client_exe="$1" +socket_path="$2" +username="$3" +password="$4" +db="$5" +total_timeout="$6" + +########################################################################### + +if [ -z "$client_exe" ]; then + echo "Error: invalid path to client executable ($client_exe)." + exit 0; +fi + +if [ ! -x "$client_exe" ]; then + echo "Error: client by path '$client_exe' is not available." + exit 0; +fi + +if [ -z "$socket_path" ]; then + echo "Error: invalid socket patch." + exit 0 +fi + +########################################################################### + +client_args="--silent --socket=$socket_path " + +[ -n "$username" ] && client_args="$client_args --user=$username " +[ -n "$password" ] && client_args="$client_args --password=$password " +[ -n "$db" ] && client_args="$client_args $db" + +########################################################################### + +cur_attempt=1 + +while true; do + + if ( echo 'quit' | "$client_exe" $client_args >/dev/null 2>&1 ); then + echo "Success: server is ready to accept connection on socket." + exit 0 + fi + + [ $cur_attempt -ge $total_timeout ] && break + + sleep 1 + + cur_attempt=`expr $cur_attempt + 1` + +done + +echo "Error: server does not accept connections after $total_timeout seconds." +exit 0 diff --git a/mysql-test/t/wait_timeout.test b/mysql-test/t/wait_timeout.test index dbd792e48d8..bdff72cdc76 100644 --- a/mysql-test/t/wait_timeout.test +++ b/mysql-test/t/wait_timeout.test @@ -55,7 +55,7 @@ select 2; select 3; # Disconnect so that we will not be confused by a future abort from this # connection. -disconnect default +disconnect default; # # Do the same test as above on a TCP connection diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 4aa99a70121..7b362b4c1f9 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -20,7 +20,7 @@ ADD_LIBRARY(mysys array.c charset-def.c charset.c checksum.c default.c default_m my_clock.c my_compress.c my_conio.c my_copy.c my_crc32.c my_create.c my_delete.c my_div.c my_error.c my_file.c my_fopen.c my_fstream.c my_gethostbyname.c my_gethwaddr.c my_getopt.c my_getsystime.c my_getwd.c my_handler.c my_init.c - my_lib.c my_lock.c my_lockmem.c my_lread.c my_lwrite.c my_malloc.c my_messnc.c + my_lib.c my_lock.c my_lockmem.c my_malloc.c my_messnc.c my_mkdir.c my_mmap.c my_net.c my_once.c my_open.c my_pread.c my_pthread.c my_quick.c my_read.c my_realloc.c my_redel.c my_rename.c my_seek.c my_sleep.c my_static.c my_symlink.c my_symlink2.c my_sync.c my_thr_init.c my_wincond.c diff --git a/mysys/Makefile.am b/mysys/Makefile.am index b209d64e78f..79d79d41c34 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -43,7 +43,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ tree.c trie.c list.c hash.c array.c string.c typelib.c \ my_copy.c my_append.c my_lib.c \ my_delete.c my_rename.c my_redel.c \ - my_chsize.c my_lread.c my_lwrite.c my_clock.c \ + my_chsize.c my_clock.c \ my_quick.c my_lockmem.c my_static.c \ my_sync.c my_getopt.c my_mkdir.c \ default_modify.c default.c \ diff --git a/mysys/charset.c b/mysys/charset.c index 64b15fab0c2..d10a580ae4e 100644 --- a/mysys/charset.c +++ b/mysys/charset.c @@ -312,7 +312,7 @@ static my_bool my_read_charset_file(const char *filename, myf myflags) { char *buf; int fd; - uint len; + uint len, tmp_len; MY_STAT stat_info; if (!my_stat(filename, &stat_info, MYF(myflags)) || @@ -321,12 +321,11 @@ static my_bool my_read_charset_file(const char *filename, myf myflags) return TRUE; if ((fd=my_open(filename,O_RDONLY,myflags)) < 0) - { - my_free(buf,myflags); - return TRUE; - } - len=read(fd,buf,len); + goto error; + tmp_len=my_read(fd, buf, len, myflags); my_close(fd,myflags); + if (tmp_len != len) + goto error; if (my_parse_charset_xml(buf,len,add_collation)) { @@ -340,6 +339,10 @@ static my_bool my_read_charset_file(const char *filename, myf myflags) my_free(buf, myflags); return FALSE; + +error: + my_free(buf, myflags); + return TRUE; } diff --git a/mysys/make-ccc b/mysys/make-ccc index 9c54185682a..b34bd80e1d1 100755 --- a/mysys/make-ccc +++ b/mysys/make-ccc @@ -1,4 +1,4 @@ rm -f .deps/* raid.o mf_iocache.o libmysys.a -ccc -DDEFAULT_BASEDIR="\"/usr/local/mysql\"" -DDATADIR="\"/usr/local/mysql/var\"" -DHAVE_CONFIG_H -I./../include -I../include -I.. -DDBUG_OFF -fast -O3 -fomit-frame-pointer -c array.c checksum.c default.c errors.c getopt.c getopt1.c getvar.c hash.c list.c mf_brkhant.c mf_cache.c mf_casecnv.c mf_dirname.c mf_fn_ext.c mf_format.c mf_getdate.c mf_keycache.c mf_loadpath.c mf_pack.c mf_pack2.c mf_path.c mf_qsort.c mf_qsort2.c mf_radix.c mf_reccache.c mf_same.c mf_sort.c mf_soundex.c mf_stripp.c mf_unixpath.c mf_wcomp.c mf_wfile.c mulalloc.c my_alarm.c my_alloc.c my_append.c my_chsize.c my_clock.c my_compress.c my_copy.c my_create.c my_delete.c my_div.c my_error.c my_fopen.c my_fstream.c my_getwd.c my_init.c my_lib.c my_lockmem.c my_lread.c my_lwrite.c my_malloc.c my_messnc.c my_mkdir.c my_net.c my_once.c my_open.c my_pread.c my_pthread.c my_quick.c my_read.c my_realloc.c my_redel.c my_rename.c my_seek.c my_static.c my_tempnam.c my_thr_init.c my_write.c ptr_cmp.c queues.c safemalloc.c string.c thr_alarm.c thr_lock.c thr_mutex.c thr_rwlock.c tree.c typelib.c +ccc -DDEFAULT_BASEDIR="\"/usr/local/mysql\"" -DDATADIR="\"/usr/local/mysql/var\"" -DHAVE_CONFIG_H -I./../include -I../include -I.. -DDBUG_OFF -fast -O3 -fomit-frame-pointer -c array.c checksum.c default.c errors.c getopt.c getopt1.c getvar.c hash.c list.c mf_brkhant.c mf_cache.c mf_casecnv.c mf_dirname.c mf_fn_ext.c mf_format.c mf_getdate.c mf_keycache.c mf_loadpath.c mf_pack.c mf_pack2.c mf_path.c mf_qsort.c mf_qsort2.c mf_radix.c mf_reccache.c mf_same.c mf_sort.c mf_soundex.c mf_stripp.c mf_unixpath.c mf_wcomp.c mf_wfile.c mulalloc.c my_alarm.c my_alloc.c my_append.c my_chsize.c my_clock.c my_compress.c my_copy.c my_create.c my_delete.c my_div.c my_error.c my_fopen.c my_fstream.c my_getwd.c my_init.c my_lib.c my_lockmem.c my_malloc.c my_messnc.c my_mkdir.c my_net.c my_once.c my_open.c my_pread.c my_pthread.c my_quick.c my_read.c my_realloc.c my_redel.c my_rename.c my_seek.c my_static.c my_tempnam.c my_thr_init.c my_write.c ptr_cmp.c queues.c safemalloc.c string.c thr_alarm.c thr_lock.c thr_mutex.c thr_rwlock.c tree.c typelib.c make raid.o mf_iocache.o my_lock.o ar -cr libmysys.a array.o raid.o mf_iocache.o my_lock.o diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index b1cf940d70d..249eaf48ad2 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -332,7 +332,11 @@ my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type, { info->read_end=info->write_pos; info->end_of_file=my_b_tell(info); - info->seek_not_done=1; + /* + Trigger a new seek only if we have a valid + file handle. + */ + info->seek_not_done= (info->file != -1); } else if (type == WRITE_CACHE) { @@ -441,11 +445,24 @@ int _my_b_read(register IO_CACHE *info, byte *Buffer, uint Count) /* pos_in_file always point on where info->buffer was read */ pos_in_file=info->pos_in_file+(uint) (info->read_end - info->buffer); + + /* + Whenever a function which operates on IO_CACHE flushes/writes + some part of the IO_CACHE to disk it will set the property + "seek_not_done" to indicate this to other functions operating + on the IO_CACHE. + */ if (info->seek_not_done) - { /* File touched, do seek */ - VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0))); + { + if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) + == MY_FILEPOS_ERROR) + { + info->error= -1; + DBUG_RETURN(1); + } info->seek_not_done=0; } + diff_length=(uint) (pos_in_file & (IO_SIZE-1)); if (Count >= (uint) (IO_SIZE+(IO_SIZE-diff_length))) { /* Fill first intern buffer */ @@ -946,8 +963,22 @@ int _my_b_read_r(register IO_CACHE *cache, byte *Buffer, uint Count) len= 0; else { - if (cache->seek_not_done) /* File touched, do seek */ - VOID(my_seek(cache->file, pos_in_file, MY_SEEK_SET, MYF(0))); + /* + Whenever a function which operates on IO_CACHE flushes/writes + some part of the IO_CACHE to disk it will set the property + "seek_not_done" to indicate this to other functions operating + on the IO_CACHE. + */ + if (cache->seek_not_done) + { + if (my_seek(cache->file, pos_in_file, MY_SEEK_SET, MYF(0)) + == MY_FILEPOS_ERROR) + { + cache->error= -1; + unlock_io_cache(cache); + DBUG_RETURN(1); + } + } len= (int) my_read(cache->file, cache->buffer, length, cache->myflags); } DBUG_PRINT("io_cache_share", ("read %d bytes", len)); @@ -1049,11 +1080,16 @@ static void copy_to_read_buffer(IO_CACHE *write_cache, /* - Do sequential read from the SEQ_READ_APPEND cache - we do this in three stages: + Do sequential read from the SEQ_READ_APPEND cache. + + We do this in three stages: - first read from info->buffer - then if there are still data to read, try the file descriptor - afterwards, if there are still data to read, try append buffer + + RETURNS + 0 Success + 1 Failed to read */ int _my_b_seq_read(register IO_CACHE *info, byte *Buffer, uint Count) @@ -1081,7 +1117,13 @@ int _my_b_seq_read(register IO_CACHE *info, byte *Buffer, uint Count) With read-append cache we must always do a seek before we read, because the write could have moved the file pointer astray */ - VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0))); + if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)) + == MY_FILEPOS_ERROR) + { + info->error= -1; + unlock_append_buffer(info); + return (1); + } info->seek_not_done=0; diff_length=(uint) (pos_in_file & (IO_SIZE-1)); @@ -1197,6 +1239,21 @@ read_append_buffer: #ifdef HAVE_AIOWAIT +/* + Read from the IO_CACHE into a buffer and feed asynchronously + from disk when needed. + + SYNOPSIS + _my_b_async_read() + info IO_CACHE pointer + Buffer Buffer to retrieve count bytes from file + Count Number of bytes to read into Buffer + + RETURN VALUE + -1 An error has occurred; my_errno is set. + 0 Success + 1 An error has occurred; IO_CACHE to error state. +*/ int _my_b_async_read(register IO_CACHE *info, byte *Buffer, uint Count) { uint length,read_length,diff_length,left_length,use_length,org_Count; @@ -1287,13 +1344,20 @@ int _my_b_async_read(register IO_CACHE *info, byte *Buffer, uint Count) info->error=(int) (read_length+left_length); return 1; } - VOID(my_seek(info->file,next_pos_in_file,MY_SEEK_SET,MYF(0))); + + if (my_seek(info->file,next_pos_in_file,MY_SEEK_SET,MYF(0)) + == MY_FILEPOS_ERROR) + { + info->error= -1; + return (1); + } + read_length=IO_SIZE*2- (uint) (next_pos_in_file & (IO_SIZE-1)); if (Count < read_length) { /* Small block, read to cache */ if ((read_length=my_read(info->file,info->request_pos, read_length, info->myflags)) == (uint) -1) - return info->error= -1; + return info->error= -1; use_length=min(Count,read_length); memcpy(Buffer,info->request_pos,(size_t) use_length); info->read_pos=info->request_pos+Count; @@ -1380,7 +1444,15 @@ int _my_b_get(IO_CACHE *info) return (int) (uchar) buff; } - /* Returns != 0 if error on write */ +/* + Write a byte buffer to IO_CACHE and flush to disk + if IO_CACHE is full. + + RETURN VALUE + 1 On error on write + 0 On success + -1 On error; my_errno contains error code. +*/ int _my_b_write(register IO_CACHE *info, const byte *Buffer, uint Count) { @@ -1404,8 +1476,18 @@ int _my_b_write(register IO_CACHE *info, const byte *Buffer, uint Count) { /* Fill first intern buffer */ length=Count & (uint) ~(IO_SIZE-1); if (info->seek_not_done) - { /* File touched, do seek */ - VOID(my_seek(info->file,info->pos_in_file,MY_SEEK_SET,MYF(0))); + { + /* + Whenever a function which operates on IO_CACHE flushes/writes + some part of the IO_CACHE to disk it will set the property + "seek_not_done" to indicate this to other functions operating + on the IO_CACHE. + */ + if (my_seek(info->file,info->pos_in_file,MY_SEEK_SET,MYF(0))) + { + info->error= -1; + return (1); + } info->seek_not_done=0; } if (my_write(info->file,Buffer,(uint) length,info->myflags | MY_NABP)) diff --git a/mysys/my_chsize.c b/mysys/my_chsize.c index fe0d0ffa607..4b26085c870 100644 --- a/mysys/my_chsize.c +++ b/mysys/my_chsize.c @@ -86,7 +86,11 @@ int my_chsize(File fd, my_off_t newlength, int filler, myf MyFlags) Fill space between requested length and true length with 'filler' We should never come here on any modern machine */ - VOID(my_seek(fd, newlength, MY_SEEK_SET, MYF(MY_WME+MY_FAE))); + if (my_seek(fd, newlength, MY_SEEK_SET, MYF(MY_WME+MY_FAE)) + == MY_FILEPOS_ERROR) + { + goto err; + } swap_variables(my_off_t, newlength, oldsize); #endif } diff --git a/mysys/my_lock.c b/mysys/my_lock.c index 919727e03d6..e32807004e8 100644 --- a/mysys/my_lock.c +++ b/mysys/my_lock.c @@ -30,7 +30,14 @@ #include <nks/fsio.h> #endif - /* Lock a part of a file */ +/* + Lock a part of a file + + RETURN VALUE + 0 Success + -1 An error has occured and 'my_errno' is set + to indicate the actual error code. +*/ int my_lock(File fd, int locktype, my_off_t start, my_off_t length, myf MyFlags) @@ -94,10 +101,22 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length, #elif defined(HAVE_LOCKING) /* Windows */ { - my_bool error; + my_bool error= FALSE; pthread_mutex_lock(&my_file_info[fd].mutex); - if (MyFlags & MY_SEEK_NOT_DONE) - VOID(my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))); + if (MyFlags & MY_SEEK_NOT_DONE) + { + if( my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE)) + == MY_FILEPOS_ERROR ) + { + /* + If my_seek fails my_errno will already contain an error code; + just unlock and return error code. + */ + DBUG_PRINT("error",("my_errno: %d (%d)",my_errno,errno)); + pthread_mutex_unlock(&my_file_info[fd].mutex); + DBUG_RETURN(-1); + } + } error= locking(fd,locktype,(ulong) length) && errno != EINVAL; pthread_mutex_unlock(&my_file_info[fd].mutex); if (!error) @@ -135,7 +154,17 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length, } #else if (MyFlags & MY_SEEK_NOT_DONE) - VOID(my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))); + { + if (my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE)) + == MY_FILEPOS_ERROR) + { + /* + If an error has occured in my_seek then we will already + have an error code in my_errno; Just return error code. + */ + DBUG_RETURN(-1); + } + } if (lockf(fd,locktype,length) != -1) DBUG_RETURN(0); #endif /* HAVE_FCNTL */ diff --git a/mysys/my_lread.c b/mysys/my_lread.c deleted file mode 100644 index 601d772b844..00000000000 --- a/mysys/my_lread.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (C) 2000 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" - - /* Read a chunk of bytes from a file */ - -uint32 my_lread(int Filedes, byte *Buffer, uint32 Count, myf MyFlags) - /* File descriptor */ - /* Buffer must be at least count bytes */ - /* Max number of bytes returnd */ - /* Flags on what to do on error */ -{ - uint32 readbytes; - DBUG_ENTER("my_lread"); - DBUG_PRINT("my",("Fd: %d Buffer: %ld Count: %ld MyFlags: %d", - Filedes, Buffer, Count, MyFlags)); - - /* Temp hack to get count to int32 while read wants int */ - if ((readbytes = (uint32) read(Filedes, Buffer, (uint) Count)) != Count) - { - my_errno=errno; - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - if (readbytes == MY_FILE_ERROR) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),errno); - else - if (MyFlags & (MY_NABP | MY_FNABP)) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),errno); - } - if (readbytes == MY_FILE_ERROR || MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN((uint32) -1); /* Return med felkod */ - } - if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Ok vid l{sning */ - DBUG_RETURN(readbytes); -} /* my_lread */ diff --git a/mysys/my_lwrite.c b/mysys/my_lwrite.c deleted file mode 100644 index 3b9afdbd71f..00000000000 --- a/mysys/my_lwrite.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2000 MySQL AB - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" - - /* Write a chunk of bytes to a file */ - -uint32 my_lwrite(int Filedes, const byte *Buffer, uint32 Count, myf MyFlags) -{ - uint32 writenbytes; - DBUG_ENTER("my_lwrite"); - DBUG_PRINT("my",("Fd: %d Buffer: 0x%lx Count: %ld MyFlags: %d", - Filedes, Buffer, Count, MyFlags)); - - /* Temp hack to get count to int32 while write wants int */ - if ((writenbytes = (uint32) write(Filedes, Buffer, (uint) Count)) != Count) - { - my_errno=errno; - if (writenbytes == (uint32) -1 || MyFlags & (MY_NABP | MY_FNABP)) - { - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),errno); - } - DBUG_RETURN((uint32) -1); /* Return med felkod */ - } - } - if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Ok vid l{sning */ - DBUG_RETURN(writenbytes); -} /* my_lwrite */ diff --git a/mysys/my_pread.c b/mysys/my_pread.c index 978366e57e5..45a4a363c0a 100644 --- a/mysys/my_pread.c +++ b/mysys/my_pread.c @@ -75,8 +75,12 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset, DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d", readbytes,Count,Filedes,my_errno)); #ifdef THREAD - if (readbytes == 0 && errno == EINTR) - continue; /* Interrupted */ + if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR) + { + DBUG_PRINT("debug", ("my_pread() was interrupted and returned %d", + (int) readbytes)); + continue; /* Interrupted */ + } #endif if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { @@ -170,8 +174,8 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset, VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); continue; } - if ((writenbytes == 0 && my_errno == EINTR) || - (writenbytes > 0 && (uint) writenbytes != (uint) -1)) + if ((writenbytes > 0 && (uint) writenbytes != (uint) -1) || + my_errno == EINTR) continue; /* Retry */ #endif if (MyFlags & (MY_NABP | MY_FNABP)) diff --git a/mysys/my_quick.c b/mysys/my_quick.c index 44ed3fc0b2c..ffc8160c371 100644 --- a/mysys/my_quick.c +++ b/mysys/my_quick.c @@ -26,6 +26,14 @@ uint my_quick_read(File Filedes,byte *Buffer,uint Count,myf MyFlags) if ((readbytes = (uint) read(Filedes, Buffer, Count)) != Count) { +#ifndef DBUG_OFF + if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR) + { + DBUG_PRINT("error", ("my_quick_read() was interrupted and returned %d" + ". This function does not retry the read!", + (int) readbytes)); + } +#endif my_errno=errno; return readbytes; } @@ -35,8 +43,24 @@ uint my_quick_read(File Filedes,byte *Buffer,uint Count,myf MyFlags) uint my_quick_write(File Filedes,const byte *Buffer,uint Count) { - if ((uint) write(Filedes,Buffer,Count) != Count) +#ifndef DBUG_OFF + uint writtenbytes; +#endif + + if (( +#ifndef DBUG_OFF + writtenbytes = +#endif + (uint) write(Filedes,Buffer,Count)) != Count) { +#ifndef DBUG_OFF + if ((writtenbytes == 0 || (int) writtenbytes == -1) && errno == EINTR) + { + DBUG_PRINT("error", ("my_quick_write() was interrupted and returned %d" + ". This function does not retry the write!", + (int) writtenbytes)); + } +#endif my_errno=errno; return (uint) -1; } diff --git a/mysys/my_read.c b/mysys/my_read.c index 2e23f2175f8..8b88e483fef 100644 --- a/mysys/my_read.c +++ b/mysys/my_read.c @@ -51,10 +51,11 @@ uint my_read(File Filedes, byte *Buffer, uint Count, myf MyFlags) DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d", readbytes, Count, Filedes, my_errno)); #ifdef THREAD - if ((int) readbytes <= 0 && errno == EINTR) - { - DBUG_PRINT("debug", ("my_read() was interrupted and returned %d", (int) readbytes)); - continue; /* Interrupted */ + if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR) + { + DBUG_PRINT("debug", ("my_read() was interrupted and returned %d", + (int) readbytes)); + continue; /* Interrupted */ } #endif if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) diff --git a/mysys/my_seek.c b/mysys/my_seek.c index e5b1905e551..269d1a65b31 100644 --- a/mysys/my_seek.c +++ b/mysys/my_seek.c @@ -16,8 +16,30 @@ #include "mysys_priv.h" - /* Seek to position in file */ - /*ARGSUSED*/ +/* + Seek to a position in a file. + + ARGUMENTS + File fd The file descriptor + my_off_t pos The expected position (absolute or relative) + int whence A direction parameter and one of + {SEEK_SET, SEEK_CUR, SEEK_END} + myf MyFlags Not used. + + DESCRIPTION + The my_seek function is a wrapper around the system call lseek and + repositions the offset of the file descriptor fd to the argument + offset according to the directive whence as follows: + SEEK_SET The offset is set to offset bytes. + SEEK_CUR The offset is set to its current location plus offset bytes + SEEK_END The offset is set to the size of the file plus offset bytes + + RETURN VALUE + my_off_t newpos The new position in the file. + MY_FILEPOS_ERROR An error was encountered while performing + the seek. my_errno is set to indicate the + actual error. +*/ my_off_t my_seek(File fd, my_off_t pos, int whence, myf MyFlags __attribute__((unused))) @@ -29,8 +51,13 @@ my_off_t my_seek(File fd, my_off_t pos, int whence, whence, MyFlags)); DBUG_ASSERT(pos != MY_FILEPOS_ERROR); /* safety check */ - if (-1 != fd) - newpos=lseek(fd, pos, whence); + /* + Make sure we are using a valid file descriptor! + */ + DBUG_ASSERT(fd != -1); + + newpos= lseek(fd, pos, whence); + if (newpos == (os_off_t) -1) { my_errno=errno; diff --git a/mysys/my_write.c b/mysys/my_write.c index 4e8369480b3..ae8cb4ab02b 100644 --- a/mysys/my_write.c +++ b/mysys/my_write.c @@ -57,18 +57,24 @@ uint my_write(int Filedes, const byte *Buffer, uint Count, myf MyFlags) VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); continue; } - if (!writenbytes) + + if ((writenbytes == 0 || (int) writenbytes == -1)) { - /* We may come here on an interrupt or if the file quote is exeeded */ if (my_errno == EINTR) - continue; - if (!errors++) /* Retry once */ { - errno=EFBIG; /* Assume this is the error */ - continue; + DBUG_PRINT("debug", ("my_write() was interrupted and returned %d", + (int) writenbytes)); + continue; /* Interrupted */ + } + + if (!writenbytes && !errors++) /* Retry once */ + { + /* We may come here if the file quota is exeeded */ + errno=EFBIG; /* Assume this is the error */ + continue; } } - else if ((uint) writenbytes != (uint) -1) + else continue; /* Retry */ #endif if (MyFlags & (MY_NABP | MY_FNABP)) diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index dcb41837d96..c55cc32b47d 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -15,8 +15,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* To avoid problems with alarms in debug code, we disable DBUG here */ -#undef DBUG_OFF -#define DBUG_OFF +#define FORCE_DBUG_OFF #include <my_global.h> #if defined(THREAD) && !defined(DONT_USE_THR_ALARM) diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c index 36cb83ae754..a2c42ee326c 100644 --- a/mysys/thr_lock.c +++ b/mysys/thr_lock.c @@ -72,7 +72,7 @@ multiple read locks. */ #if !defined(MAIN) && !defined(DBUG_OFF) && !defined(EXTRA_DEBUG) -#define DBUG_OFF +#define FORCE_DBUG_OFF #endif #include "mysys_priv.h" diff --git a/netware/BUILD/compile-AUTOTOOLS b/netware/BUILD/compile-AUTOTOOLS index 20e506aa683..c93fb1b1b28 100755 --- a/netware/BUILD/compile-AUTOTOOLS +++ b/netware/BUILD/compile-AUTOTOOLS @@ -5,8 +5,11 @@ # stop on errors set -e +sed -e "s/^DIST_COMMON/#DIST_COMMON/g" storage/ndb/Makefile.am > storage/ndb/Makefile.am.$$ +mv storage/ndb/Makefile.am.$$ storage/ndb/Makefile.am -for package in . ./storage/innobase +# for package in . ./storage/innobase +for package in . do (cd $package rm -rf config.cache autom4te.cache @@ -14,6 +17,7 @@ do autoheader libtoolize --force aclocal +# automake --verbose --add-missing --force-missing automake --add-missing --force-missing autoconf) done diff --git a/netware/BUILD/compile-netware-END b/netware/BUILD/compile-netware-END index c5c08cea908..6c531ab5c7c 100755 --- a/netware/BUILD/compile-netware-END +++ b/netware/BUILD/compile-netware-END @@ -15,11 +15,16 @@ if test -e "Makefile"; then make -k clean; fi rm -f */.deps/*.P rm -rf Makefile.in.bk -# Metrowerks enviornment +# Setup Metrowerks environment . $path/mwenv -# run auto tools -. $path/compile-AUTOTOOLS +# Temporary hack to allow building from source dist +if [ ! "$USER"=pushbuild ] +then + # Run autotools(use BUILD/autorun.sh) + echo "Running autotools again(BUILD/autorun.sh)" + . BUILD/autorun.sh +fi # configure ./configure $base_configs $extra_configs diff --git a/netware/BUILD/compile-netware-START b/netware/BUILD/compile-netware-START index 95b222994d3..8f828f34bd1 100755 --- a/netware/BUILD/compile-netware-START +++ b/netware/BUILD/compile-netware-START @@ -24,5 +24,4 @@ base_configs=" \ --prefix=N:/mysql \ --without-mysqlmanager \ --without-man \ - --without-csv-storage-engine \ " diff --git a/netware/BUILD/compile-netware-max b/netware/BUILD/compile-netware-max index ec737d4615c..d8278a4e915 100644..100755 --- a/netware/BUILD/compile-netware-max +++ b/netware/BUILD/compile-netware-max @@ -15,7 +15,7 @@ suffix="max" extra_configs=" \ --with-innodb \ --with-embedded-server \ - --with-openssl \ + --with-ssl \ " . $path/compile-netware-END diff --git a/netware/BUILD/compile-netware-max-debug b/netware/BUILD/compile-netware-max-debug index ea3553ae6e1..de1b5dd17cc 100644..100755 --- a/netware/BUILD/compile-netware-max-debug +++ b/netware/BUILD/compile-netware-max-debug @@ -15,7 +15,7 @@ extra_configs=" \ --with-innodb \ --with-debug=full \ --with-embedded-server \ - --with-openssl \ + --with-ssl \ " . $path/compile-netware-END diff --git a/netware/BUILD/compile-netware-src b/netware/BUILD/compile-netware-src index f4e8a53ffea..f4e8a53ffea 100644..100755 --- a/netware/BUILD/compile-netware-src +++ b/netware/BUILD/compile-netware-src diff --git a/netware/BUILD/mwenv b/netware/BUILD/mwenv index d8d53293b2c..44497c48917 100755 --- a/netware/BUILD/mwenv +++ b/netware/BUILD/mwenv @@ -8,7 +8,7 @@ fi # The base path(in wineformat) where compilers, includes and # libraries are installed -if test -z $MYDEV +if test -z "$MYDEV" then # the default is "F:/mydev" export MYDEV="F:/mydev" @@ -26,8 +26,17 @@ WINE_BUILD_DIR=`echo "$BUILD_DIR" | sed 's_'$base_unix_part'/__'` WINE_BUILD_DIR="$base/$WINE_BUILD_DIR" echo "WINE_BUILD_DIR: $WINE_BUILD_DIR" -export MWCNWx86Includes="$MYDEV/libc/include;$MYDEV/fs64/headers;$MYDEV/zlib-1.2.3;$WINE_BUILD_DIR/include;$MYDEV" -export MWNWx86Libraries="$MYDEV/libc/imports;$MYDEV/mw/lib;$MYDEV/fs64/imports;$MYDEV/zlib-1.2.3;$MYDEV/openssl;$WINE_BUILD_DIR/netware/BUILD" +# Look for libc, MySQL 5.1.x uses libc-2006 by default +libc_dir="$MYDEV/libc-2006" +if [ ! -d `winepath $libc_dir` ] +then + # The libcdir didn't exist, set default + libc_dir="$MYDEV/libc" +fi +echo "Using libc in $libc_dir"; + +export MWCNWx86Includes="$libc_dir/include;$MYDEV/fs64/headers;$MYDEV/zlib-1.2.3;$WINE_BUILD_DIR/include;$MYDEV" +export MWNWx86Libraries="$libc_dir/imports;$MYDEV/mw/lib;$MYDEV/fs64/imports;$MYDEV/zlib-1.2.3;$MYDEV/openssl;$WINE_BUILD_DIR/netware/BUILD" export MWNWx86LibraryFiles="libcpre.o;libc.imp;netware.imp;mwcrtl.lib;mwcpp.lib;libz.a;neb.imp;zPublics.imp;knetware.imp" export WINEPATH="$MYDEV/mw/bin" @@ -46,3 +55,21 @@ export LD='mwldnlm' export LDFLAGS='-entry _LibCPrelude -exit _LibCPostlude -map -flags pseudopreemption' export RANLIB=: export STRIP=: + +# +# Check that TERM has been set to avoid problem "Error opening +# terminal: unknown" when the script is executed using non interactive ssh +# +if test -z "$TERM" -o "$TERM"=dumb +then + export TERM=linux +fi + +# Temporary hack to allow building from source dist +if [ "$USER"=pushbuild ] +then + export ARFLAGS=$AR_FLAGS +fi + +# Print all env. variables +export diff --git a/netware/BUILD/mwldnlm b/netware/BUILD/mwldnlm index cc8c9e63c6e..b1822827b59 100755 --- a/netware/BUILD/mwldnlm +++ b/netware/BUILD/mwldnlm @@ -3,6 +3,13 @@ # stop on errors set -e +# If libtool passes "x" as the first argument to this script +# it's an indication that libtool is trying to unpack .la's +# so they can be added to a new library +# This step does not work on Netware and we avoid it by +# replacing the .la library with the path to the .a library +# in Makefile.in + args=" $*" # NOTE: Option 'pipefail' is not standard sh diff --git a/netware/BUILD/nwbootstrap b/netware/BUILD/nwbootstrap index 22e1569e7ca..563d316ea56 100755 --- a/netware/BUILD/nwbootstrap +++ b/netware/BUILD/nwbootstrap @@ -151,17 +151,18 @@ echo "making files writable..." cd $target_dir chmod -R u+rw,g+rw . -# edit the mvenv file -echo "updating the mwenv environment file..." +## # edit the mvenv file +## echo "updating the mwenv environment file..." mwenv="./netware/BUILD/mwenv" -mv -f $mwenv $mwenv.org -sed -e "s;WINE_BUILD_DIR;$wine_build_dir;g" \ - -e "s;BUILD_DIR;$build_dir;g" \ - -e "s;VERSION;$version;g" $mwenv.org > $mwenv -chmod +rwx $mwenv +## mv -f $mwenv $mwenv.org +## sed -e "s;WINE_BUILD_DIR;$wine_build_dir;g" \ +## -e "s;BUILD_DIR;$build_dir;g" \ +## -e "s;VERSION;$version;g" $mwenv.org > $mwenv +## chmod +rwx $mwenv PWD=`pwd` -SRC_DIR=`grep "^export MYDEV=" $mwenv | cut -d'=' -f2 | \ +# This line will catch the default value only, let's hope it is correct +SRC_DIR=`grep "^ *export MYDEV=" $mwenv | cut -d'=' -f2 | \ sed -e 's;";;g' -e "s;^;echo ;g" -e "s;$;/\`basename $PWD\`;g" | /bin/sh` diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh index c254a77e805..9302745ceee 100644 --- a/scripts/make_binary_distribution.sh +++ b/scripts/make_binary_distribution.sh @@ -253,8 +253,8 @@ $CP mysql-test/t/*.test $BASE/mysql-test/t $CP mysql-test/t/*.imtest mysql-test/t/*.disabled $BASE/mysql-test/t $CP mysql-test/t/*.opt mysql-test/t/*.slave-mi $BASE/mysql-test/t $CP mysql-test/t/*.sh mysql-test/t/*.sql $BASE/mysql-test/t -$CP mysql-test/r/*.result mysql-test/r/*.require \ - $BASE/mysql-test/r +$CP mysql-test/r/*.result $BASE/mysql-test/r +$CP mysql-test/r/*.require $BASE/mysql-test/r $CP mysql-test/extra/binlog_tests/*.test $BASE/mysql-test/extra/binlog_tests $CP mysql-test/extra/rpl_tests/*.test $BASE/mysql-test/extra/rpl_tests @@ -326,14 +326,16 @@ fi # NDB Cluster if [ x$NDBCLUSTER = x1 ]; then - ( cd storage/ndb ; @MAKE@ DESTDIR=$BASE/ndb-stage install ) - ( cd mysql-test/ndb ; @MAKE@ DESTDIR=$BASE/ndb-stage install ) + ( cd storage/ndb ; @MAKE@ DESTDIR=$BASE/ndb-stage install ) + ( cd mysql-test ; @MAKE@ DESTDIR=$BASE/ndb-stage install ) $CP $BASE/ndb-stage@bindir@/* $BASE/bin/. $CP $BASE/ndb-stage@libexecdir@/* $BASE/bin/. $CP $BASE/ndb-stage@pkglibdir@/* $BASE/lib/. test -d $BASE/include/storage || mkdir $BASE/include/storage $CP -r $BASE/ndb-stage@pkgincludedir@/storage/ndb $BASE/include/storage/ $CP -r $BASE/ndb-stage@prefix@/mysql-test/ndb $BASE/mysql-test/. || exit 1 + $CP -r $BASE/ndb-stage@prefix@/mysql-test/std_data/ndb_backup50 $BASE/mysql-test/std_data/. || exit 1 + $CP -r $BASE/ndb-stage@prefix@/mysql-test/std_data/ndb_backup51 $BASE/mysql-test/std_data/. || exit 1 rm -rf $BASE/ndb-stage fi diff --git a/scripts/make_win_bin_dist b/scripts/make_win_bin_dist index cebcccb56f4..b200e5428be 100755 --- a/scripts/make_win_bin_dist +++ b/scripts/make_win_bin_dist @@ -1,41 +1,227 @@ -#! /bin/sh - -NOINST_NAME=$1 - -mkdir $NOINST_NAME -mkdir $NOINST_NAME/bin -cp client/release/*.exe $NOINST_NAME/bin/ -cp extra/release/*.exe $NOINST_NAME/bin/ -mv $NOINST_NAME/bin/comp_err.exe $NOINST_NAME/bin/comp-err.exe -cp storage/myisam/release/*.exe $NOINST_NAME/bin/ -cp server-tools/instance-manager/release/*.exe $NOINST_NAME/bin/ -cp tests/release/*.exe $NOINST_NAME/bin/ -cp libmysql/release/*.exe $NOINST_NAME/bin/ -cp libmysql/release/libmysql.dll $NOINST_NAME/bin/ - -cp sql/release/mysqld.exe $NOINST_NAME/bin/mysqld.exe -cp sql/debug/mysqld.exe $NOINST_NAME/bin/mysqld-debug.exe -# For Pro/Classic builds, do this instead: -# cp sql/release/mysqld.exe $NOINST_NAME/bin/mysqld-nt.exe -# cp sql/debug/mysqld.exe $NOINST_NAME/bin/mysqld-debug.exe - -cp COPYING EXCEPTIONS-CLIENT $NOINST_NAME/ -cp -dpR win/data $NOINST_NAME/data -mkdir $NOINST_NAME/Docs -cp Docs/INSTALL-BINARY Docs/manual.chm ChangeLog COPYING $NOINST_NAME/Docs/ - -# These will be filled in when we enable embedded. -mkdir -p $NOINST_NAME/Embedded/DLL/debug $NOINST_NAME/Embedded/DLL/release $NOINST_NAME/Embedded/static/release - -mkdir -p $NOINST_NAME/examples/libmysqltest/debug $NOINST_NAME/examples/libmysqltest/release -cp libmysql/mytest.c libmysql/myTest.vcproj libmysql/release/myTest.exe $NOINST_NAME/examples/libmysqltest/ -cp libmysql/debug/myTest.exe $NOINST_NAME/examples/libmysqltest/debug/ -cp libmysql/release/myTest.exe $NOINST_NAME/examples/libmysqltest/release/ - -mkdir -p $NOINST_NAME/examples/tests -cp tests/*.res tests/*.tst tests/*.pl tests/*.c $NOINST_NAME/examples/tests/ - -mkdir -p $NOINST_NAME/include +#!/bin/sh + +# Exit if failing to copy, we want exact specifications, not +# just "what happen to be built". +set -e + +# ---------------------------------------------------------------------- +# Read first argument that is the base name of the resulting TAR file. +# See usage() function below for a description on the arguments. +# +# NOTE: We will read the rest of the command line later on. +# NOTE: Pattern matching with "{..,..}" can't be used, not portable. +# ---------------------------------------------------------------------- + +# FIXME FIXME "debug", own build or handled here? +# FIXME FIXME add way to copy from other builds executables + +usage() +{ + echo <<EOF +Usage: make_win_bin_dist [ options ] package-base-name [ copy-defs... ] + +This is a script to run from the top of a source tree built on Windows. +The "package-base-name" argument should be something like + + mysql-noinstall-5.0.25-win32 (or winx64) + +and will be the name of the directory of the unpacked ZIP (stripping +away the "noinstall" part of the ZIP file name if any) and the base +for the resulting package name. + +Options are + + --embedded Pack the embedded server and give error if not built. + The default is to pack it if it is built. + + --no-embedded Don't pack the embedded server even if built + + --debug Pack the debug binaries and give error if not built. + + --no-debug Don't pack the debug binaries even if built + + --only-debug The target for this build was "Debug", and we just + want to replace the normal binaries with debug + versions, i.e. no separate "debug" directories. + + --exe-suffix=SUF Add a suffix to the "mysqld" binary. + +As you might want to include files of directories from other builds +(like a "mysqld-max.exe" server), you can instruct this script do copy +them in for you. This is the "copy-def" arguments, and they are of the +form + + relative-dest-name=source-name ..... + +i.e. can be something like + + bin/mysqld-max.exe=../my-max-build/sql/release/mysqld.exe + +If you specify a directory the whole directory will be copied. + +EOF + exit 1 +} + +# ---------------------------------------------------------------------- +# We need to be at the top of a source tree, check that we are +# ---------------------------------------------------------------------- + +if [ ! -d "sql" ] ; then + echo "You need to run this script from inside the source tree" + usage +fi + +# ---------------------------------------------------------------------- +# Actual argument processing, first part +# ---------------------------------------------------------------------- + +NOINST_NAME="" +TARGET="release" +PACK_EMBEDDED="" # Could be "no", "yes" or empty +PACK_DEBUG="" # Could be "no", "yes" or empty +EXE_SUFFIX="" + +for arg do + shift + case "$arg" in + --embedded) PACK_EMBEDDED="yes" ;; + --no-embedded) PACK_EMBEDDED="no" ;; + --debug) PACK_DEBUG="yes" ;; + --no-debug) PACK_DEBUG="no" ;; + --only-debug) TARGET="debug" ; PACK_DEBUG="no" ;; + --exe-suffix=*) EXE_SUFFIX=`echo "$arg" | sed -e "s,--exe-suffix=,,"` ;; + -*) + echo "Unknown argument '$arg'" + usage + ;; + *) + NOINST_NAME="$arg" + break + esac +done + +if [ x"$NOINST_NAME" = x"" ] ; then + echo "No base package name given" + usage +fi +DESTDIR=`echo $NOINST_NAME | sed 's/-noinstall-/-/'` + +if [ -e $DESTDIR ] ; then + echo "Please remove the old $DESTDIR before running this script" + usage +fi + +# ---------------------------------------------------------------------- +# Copy executables, and client DLL (FIXME why?) +# ---------------------------------------------------------------------- + +trap 'echo "Clearning up and exiting..." ; rm -fr $DESTDIR; exit 1' ERR + +mkdir $DESTDIR +mkdir $DESTDIR/bin +cp client/$TARGET/*.exe $DESTDIR/bin/ +cp extra/$TARGET/*.exe $DESTDIR/bin/ +cp storage/myisam/$TARGET/*.exe $DESTDIR/bin/ +cp server-tools/instance-manager/$TARGET/*.exe $DESTDIR/bin/ +cp tests/$TARGET/*.exe $DESTDIR/bin/ +cp libmysql/$TARGET/*.exe $DESTDIR/bin/ +cp libmysql/$TARGET/libmysql.dll $DESTDIR/bin/ + +# FIXME really needed?! +mv $DESTDIR/bin/comp_err.exe $DESTDIR/bin/comp-err.exe + +cp sql/$TARGET/mysqld.exe $DESTDIR/bin/mysqld$EXE_SUFFIX.exe + +if [ x"$PACK_DEBUG" = "" -a -f "sql/debug/mysqld.exe" -o \ + x"$PACK_DEBUG" = "yes" ] ; then + cp sql/debug/mysqld.exe $DESTDIR/bin/mysqld-debug.exe + cp sql/debug/mysqld.pdb $DESTDIR/bin/mysqld-debug.pdb + cp sql/debug/mysqld.map $DESTDIR/bin/mysqld-debug.map +fi + +# ---------------------------------------------------------------------- +# Copy data directory, readme files etc +# ---------------------------------------------------------------------- + +# FIXME is there ever a data directory to copy? +if [ -d win/data ] ; then + cp -pR win/data $DESTDIR/data +fi + +# FIXME maybe a flag to define "release build", or do the +# check from the calling script that all these are there, +# and with the correct content. + +mkdir $DESTDIR/Docs +cp Docs/INSTALL-BINARY $DESTDIR/Docs/ +cp Docs/manual.chm $DESTDIR/Docs/ || /bin/true +cp ChangeLog $DESTDIR/Docs/ || /bin/true +cp support-files/my-*.ini $DESTDIR/ + +if [ -f COPYING ] ; then + cp COPYING EXCEPTIONS-CLIENT $DESTDIR/ + cp COPYING $DESTDIR/Docs/ +fi + +# ---------------------------------------------------------------------- +# These will be filled in when we enable embedded. Note that if no +# argument is given, it is copied if exists, else a check is done. +# ---------------------------------------------------------------------- + +copy_embedded() +{ + mkdir -p $DESTDIR/Embedded/DLL/release \ + $DESTDIR/Embedded/static/release \ + $DESTDIR/include + cp libmysqld/libmysqld.def $DESTDIR/include/ + cp libmysqld/$TARGET/mysqlserver.lib $DESTDIR/Embedded/static/release/ + cp libmysqld/$TARGET/libmysqld.dll $DESTDIR/Embedded/DLL/release/ + cp libmysqld/$TARGET/libmysqld.exp $DESTDIR/Embedded/DLL/release/ + cp libmysqld/$TARGET/libmysqld.lib $DESTDIR/Embedded/DLL/release/ + + if [ x"$PACK_DEBUG" = "" -a -f "libmysqld/debug/libmysqld.lib" -o \ + x"$PACK_DEBUG" = "yes" ] ; then + mkdir -p $DESTDIR/Embedded/DLL/debug + cp libmysqld/debug/libmysqld.dll $DESTDIR/Embedded/DLL/debug/ + cp libmysqld/debug/libmysqld.exp $DESTDIR/Embedded/DLL/debug/ + cp libmysqld/debug/libmysqld.lib $DESTDIR/Embedded/DLL/debug/ + fi +} + +if [ x"$PACK_EMBEDDED" = "" -a \ + -f "libmysqld/$TARGET/mysqlserver.lib" -a \ + -f "libmysqld/$TARGET/libmysqld.lib" -o \ + x"$PACK_EMBEDDED" = "yes" ] ; then + copy_embedded +fi + +# ---------------------------------------------------------------------- +# FIXME test stuff that is useless garbage? +# ---------------------------------------------------------------------- + +mkdir -p $DESTDIR/examples/libmysqltest/release +cp libmysql/mytest.c libmysql/myTest.vcproj libmysql/$TARGET/myTest.exe \ + $DESTDIR/examples/libmysqltest/ +cp libmysql/$TARGET/myTest.exe $DESTDIR/examples/libmysqltest/release/ + +if [ x"$PACK_DEBUG" = "" -a -f "libmysql/debug/myTest.exe" -o \ + x"$PACK_DEBUG" = "yes" ] ; then + mkdir -p $DESTDIR/examples/libmysqltest/debug + cp libmysql/debug/myTest.exe $DESTDIR/examples/libmysqltest/debug/ +fi + +mkdir -p $DESTDIR/examples/tests +cp tests/*.res tests/*.tst tests/*.pl tests/*.c $DESTDIR/examples/tests/ + +mkdir -p $DESTDIR/examples/udf_example +cp sql/udf_example.def sql/udf_example.vcproj sql/udf_example.c $DESTDIR/examples/udf_example/ + +# ---------------------------------------------------------------------- +# FIXME why not copy it all in "include"?! +# ---------------------------------------------------------------------- + +mkdir -p $DESTDIR/include cp include/conf*.h \ include/mysql*.h \ include/errmsg.h \ @@ -48,69 +234,122 @@ cp include/conf*.h \ include/m_string.h \ include/m_ctype.h \ include/my_global.h \ - include/typelib.h $NOINST_NAME/include/ -cp libmysql/libmysql.def $NOINST_NAME/include/ -cp libmysqld/libmysqld.def $NOINST_NAME/include/ - -mkdir -p $NOINST_NAME/lib/debug $NOINST_NAME/lib/opt -cp libmysql/debug/libmysql.dll \ - libmysql/debug/libmysql.lib \ - client/debug/mysqlclient.lib \ - mysys/debug/mysys.lib \ - regex/debug/regex.lib \ - strings/debug/strings.lib \ - zlib/debug/zlib.lib $NOINST_NAME/lib/debug/ -cp libmysql/release/libmysql.dll \ - libmysql/release/libmysql.lib \ - client/release/mysqlclient.lib \ - regex/release/regex.lib \ - strings/release/strings.lib \ - zlib/release/zlib.lib $NOINST_NAME/lib/opt/ -cp mysys/release/mysys.lib $NOINST_NAME/lib/opt/mysys_tls.lib - -cp support-files/my-*.ini $NOINST_NAME/ - -mkdir -p $NOINST_NAME/mysql-test/include $NOINST_NAME/mysql-test/lib \ - $NOINST_NAME/mysql-test/r $NOINST_NAME/mysql-test/std_data \ - $NOINST_NAME/mysql-test/t $NOINST_NAME/mysql-test/extra -cp mysql-test/mysql-test-run.pl $NOINST_NAME/mysql-test/ -cp mysql-test/README $NOINST_NAME/mysql-test/ -cp mysql-test/install_test_db.sh $NOINST_NAME/mysql-test/install_test_db -cp mysql-test/include/*.inc $NOINST_NAME/mysql-test/include/ -cp mysql-test/lib/*.pl $NOINST_NAME/mysql-test/lib/ -cp mysql-test/lib/*.sql $NOINST_NAME/mysql-test/lib/ -cp mysql-test/r/*.require $NOINST_NAME/mysql-test/r/ + include/typelib.h $DESTDIR/include/ +cp libmysql/libmysql.def $DESTDIR/include/ + +# ---------------------------------------------------------------------- +# Client libraries, and other libraries +# FIXME why "libmysql.dll" installed both in "bin" and "lib/opt"? +# ---------------------------------------------------------------------- + +mkdir -p $DESTDIR/lib/opt +cp libmysql/$TARGET/libmysql.dll \ + libmysql/$TARGET/libmysql.lib \ + client/$TARGET/mysqlclient.lib \ + regex/$TARGET/regex.lib \ + strings/$TARGET/strings.lib \ + zlib/$TARGET/zlib.lib $DESTDIR/lib/opt/ + +if [ x"$PACK_DEBUG" = "" -a -f "libmysql/debug/libmysql.lib" -o \ + x"$PACK_DEBUG" = "yes" ] ; then + mkdir -p $DESTDIR/lib/debug + cp libmysql/debug/libmysql.dll \ + libmysql/debug/libmysql.lib \ + client/debug/mysqlclient.lib \ + mysys/debug/mysys.lib \ + regex/debug/regex.lib \ + strings/debug/strings.lib \ + zlib/debug/zlib.lib $DESTDIR/lib/debug/ +fi + +# FIXME sort this out... +cp mysys/$TARGET/mysys.lib $DESTDIR/lib/opt/mysys_tls.lib + +# ---------------------------------------------------------------------- +# Copy the test directory +# ---------------------------------------------------------------------- + +mkdir -p $DESTDIR/mysql-test/include $DESTDIR/mysql-test/lib \ + $DESTDIR/mysql-test/r $DESTDIR/mysql-test/std_data \ + $DESTDIR/mysql-test/t +cp mysql-test/mysql-test-run.pl $DESTDIR/mysql-test/ +cp mysql-test/README $DESTDIR/mysql-test/ +cp mysql-test/install_test_db.sh $DESTDIR/mysql-test/install_test_db +cp mysql-test/include/*.inc $DESTDIR/mysql-test/include/ +cp mysql-test/lib/*.pl $DESTDIR/mysql-test/lib/ +cp mysql-test/lib/*.sql $DESTDIR/mysql-test/lib/ +cp mysql-test/r/*.require $DESTDIR/mysql-test/r/ # Need this trick, or we get "argument list too long". -ABS_DST=`pwd`/$NOINST_NAME +ABS_DST=`pwd`/$DESTDIR (cd mysql-test/r/ && cp *.result $ABS_DST/mysql-test/r/) -cp mysql-test/std_data/* $NOINST_NAME/mysql-test/std_data/ -cp mysql-test/t/*.disabled $NOINST_NAME/mysql-test/t/ -cp mysql-test/t/*.opt $NOINST_NAME/mysql-test/t/ -cp mysql-test/t/*.sh $NOINST_NAME/mysql-test/t/ -cp mysql-test/t/*.slave-mi $NOINST_NAME/mysql-test/t/ -cp mysql-test/t/*.sql $NOINST_NAME/mysql-test/t/ -cp mysql-test/t/*.def $NOINST_NAME/mysql-test/t/ +cp mysql-test/std_data/Moscow_leap $DESTDIR/mysql-test/std_data/ +cp mysql-test/std_data/des_key_file $DESTDIR/mysql-test/std_data/ +cp mysql-test/std_data/*.000001 $DESTDIR/mysql-test/std_data/ +cp mysql-test/std_data/*.cnf $DESTDIR/mysql-test/std_data/ +cp mysql-test/std_data/*.dat $DESTDIR/mysql-test/std_data/ +cp mysql-test/std_data/*.frm $DESTDIR/mysql-test/std_data/ +cp mysql-test/std_data/*.pem $DESTDIR/mysql-test/std_data/ +cp mysql-test/t/*.opt $DESTDIR/mysql-test/t/ +cp mysql-test/t/*.sh $DESTDIR/mysql-test/t/ +cp mysql-test/t/*.slave-mi $DESTDIR/mysql-test/t/ +cp mysql-test/t/*.sql $DESTDIR/mysql-test/t/ +cp mysql-test/t/*.def $DESTDIR/mysql-test/t/ (cd mysql-test/t/ && cp *.test $ABS_DST/mysql-test/t/) -cp -dpR mysql-test/extra/* $NOINST_NAME/mysql-test/extra/ -# This copies in the unsubstituted scripts (containing @VAR@), but that seems -# rather better than substituting random Unix paths and architecture names -# from the Unix bootstrap host. Not sure what the point is of including these -# shell scripts in the Windows packaging in any case. -mkdir -p $NOINST_NAME/scripts +# Note that this will not copy "extra" if a soft link +if [ -d mysql-test/extra ] ; then + mkdir -p $DESTDIR/mysql-test/extra + cp -pR mysql-test/extra/* $DESTDIR/mysql-test/extra/ +fi + +# ---------------------------------------------------------------------- +# Copy what could be usable in the "scripts" directory. Currently +# only SQL files, others are bourne shell scripts or Perl scripts +# not really usable on Windows. +# +# But to be nice to the few Cygwin users we might have in 5.0 we +# continue to copy the stuff, but don't include it include it in +# the WiX install. +# ---------------------------------------------------------------------- + +mkdir -p $DESTDIR/scripts + +# Uncomment and remove the for loop in 5.1 +#cp scripts/*.sql $DESTDIR/scripts/ + for i in `cd scripts && ls`; do \ if echo $i | grep -q '\.sh'; then \ - cp scripts/$i $NOINST_NAME/scripts/`echo $i | sed -e 's/\.sh$//'`; \ - else if [ $i = Makefile.am -o $i = Makefile.in -o -e scripts/$i.sh ] ; then \ + cp scripts/$i $DESTDIR/scripts/`echo $i | sed -e 's/\.sh$//'`; \ + elif [ $i = Makefile.am -o $i = Makefile.in -o -e scripts/$i.sh ] ; then \ : ; \ else \ - cp scripts/$i $NOINST_NAME/scripts/$i; \ - fi; fi; \ + cp scripts/$i $DESTDIR/scripts/$i; \ + fi; \ +done + +cp -pR sql/share $DESTDIR/ + +# ---------------------------------------------------------------------- +# Copy other files specified on command line DEST=SOURCE +# ---------------------------------------------------------------------- + +for arg do + dst=`echo $arg | sed 's/=.*$//'` + src=`echo $arg | sed 's/^.*=//'` + + if [ x"$dst" = x"" -o x"$src" = x"" ] ; then + echo "Invalid specification of what to copy" + usage + fi + + mkdir -p `dirname $DESTDIR/$dst` + cp -pR "$src" $DESTDIR/$dst done -cp -dpR sql/share $NOINST_NAME/ -cp -dpR sql-bench $NOINST_NAME/ -rm -f $NOINST_NAME/sql-bench/*.sh $NOINST_NAME/sql-bench/Makefile* +# ---------------------------------------------------------------------- +# Finally creat the ZIP archive +# ---------------------------------------------------------------------- -zip -r $NOINST_NAME.zip $NOINST_NAME -rm -Rf $NOINST_NAME +rm -f $NOINST_NAME.zip +zip -r $NOINST_NAME.zip $DESTDIR +rm -Rf $DESTDIR diff --git a/server-tools/instance-manager/guardian.cc b/server-tools/instance-manager/guardian.cc index 68d89a4b375..03bfadd8571 100644 --- a/server-tools/instance-manager/guardian.cc +++ b/server-tools/instance-manager/guardian.cc @@ -74,7 +74,7 @@ Guardian_thread::Guardian_thread(Thread_registry &thread_registry_arg, uint monitoring_interval_arg) : Guardian_thread_args(thread_registry_arg, instance_map_arg, monitoring_interval_arg), - thread_info(pthread_self()), guarded_instances(0) + thread_info(pthread_self(), TRUE), guarded_instances(0) { pthread_mutex_init(&LOCK_guardian, 0); pthread_cond_init(&COND_guardian, 0); @@ -95,11 +95,11 @@ Guardian_thread::~Guardian_thread() } -void Guardian_thread::request_shutdown(bool stop_instances_arg) +void Guardian_thread::request_shutdown() { pthread_mutex_lock(&LOCK_guardian); /* stop instances or just clean up Guardian repository */ - stop_instances(stop_instances_arg); + stop_instances(); shutdown_requested= TRUE; pthread_mutex_unlock(&LOCK_guardian); } @@ -154,11 +154,11 @@ void Guardian_thread::process_instance(Instance *instance, { /* Pid file not created yet, don't go to STARTED state yet */ } - else + else if (current_node->state != STARTED) { /* clear status fields */ - log_info("guardian: instance %s is running, set state to STARTED", - instance->options.instance_name); + log_info("guardian: instance '%s' is running, set state to STARTED.", + (const char *) instance->options.instance_name.str); current_node->restart_counter= 0; current_node->crash_moment= 0; current_node->state= STARTED; @@ -168,8 +168,8 @@ void Guardian_thread::process_instance(Instance *instance, { switch (current_node->state) { case NOT_STARTED: - log_info("guardian: starting instance %s", - instance->options.instance_name); + log_info("guardian: starting instance '%s'...", + (const char *) instance->options.instance_name.str); /* NOTE, set state to STARTING _before_ start() is called */ current_node->state= STARTING; @@ -193,8 +193,8 @@ void Guardian_thread::process_instance(Instance *instance, if (instance->is_crashed()) { instance->start(); - log_info("guardian: starting instance %s", - instance->options.instance_name); + log_info("guardian: starting instance '%s'...", + (const char *) instance->options.instance_name.str); } } else @@ -211,14 +211,14 @@ void Guardian_thread::process_instance(Instance *instance, instance->start(); current_node->last_checked= current_time; current_node->restart_counter++; - log_info("guardian: restarting instance %s", - instance->options.instance_name); + log_info("guardian: restarting instance '%s'...", + (const char *) instance->options.instance_name.str); } } else { log_info("guardian: cannot start instance %s. Abandoning attempts " - "to (re)start it", instance->options.instance_name); + "to (re)start it", instance->options.instance_name.str); current_node->state= CRASHED_AND_ABANDONED; } } @@ -250,6 +250,8 @@ void Guardian_thread::run() LIST *node; struct timespec timeout; + log_info("Guardian: started."); + thread_registry.register_thread(&thread_info); my_thread_init(); @@ -277,12 +279,16 @@ void Guardian_thread::run() &LOCK_guardian, &timeout); } + log_info("Guardian: stopped."); + stopped= TRUE; pthread_mutex_unlock(&LOCK_guardian); /* now, when the Guardian is stopped we can stop the IM */ thread_registry.unregister_thread(&thread_info); thread_registry.request_shutdown(); my_thread_end(); + + log_info("Guardian: finished."); } @@ -414,12 +420,11 @@ int Guardian_thread::stop_guard(Instance *instance) SYNOPSYS stop_instances() - stop_instances_arg whether we should stop instances at shutdown DESCRIPTION Loops through the guarded_instances list and prepares them for shutdown. - If stop_instances was requested, we need to issue a stop command and change - the state accordingly. Otherwise we simply delete an entry. + For each instance we issue a stop command and change the state + accordingly. NOTE Guardian object should be locked by the calling function. @@ -429,42 +434,29 @@ int Guardian_thread::stop_guard(Instance *instance) 1 - error occured */ -int Guardian_thread::stop_instances(bool stop_instances_arg) +int Guardian_thread::stop_instances() { LIST *node; node= guarded_instances; while (node != NULL) { - if (!stop_instances_arg) + GUARD_NODE *current_node= (GUARD_NODE *) node->data; + /* + If instance is running or was running (and now probably hanging), + request stop. + */ + if (current_node->instance->is_running() || + (current_node->state == STARTED)) { - /* just forget about an instance */ - guarded_instances= list_delete(guarded_instances, node); - /* - This should still work fine, as we have only removed the - node from the list. The pointer to the next one is still valid - */ - node= node->next; + current_node->state= STOPPING; + current_node->last_checked= time(NULL); } else - { - GUARD_NODE *current_node= (GUARD_NODE *) node->data; - /* - If instance is running or was running (and now probably hanging), - request stop. - */ - if (current_node->instance->is_running() || - (current_node->state == STARTED)) - { - current_node->state= STOPPING; - current_node->last_checked= time(NULL); - } - else - /* otherwise remove it from the list */ - guarded_instances= list_delete(guarded_instances, node); - /* But try to kill it anyway. Just in case */ - current_node->instance->kill_instance(SIGTERM); - node= node->next; - } + /* otherwise remove it from the list */ + guarded_instances= list_delete(guarded_instances, node); + /* But try to kill it anyway. Just in case */ + current_node->instance->kill_instance(SIGTERM); + node= node->next; } return 0; } diff --git a/server-tools/instance-manager/guardian.h b/server-tools/instance-manager/guardian.h index 6d3a2b222d7..27ca155fd67 100644 --- a/server-tools/instance-manager/guardian.h +++ b/server-tools/instance-manager/guardian.h @@ -91,7 +91,7 @@ public: /* Initialize or refresh the list of guarded instances */ int init(); /* Request guardian shutdown. Stop instances if needed */ - void request_shutdown(bool stop_instances); + void request_shutdown(); /* Start instance protection */ int guard(Instance *instance, bool nolock= FALSE); /* Stop instance protection */ @@ -123,7 +123,7 @@ public: private: /* Prepares Guardian shutdown. Stops instances is needed */ - int stop_instances(bool stop_instances_arg); + int stop_instances(); /* check instance state and act accordingly */ void process_instance(Instance *instance, GUARD_NODE *current_node, LIST **guarded_instances, LIST *elem); diff --git a/server-tools/instance-manager/instance.cc b/server-tools/instance-manager/instance.cc index dfe26397414..3927363a3e5 100644 --- a/server-tools/instance-manager/instance.cc +++ b/server-tools/instance-manager/instance.cc @@ -34,6 +34,7 @@ #include "mysql_manager_error.h" #include "portability.h" #include "priv.h" +#include "thread_registry.h" const LEX_STRING @@ -44,7 +45,8 @@ static const int INSTANCE_NAME_PREFIX_LEN= Instance::DFLT_INSTANCE_NAME.length; static void start_and_monitor_instance(Instance_options *old_instance_options, - Instance_map *instance_map); + Instance_map *instance_map, + Thread_registry *thread_registry); #ifndef __WIN__ typedef pid_t My_process_info; @@ -63,7 +65,8 @@ pthread_handler_t proxy(void *arg) { Instance *instance= (Instance *) arg; start_and_monitor_instance(&instance->options, - instance->get_map()); + instance->get_map(), + &instance->thread_registry); return 0; } @@ -99,6 +102,7 @@ static int wait_process(My_process_info *pi) thread, but we don't know this one). Or we could use waitpid(), but couldn't use wait(), because it could return in any wait() in the program. */ + if (linuxthreads) wait(NULL); /* LinuxThreads were detected */ else @@ -165,8 +169,8 @@ static int start_process(Instance_options *instance_options, /* exec never returns */ exit(1); case -1: - log_info("cannot create a new process to start instance %s", - instance_options->instance_name); + log_info("cannot create a new process to start instance '%s'.", + (const char *) instance_options->instance_name.str); return 1; } return 0; @@ -239,11 +243,28 @@ static int start_process(Instance_options *instance_options, */ static void start_and_monitor_instance(Instance_options *old_instance_options, - Instance_map *instance_map) + Instance_map *instance_map, + Thread_registry *thread_registry) { Instance_name instance_name(&old_instance_options->instance_name); Instance *current_instance; My_process_info process_info; + Thread_info thread_info(pthread_self(), FALSE); + + log_info("Monitoring thread (instance: '%s'): started.", + (const char *) instance_name.get_c_str()); + + if (!old_instance_options->nonguarded) + { + /* + Register thread in Thread_registry to wait for it to stop on shutdown + only if instance is nuarded. If instance is guarded, the thread will not + finish, because nonguarded instances are not stopped on shutdown. + */ + + thread_registry->register_thread(&thread_info); + my_thread_init(); + } /* Lock instance map to guarantee that no instances are deleted during @@ -256,7 +277,8 @@ static void start_and_monitor_instance(Instance_options *old_instance_options, are using is destroyed. (E.g. by "FLUSH INSTANCES") */ - log_info("starting instance %s", (const char *) instance_name.get_c_str()); + log_info("starting instance %s...", + (const char *) instance_name.get_c_str()); if (start_process(old_instance_options, &process_info)) { @@ -279,7 +301,14 @@ static void start_and_monitor_instance(Instance_options *old_instance_options, instance_map->unlock(); - return; + if (!old_instance_options->nonguarded) + { + thread_registry->unregister_thread(&thread_info); + my_thread_end(); + } + + log_info("Monitoring thread (instance: '%s'): finished.", + (const char *) instance_name.get_c_str()); } @@ -311,9 +340,9 @@ void Instance::remove_pid() int pid; if ((pid= options.get_pid()) != 0) /* check the pidfile */ if (options.unlink_pidfile()) /* remove stalled pidfile */ - log_error("cannot remove pidfile for instance %i, this might be \ - since IM lacks permmissions or hasn't found the pidifle", - options.instance_name); + log_error("cannot remove pidfile for instance '%s', this might be " + "since IM lacks permmissions or hasn't found the pidifle", + (const char *) options.instance_name.str); } @@ -342,10 +371,6 @@ int Instance::start() { remove_pid(); - /* - No need to monitor this thread in the Thread_registry, as all - instances are to be stopped during shutdown. - */ pthread_t proxy_thd_id; pthread_attr_t proxy_thd_attr; int rc; @@ -403,7 +428,8 @@ void Instance::set_crash_flag_n_wake_all() -Instance::Instance(): crashed(FALSE), configured(FALSE) +Instance::Instance(Thread_registry &thread_registry_arg): + crashed(FALSE), configured(FALSE), thread_registry(thread_registry_arg) { pthread_mutex_init(&LOCK_instance, 0); pthread_cond_init(&COND_instance_stopped, 0); @@ -467,9 +493,9 @@ bool Instance::is_running() We have successfully connected to the server using fake username/password. Write a warning to the logfile. */ - log_info("The Instance Manager was able to log into you server \ - with faked compiled-in password while checking server status. \ - Looks like something is wrong."); + log_info("The Instance Manager was able to log into you server " + "with faked compiled-in password while checking server status. " + "Looks like something is wrong."); pthread_mutex_unlock(&LOCK_instance); return_val= TRUE; /* server is alive */ } @@ -616,10 +642,10 @@ void Instance::kill_instance(int signum) /* Kill suceeded */ if (signum == SIGKILL) /* really killed instance with SIGKILL */ { - log_error("The instance %s is being stopped forcibly. Normally" \ - "it should not happen. Probably the instance has been" \ + log_error("The instance '%s' is being stopped forcibly. Normally" + "it should not happen. Probably the instance has been" "hanging. You should also check your IM setup", - options.instance_name); + (const char *) options.instance_name.str); /* After sucessful hard kill the pidfile need to be removed */ options.unlink_pidfile(); } diff --git a/server-tools/instance-manager/instance.h b/server-tools/instance-manager/instance.h index 1f06cabebf7..329eaa68b1a 100644 --- a/server-tools/instance-manager/instance.h +++ b/server-tools/instance-manager/instance.h @@ -27,6 +27,7 @@ #endif class Instance_map; +class Thread_registry; /* @@ -87,7 +88,7 @@ public: static bool is_mysqld_compatible_name(const LEX_STRING *name); public: - Instance(); + Instance(Thread_registry &thread_registry_arg); ~Instance(); int init(const LEX_STRING *name_arg); @@ -120,6 +121,7 @@ public: public: enum { DEFAULT_SHUTDOWN_DELAY= 35 }; Instance_options options; + Thread_registry &thread_registry; private: /* This attributes is a flag, specifies if the instance has been crashed. */ diff --git a/server-tools/instance-manager/instance_map.cc b/server-tools/instance-manager/instance_map.cc index ec73fb7d73a..2f830e616c4 100644 --- a/server-tools/instance-manager/instance_map.cc +++ b/server-tools/instance-manager/instance_map.cc @@ -169,7 +169,7 @@ int Instance_map::process_one_option(const LEX_STRING *group, if (!(instance= (Instance *) hash_search(&hash, (byte *) group->str, group->length))) { - if (!(instance= new Instance())) + if (!(instance= new Instance(thread_registry))) return 1; if (instance->init(group) || add_instance(instance)) @@ -213,8 +213,10 @@ int Instance_map::process_one_option(const LEX_STRING *group, } -Instance_map::Instance_map(const char *default_mysqld_path_arg): -mysqld_path(default_mysqld_path_arg) +Instance_map::Instance_map(const char *default_mysqld_path_arg, + Thread_registry &thread_registry_arg): + mysqld_path(default_mysqld_path_arg), + thread_registry(thread_registry_arg) { pthread_mutex_init(&LOCK_instance_map, 0); } @@ -293,7 +295,9 @@ int Instance_map::flush_instances() get_instance_key, delete_instance, 0); rc= load(); - guardian->init(); // TODO: check error status. + /* don't init guardian if we failed to load instances */ + if (!rc) + guardian->init(); // TODO: check error status. return rc; } @@ -331,7 +335,7 @@ int Instance_map::remove_instance(Instance *instance) int Instance_map::create_instance(const LEX_STRING *instance_name, const Named_value_arr *options) { - Instance *instance= new Instance(); + Instance *instance= new Instance(thread_registry); if (!instance) { diff --git a/server-tools/instance-manager/instance_map.h b/server-tools/instance-manager/instance_map.h index 8e6d2360652..9de40e35e0f 100644 --- a/server-tools/instance-manager/instance_map.h +++ b/server-tools/instance-manager/instance_map.h @@ -28,6 +28,7 @@ class Guardian_thread; class Instance; class Named_value_arr; +class Thread_registry; extern int load_all_groups(char ***groups, const char *filename); extern void free_groups(char **groups); @@ -104,7 +105,8 @@ public: int create_instance(const LEX_STRING *instance_name, const Named_value_arr *options); - Instance_map(const char *default_mysqld_path_arg); + Instance_map(const char *default_mysqld_path_arg, + Thread_registry &thread_registry_arg); ~Instance_map(); /* @@ -130,6 +132,8 @@ private: enum { START_HASH_SIZE = 16 }; pthread_mutex_t LOCK_instance_map; HASH hash; + + Thread_registry &thread_registry; }; #endif /* INCLUDES_MYSQL_INSTANCE_MANAGER_INSTANCE_MAP_H */ diff --git a/server-tools/instance-manager/listener.cc b/server-tools/instance-manager/listener.cc index 197c315dee8..62962c00957 100644 --- a/server-tools/instance-manager/listener.cc +++ b/server-tools/instance-manager/listener.cc @@ -87,7 +87,7 @@ private: Listener_thread::Listener_thread(const Listener_thread_args &args) : Listener_thread_args(args.thread_registry, args.user_map, args.instance_map) ,total_connection_count(0) - ,thread_info(pthread_self()) + ,thread_info(pthread_self(), TRUE) ,num_sockets(0) { } @@ -112,6 +112,8 @@ void Listener_thread::run() { int i, n= 0; + log_info("Listener_thread: started."); + #ifndef __WIN__ /* we use this var to check whether we are running on LinuxThreads */ pid_t thread_pid; @@ -164,7 +166,7 @@ void Listener_thread::run() if (rc == 0 || rc == -1) { if (rc == -1 && errno != EINTR) - log_error("Listener_thread::run(): select() failed, %s", + log_error("Listener_thread: select() failed, %s", strerror(errno)); continue; } @@ -198,7 +200,7 @@ void Listener_thread::run() /* III. Release all resources and exit */ - log_info("Listener_thread::run(): shutdown requested, exiting..."); + log_info("Listener_thread: shutdown requested, exiting..."); for (i= 0; i < num_sockets; i++) close(sockets[i]); @@ -209,6 +211,8 @@ void Listener_thread::run() thread_registry.unregister_thread(&thread_info); my_thread_end(); + + log_info("Listener_thread: finished."); return; err: @@ -230,7 +234,7 @@ int Listener_thread::create_tcp_socket() int ip_socket= socket(AF_INET, SOCK_STREAM, 0); if (ip_socket == INVALID_SOCKET) { - log_error("Listener_thead::run(): socket(AF_INET) failed, %s", + log_error("Listener_thead: socket(AF_INET) failed, %s", strerror(errno)); return -1; } @@ -261,7 +265,7 @@ int Listener_thread::create_tcp_socket() if (bind(ip_socket, (struct sockaddr *) &ip_socket_address, sizeof(ip_socket_address))) { - log_error("Listener_thread::run(): bind(ip socket) failed, '%s'", + log_error("Listener_thread: bind(ip socket) failed, '%s'", strerror(errno)); close(ip_socket); return -1; @@ -269,7 +273,7 @@ int Listener_thread::create_tcp_socket() if (listen(ip_socket, LISTEN_BACK_LOG_SIZE)) { - log_error("Listener_thread::run(): listen(ip socket) failed, %s", + log_error("Listener_thread: listen(ip socket) failed, %s", strerror(errno)); close(ip_socket); return -1; @@ -283,7 +287,7 @@ int Listener_thread::create_tcp_socket() FD_SET(ip_socket, &read_fds); sockets[num_sockets++]= ip_socket; - log_info("accepting connections on ip socket"); + log_info("accepting connections on ip socket (port: %d)", (int) im_port); return 0; } @@ -294,7 +298,7 @@ create_unix_socket(struct sockaddr_un &unix_socket_address) int unix_socket= socket(AF_UNIX, SOCK_STREAM, 0); if (unix_socket == INVALID_SOCKET) { - log_error("Listener_thead::run(): socket(AF_UNIX) failed, %s", + log_error("Listener_thead: socket(AF_UNIX) failed, %s", strerror(errno)); return -1; } @@ -314,7 +318,7 @@ create_unix_socket(struct sockaddr_un &unix_socket_address) if (bind(unix_socket, (struct sockaddr *) &unix_socket_address, sizeof(unix_socket_address))) { - log_error("Listener_thread::run(): bind(unix socket) failed, " + log_error("Listener_thread: bind(unix socket) failed, " "socket file name is '%s', error '%s'", unix_socket_address.sun_path, strerror(errno)); close(unix_socket); @@ -325,7 +329,7 @@ create_unix_socket(struct sockaddr_un &unix_socket_address) if (listen(unix_socket, LISTEN_BACK_LOG_SIZE)) { - log_error("Listener_thread::run(): listen(unix socket) failed, %s", + log_error("Listener_thread: listen(unix socket) failed, %s", strerror(errno)); close(unix_socket); return -1; @@ -337,7 +341,7 @@ create_unix_socket(struct sockaddr_un &unix_socket_address) /* make sure that instances won't be listening our sockets */ set_no_inherit(unix_socket); - log_info("accepting connections on unix socket %s", + log_info("accepting connections on unix socket '%s'", unix_socket_address.sun_path); sockets[num_sockets++]= unix_socket; FD_SET(unix_socket, &read_fds); diff --git a/server-tools/instance-manager/log.cc b/server-tools/instance-manager/log.cc index a88344f0b91..7214cde7193 100644 --- a/server-tools/instance-manager/log.cc +++ b/server-tools/instance-manager/log.cc @@ -52,14 +52,16 @@ static inline void log(FILE *file, const char *format, va_list args) struct tm bd_time; // broken-down time localtime_r(&now, &bd_time); - char buff_date[32]; - sprintf(buff_date, "%02d%02d%02d %2d:%02d:%02d\t", - bd_time.tm_year % 100, - bd_time.tm_mon + 1, - bd_time.tm_mday, - bd_time.tm_hour, - bd_time.tm_min, - bd_time.tm_sec); + char buff_date[128]; + sprintf(buff_date, "[%d/%lu] [%02d/%02d/%02d %02d:%02d:%02d] ", + (int) getpid(), + (unsigned long) pthread_self(), + bd_time.tm_year % 100, + bd_time.tm_mon + 1, + bd_time.tm_mday, + bd_time.tm_hour, + bd_time.tm_min, + bd_time.tm_sec); /* Format the message */ char buff_stack[256]; diff --git a/server-tools/instance-manager/manager.cc b/server-tools/instance-manager/manager.cc index d2d498eebf1..4bd298eedec 100644 --- a/server-tools/instance-manager/manager.cc +++ b/server-tools/instance-manager/manager.cc @@ -120,6 +120,19 @@ int my_sigwait(const sigset_t *set, int *sig) #endif +void stop_all(Guardian_thread *guardian, Thread_registry *registry) +{ + /* + Let guardian thread know that it should break it's processing cycle, + once it wakes up. + */ + guardian->request_shutdown(); + /* wake guardian */ + pthread_cond_signal(&guardian->COND_guardian); + /* stop all threads */ + registry->deliver_shutdown(); +} + /* manager - entry point to the main instance manager process: start listener thread, write pid file and enter into signal handling. @@ -143,7 +156,8 @@ void manager() */ User_map user_map; - Instance_map instance_map(Options::Main::default_mysqld_path); + Instance_map instance_map(Options::Main::default_mysqld_path, + thread_registry); Guardian_thread guardian_thread(thread_registry, &instance_map, Options::Main::monitoring_interval); @@ -251,7 +265,6 @@ void manager() /* Load instances. */ - { instance_map.guardian->lock(); instance_map.lock(); @@ -266,7 +279,8 @@ void manager() log_error("Cannot init instances repository. This might be caused by " "the wrong config file options. For instance, missing mysqld " "binary. Aborting."); - return; + stop_all(&guardian_thread, &thread_registry); + goto err; } } @@ -284,6 +298,7 @@ void manager() if (rc) { log_error("manager(): set_stacksize_n_create_thread(listener) failed"); + stop_all(&guardian_thread, &thread_registry); goto err; } } @@ -294,6 +309,8 @@ void manager() */ pthread_cond_signal(&guardian_thread.COND_guardian); + log_info("Main loop: started."); + while (!shutdown_complete) { int signo; @@ -302,9 +319,24 @@ void manager() if ((status= my_sigwait(&mask, &signo)) != 0) { log_error("sigwait() failed"); + stop_all(&guardian_thread, &thread_registry); goto err; } + /* + The general idea in this loop is the following: + - we are waiting for SIGINT, SIGTERM -- signals that mean we should + shutdown; + - as shutdown signal is caught, we stop Guardian thread (by calling + Guardian_thread::request_shutdown()); + - as Guardian_thread is stopped, it sends SIGTERM to this thread + (by calling Thread_registry::request_shutdown()), so that the + my_sigwait() above returns; + - as we catch the second SIGTERM, we send signals to all threads + registered in Thread_registry (by calling + Thread_registry::deliver_shutdown()) and waiting for threads to stop; + */ + #ifndef __WIN__ /* On some Darwin kernels SIGHUP is delivered along with most @@ -321,10 +353,11 @@ void manager() else #endif { + log_info("Main loop: got shutdown signal."); + if (!guardian_thread.is_stopped()) { - bool stop_instances= TRUE; - guardian_thread.request_shutdown(stop_instances); + guardian_thread.request_shutdown(); pthread_cond_signal(&guardian_thread.COND_guardian); } else @@ -335,6 +368,8 @@ void manager() } } + log_info("Main loop: finished."); + err: /* delete the pid file */ my_delete(Options::Main::pid_file_name, MYF(0)); diff --git a/server-tools/instance-manager/mysql_connection.cc b/server-tools/instance-manager/mysql_connection.cc index 17cda3af704..1c49d3cd83b 100644 --- a/server-tools/instance-manager/mysql_connection.cc +++ b/server-tools/instance-manager/mysql_connection.cc @@ -97,7 +97,7 @@ Mysql_connection_thread::Mysql_connection_thread( args.user_map, args.connection_id, args.instance_map) - ,thread_info(pthread_self()) + ,thread_info(pthread_self(), TRUE) { thread_registry.register_thread(&thread_info); } @@ -165,7 +165,7 @@ Mysql_connection_thread::~Mysql_connection_thread() void Mysql_connection_thread::run() { - log_info("accepted mysql connection %d", connection_id); + log_info("accepted mysql connection %d", (int) connection_id); my_thread_init(); @@ -175,7 +175,7 @@ void Mysql_connection_thread::run() return; } - log_info("connection %d is checked successfully", connection_id); + log_info("connection %d is checked successfully", (int) connection_id); vio_keepalive(vio, TRUE); @@ -315,7 +315,7 @@ int Mysql_connection_thread::do_command() enum enum_server_command command= (enum enum_server_command) (uchar) *packet; log_info("connection %d: packet_length=%d, command=%d", - connection_id, packet_length, command); + (int) connection_id, (int) packet_length, (int) command); return dispatch_command(command, packet + 1, packet_length - 1); } } @@ -325,27 +325,33 @@ int Mysql_connection_thread::dispatch_command(enum enum_server_command command, { switch (command) { case COM_QUIT: // client exit - log_info("query for connection %d received quit command", connection_id); + log_info("query for connection %d received quit command", + (int) connection_id); return 1; case COM_PING: - log_info("query for connection %d received ping command", connection_id); + log_info("query for connection %d received ping command", + (int) connection_id); net_send_ok(&net, connection_id, NULL); break; case COM_QUERY: { log_info("query for connection %d : ----\n%s\n-------------------------", - connection_id,packet); + (int) connection_id, + (const char *) packet); if (Command *command= parse_command(&instance_map, packet)) { int res= 0; - log_info("query for connection %d successfully parsed",connection_id); + log_info("query for connection %d successfully parsed", + (int) connection_id); res= command->execute(&net, connection_id); delete command; if (!res) - log_info("query for connection %d executed ok",connection_id); + log_info("query for connection %d executed ok", + (int) connection_id); else { - log_info("query for connection %d executed err=%d",connection_id,res); + log_info("query for connection %d executed err=%d", + (int) connection_id, (int) res); net_send_error(&net, res); return 0; } @@ -358,7 +364,8 @@ int Mysql_connection_thread::dispatch_command(enum enum_server_command command, break; } default: - log_info("query for connection %d received unknown command",connection_id); + log_info("query for connection %d received unknown command", + (int) connection_id); net_send_error(&net, ER_UNKNOWN_COM_ERROR); break; } diff --git a/server-tools/instance-manager/options.cc b/server-tools/instance-manager/options.cc index 07a1fd3e932..0fff68fbd4f 100644 --- a/server-tools/instance-manager/options.cc +++ b/server-tools/instance-manager/options.cc @@ -41,7 +41,6 @@ static char win_dflt_config_file_name[FN_REFLEN]; static char win_dflt_password_file_name[FN_REFLEN]; static char win_dflt_pid_file_name[FN_REFLEN]; -static char win_dflt_socket_file_name[FN_REFLEN]; static char win_dflt_mysqld_path[FN_REFLEN]; @@ -54,7 +53,6 @@ my_bool Options::Service::stand_alone; const char *Options::Main::config_file= win_dflt_config_file_name; const char *Options::Main::password_file_name= win_dflt_password_file_name; const char *Options::Main::pid_file_name= win_dflt_pid_file_name; -const char *Options::Main::socket_file_name= win_dflt_socket_file_name; const char *Options::Main::default_mysqld_path= win_dflt_mysqld_path; @@ -262,10 +260,12 @@ static struct my_option my_long_options[] = 0, 0, GET_BOOL, NO_ARG, 0, 0, 1, 0, 0, 0 }, #endif +#ifndef __WIN__ { "socket", OPT_SOCKET, "Socket file to use for connection.", (gptr *) &Options::Main::socket_file_name, (gptr *) &Options::Main::socket_file_name, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, +#endif #ifdef __WIN__ { "standalone", OPT_STAND_ALONE, "Run the application in stand alone mode.", @@ -550,8 +550,6 @@ static int setup_windows_defaults() strxmov(win_dflt_password_file_name, dir_name, im_name, DFLT_PASSWD_FILE_EXT, NullS); strxmov(win_dflt_pid_file_name, dir_name, im_name, DFLT_PID_FILE_EXT, NullS); - strxmov(win_dflt_socket_file_name, dir_name, im_name, DFLT_SOCKET_FILE_EXT, - NullS); return 0; } diff --git a/server-tools/instance-manager/options.h b/server-tools/instance-manager/options.h index 5c54ff201b2..ac4f6507892 100644 --- a/server-tools/instance-manager/options.h +++ b/server-tools/instance-manager/options.h @@ -50,7 +50,9 @@ struct Options static bool is_forced_default_file; static const char *pid_file_name; +#ifndef __WIN__ static const char *socket_file_name; +#endif static const char *password_file_name; static const char *default_mysqld_path; static uint monitoring_interval; diff --git a/server-tools/instance-manager/thread_registry.cc b/server-tools/instance-manager/thread_registry.cc index a424860548d..10370e0981e 100644 --- a/server-tools/instance-manager/thread_registry.cc +++ b/server-tools/instance-manager/thread_registry.cc @@ -43,8 +43,10 @@ static void handle_signal(int __attribute__((unused)) sig_no) */ Thread_info::Thread_info() {} -Thread_info::Thread_info(pthread_t thread_id_arg) : - thread_id(thread_id_arg) {} +Thread_info::Thread_info(pthread_t thread_id_arg, + bool send_signal_on_shutdown_arg) : + thread_id(thread_id_arg), + send_signal_on_shutdown(send_signal_on_shutdown_arg) {} /* TODO: think about moving signal information (now it's shutdown_in_progress) @@ -86,6 +88,9 @@ Thread_registry::~Thread_registry() void Thread_registry::register_thread(Thread_info *info) { + log_info("Thread_registry: registering thread %d...", + (int) info->thread_id); + #ifndef __WIN__ struct sigaction sa; sa.sa_handler= handle_signal; @@ -112,11 +117,19 @@ void Thread_registry::register_thread(Thread_info *info) void Thread_registry::unregister_thread(Thread_info *info) { + log_info("Thread_registry: unregistering thread %d...", + (int) info->thread_id); + pthread_mutex_lock(&LOCK_thread_registry); info->prev->next= info->next; info->next->prev= info->prev; + if (head.next == &head) + { + log_info("Thread_registry: thread registry is empty!"); pthread_cond_signal(&COND_thread_registry_is_empty); + } + pthread_mutex_unlock(&LOCK_thread_registry); } @@ -181,11 +194,6 @@ int Thread_registry::cond_timedwait(Thread_info *info, pthread_cond_t *cond, void Thread_registry::deliver_shutdown() { - Thread_info *info; - struct timespec shutdown_time; - int error; - set_timespec(shutdown_time, 1); - pthread_mutex_lock(&LOCK_thread_registry); shutdown_in_progress= TRUE; @@ -199,29 +207,14 @@ void Thread_registry::deliver_shutdown() process_alarm(THR_SERVER_ALARM); #endif - for (info= head.next; info != &head; info= info->next) - { - pthread_kill(info->thread_id, THREAD_KICK_OFF_SIGNAL); - /* - sic: race condition here, the thread may not yet fall into - pthread_cond_wait. - */ - if (info->current_cond) - pthread_cond_signal(info->current_cond); - } /* - The common practice is to test predicate before pthread_cond_wait. - I don't do that here because the predicate is practically always false - before wait - is_shutdown's been just set, and the lock's still not - released - the only case when the predicate is false is when no other - threads exist. + sic: race condition here, the thread may not yet fall into + pthread_cond_wait. */ - while (((error= pthread_cond_timedwait(&COND_thread_registry_is_empty, - &LOCK_thread_registry, - &shutdown_time)) != ETIMEDOUT && - error != ETIME) && - head.next != &head) - ; + + interrupt_threads(); + + wait_for_threads_to_unregister(); /* If previous signals did not reach some threads, they must be sleeping @@ -230,11 +223,28 @@ void Thread_registry::deliver_shutdown() so this time everybody should be informed (presumably each worker can get CPU during shutdown_time.) */ - for (info= head.next; info != &head; info= info->next) + + interrupt_threads(); + + /* Get the last chance to threads to stop. */ + + wait_for_threads_to_unregister(); + + /* + Print out threads, that didn't stopped. Thread_registry destructor will + probably abort the program if there is still any alive thread. + */ + + if (head.next != &head) { - pthread_kill(info->thread_id, THREAD_KICK_OFF_SIGNAL); - if (info->current_cond) - pthread_cond_signal(info->current_cond); + log_info("Thread_registry: non-stopped threads:"); + + for (Thread_info *info= head.next; info != &head; info= info->next) + log_info(" - %ld", (long int) info->thread_id); + } + else + { + log_info("Thread_registry: all threads stopped."); } pthread_mutex_unlock(&LOCK_thread_registry); @@ -245,3 +255,46 @@ void Thread_registry::request_shutdown() { pthread_kill(sigwait_thread_pid, SIGTERM); } + + +void Thread_registry::interrupt_threads() +{ + for (Thread_info *info= head.next; info != &head; info= info->next) + { + if (!info->send_signal_on_shutdown) + continue; + + pthread_kill(info->thread_id, THREAD_KICK_OFF_SIGNAL); + if (info->current_cond) + pthread_cond_signal(info->current_cond); + } +} + + +void Thread_registry::wait_for_threads_to_unregister() +{ + struct timespec shutdown_time; + + set_timespec(shutdown_time, 1); + + log_info("Thread_registry: joining threads..."); + + while (true) + { + if (head.next == &head) + { + log_info("Thread_registry: emptied."); + return; + } + + int error= pthread_cond_timedwait(&COND_thread_registry_is_empty, + &LOCK_thread_registry, + &shutdown_time); + + if (error == ETIMEDOUT || error == ETIME) + { + log_info("Thread_registry: threads shutdown timed out."); + return; + } + } +} diff --git a/server-tools/instance-manager/thread_registry.h b/server-tools/instance-manager/thread_registry.h index 6dc320a8533..503d24e5fb0 100644 --- a/server-tools/instance-manager/thread_registry.h +++ b/server-tools/instance-manager/thread_registry.h @@ -67,13 +67,17 @@ class Thread_info { public: - Thread_info(); - Thread_info(pthread_t thread_id_arg); + Thread_info(pthread_t thread_id_arg, bool send_signal_on_shutdown_arg); friend class Thread_registry; + +private: + Thread_info(); + private: pthread_cond_t *current_cond; Thread_info *prev, *next; pthread_t thread_id; + bool send_signal_on_shutdown; }; @@ -98,6 +102,10 @@ public: int cond_timedwait(Thread_info *info, pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *wait_time); private: + void interrupt_threads(); + void wait_for_threads_to_unregister(); + +private: Thread_info head; bool shutdown_in_progress; pthread_mutex_t LOCK_thread_registry; diff --git a/sql-common/client.c b/sql-common/client.c index 79a5be938b2..b6947028e74 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -2364,6 +2364,8 @@ my_bool mysql_reconnect(MYSQL *mysql) { MYSQL tmp_mysql; DBUG_ENTER("mysql_reconnect"); + DBUG_ASSERT(mysql); + DBUG_PRINT("enter", ("mysql->reconnect: %d", mysql->reconnect)); if (!mysql->reconnect || (mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info) diff --git a/sql-common/my_time.c b/sql-common/my_time.c index b4cfe041529..29de0504468 100644 --- a/sql-common/my_time.c +++ b/sql-common/my_time.c @@ -465,8 +465,10 @@ err: There may be an optional [.second_part] after seconds length Length of str l_time Store result here - was_cut Set to 1 if value was cut during conversion or to 0 - otherwise. + warning Set MYSQL_TIME_WARN_TRUNCATED flag if the input string + was cut during conversion, and/or + MYSQL_TIME_WARN_OUT_OF_RANGE flag, if the value is + out of range. NOTES Because of the extra days argument, this function can only @@ -478,15 +480,16 @@ err: */ my_bool str_to_time(const char *str, uint length, MYSQL_TIME *l_time, - int *was_cut) + int *warning) { - long date[5],value; + ulong date[5]; + ulonglong value; const char *end=str+length, *end_of_days; my_bool found_days,found_hours; uint state; l_time->neg=0; - *was_cut= 0; + *warning= 0; for (; str != end && my_isspace(&my_charset_latin1,*str) ; str++) length--; if (str != end && *str == '-') @@ -501,13 +504,16 @@ my_bool str_to_time(const char *str, uint length, MYSQL_TIME *l_time, /* Check first if this is a full TIMESTAMP */ if (length >= 12) { /* Probably full timestamp */ + int was_cut; enum enum_mysql_timestamp_type res= str_to_datetime(str, length, l_time, - (TIME_FUZZY_DATE | TIME_DATETIME_ONLY), was_cut); + (TIME_FUZZY_DATE | TIME_DATETIME_ONLY), &was_cut); if ((int) res >= (int) MYSQL_TIMESTAMP_ERROR) + { + if (was_cut) + *warning|= MYSQL_TIME_WARN_TRUNCATED; return res == MYSQL_TIMESTAMP_ERROR; - /* We need to restore was_cut flag since str_to_datetime can modify it */ - *was_cut= 0; + } } /* Not a timestamp. Try to get this as a DAYS_TO_SECOND string */ @@ -587,7 +593,7 @@ fractional: if (field_length > 0) value*= (long) log_10_int[field_length]; else if (field_length < 0) - *was_cut= 1; + *warning|= MYSQL_TIME_WARN_TRUNCATED; date[4]=value; } else @@ -601,10 +607,7 @@ fractional: ((str[1] == '-' || str[1] == '+') && (end - str) > 2 && my_isdigit(&my_charset_latin1, str[2])))) - { - *was_cut= 1; return 1; - } if (internal_format_positions[7] != 255) { @@ -623,12 +626,12 @@ fractional: } } - /* Some simple checks */ - if (date[2] >= 60 || date[3] >= 60) - { - *was_cut= 1; + /* Integer overflow checks */ + if (date[0] > UINT_MAX || date[1] > UINT_MAX || + date[2] > UINT_MAX || date[3] > UINT_MAX || + date[4] > UINT_MAX) return 1; - } + l_time->year= 0; /* For protocol::store_time */ l_time->month= 0; l_time->day= date[0]; @@ -638,6 +641,10 @@ fractional: l_time->second_part= date[4]; l_time->time_type= MYSQL_TIMESTAMP_TIME; + /* Check if the value is valid and fits into TIME range */ + if (check_time_range(l_time, warning)) + return 1; + /* Check if there is garbage at end of the TIME specification */ if (str != end) { @@ -645,7 +652,7 @@ fractional: { if (!my_isspace(&my_charset_latin1,*str)) { - *was_cut= 1; + *warning|= MYSQL_TIME_WARN_TRUNCATED; break; } } while (++str != end); @@ -655,6 +662,47 @@ fractional: /* + Check 'time' value to lie in the TIME range + + SYNOPSIS: + check_time_range() + time pointer to TIME value + warning set MYSQL_TIME_WARN_OUT_OF_RANGE flag if the value is out of range + + DESCRIPTION + If the time value lies outside of the range [-838:59:59, 838:59:59], + set it to the closest endpoint of the range and set + MYSQL_TIME_WARN_OUT_OF_RANGE flag in the 'warning' variable. + + RETURN + 0 time value is valid, but was possibly truncated + 1 time value is invalid +*/ + +int check_time_range(struct st_mysql_time *time, int *warning) +{ + longlong hour; + + if (time->minute >= 60 || time->second >= 60) + return 1; + + hour= time->hour + (24*time->day); + if (hour <= TIME_MAX_HOUR && + (hour != TIME_MAX_HOUR || time->minute != TIME_MAX_MINUTE || + time->second != TIME_MAX_SECOND || !time->second_part)) + return 0; + + time->day= 0; + time->hour= TIME_MAX_HOUR; + time->minute= TIME_MAX_MINUTE; + time->second= TIME_MAX_SECOND; + time->second_part= 0; + *warning|= MYSQL_TIME_WARN_OUT_OF_RANGE; + return 0; +} + + +/* Prepare offset of system time zone from UTC for my_system_gmt_sec() func. SYNOPSIS @@ -840,7 +888,7 @@ void set_zero_time(MYSQL_TIME *tm, enum enum_mysql_timestamp_type time_type) int my_time_to_str(const MYSQL_TIME *l_time, char *to) { uint extra_hours= 0; - return my_sprintf(to, (to, "%s%02d:%02d:%02d", + return my_sprintf(to, (to, "%s%02u:%02u:%02u", (l_time->neg ? "-" : ""), extra_hours+ l_time->hour, l_time->minute, @@ -849,7 +897,7 @@ int my_time_to_str(const MYSQL_TIME *l_time, char *to) int my_date_to_str(const MYSQL_TIME *l_time, char *to) { - return my_sprintf(to, (to, "%04d-%02d-%02d", + return my_sprintf(to, (to, "%04u-%02u-%02u", l_time->year, l_time->month, l_time->day)); @@ -857,7 +905,7 @@ int my_date_to_str(const MYSQL_TIME *l_time, char *to) int my_datetime_to_str(const MYSQL_TIME *l_time, char *to) { - return my_sprintf(to, (to, "%04d-%02d-%02d %02d:%02d:%02d", + return my_sprintf(to, (to, "%04u-%02u-%02u %02u:%02u:%02u", l_time->year, l_time->month, l_time->day, diff --git a/sql/Makefile.am b/sql/Makefile.am index edb45b3e54f..3a51eab485c 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -27,15 +27,16 @@ INCLUDES = @ZLIB_INCLUDES@ \ WRAPLIBS= @WRAPLIBS@ SUBDIRS = share libexec_PROGRAMS = mysqld -EXTRA_PROGRAMS = gen_lex_hash +noinst_PROGRAMS = gen_lex_hash bin_PROGRAMS = mysql_tzinfo_to_sql gen_lex_hash_LDFLAGS = @NOINST_LDFLAGS@ -LDADD = $(top_builddir)/vio/libvio.a \ +SUPPORTING_LIBS = $(top_builddir)/vio/libvio.a \ $(top_builddir)/mysys/libmysys.a \ $(top_builddir)/dbug/libdbug.a \ $(top_builddir)/regex/libregex.a \ - $(top_builddir)/strings/libmystrings.a @ZLIB_LIBS@ -mysqld_DEPENDENCIES= @mysql_plugin_libs@ $(LDADD) + $(top_builddir)/strings/libmystrings.a +mysqld_DEPENDENCIES= @mysql_plugin_libs@ $(SUPPORTING_LIBS) +LDADD = $(SUPPORTING_LIBS) @ZLIB_LIBS@ mysqld_LDADD = @MYSQLD_EXTRA_LDFLAGS@ \ @pstack_libs@ \ @mysql_plugin_libs@ \ @@ -120,8 +121,9 @@ DEFS = -DMYSQL_SERVER \ -DLIBDIR="\"$(MYSQLLIBdir)\"" \ @DEFS@ -BUILT_SOURCES = sql_yacc.cc sql_yacc.h lex_hash.h -EXTRA_DIST = udf_example.c udf_example.def $(BUILT_SOURCES) \ +BUILT_DIST_SRC = sql_yacc.cc sql_yacc.h +BUILT_SOURCES = $(BUILT_DIST_SRC) lex_hash.h +EXTRA_DIST = udf_example.c udf_example.def $(BUILT_DIST_SRC) \ nt_servc.cc nt_servc.h message.mc CMakeLists.txt \ udf_example.c udf_example.def CLEANFILES = lex_hash.h sql_yacc.cc sql_yacc.h sql_yacc.output @@ -157,11 +159,10 @@ sql_yacc.o: sql_yacc.cc sql_yacc.h $(HEADERS) @echo "If it fails, re-run configure with --with-low-memory" $(CXXCOMPILE) $(LM_CFLAGS) -c $< -# This generates lex_hash.h -# NOTE Built sources should depend on their sources not the tool -# this avoid the rebuild of the built files in a source dist -lex_hash.h: gen_lex_hash.cc lex.h - $(MAKE) $(AM_MAKEFLAGS) gen_lex_hash$(EXEEXT) +# FIXME seems like now "lex_hash.h" differs depending on configure +# flags, so can't pregenerate and include in source TAR. Revert to +# dist pregenerated if this changes, so the file doesn't differ. +lex_hash.h: gen_lex_hash$(EXEEXT) ./gen_lex_hash$(EXEEXT) > $@ # the following three should eventually be moved out of this directory diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 4b9aa43b14b..afd10350bb5 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -886,14 +886,29 @@ Event_queue_element::load_from_row(TABLE *table) goto error; /* - In DB the values start from 1 but enum interval_type starts - from 0 + We load the interval type from disk as string and then map it to + an integer. This decouples the values of enum interval_type + and values actually stored on disk. Therefore the type can be + reordered without risking incompatibilities of data between versions. */ if (!table->field[ET_FIELD_TRANSIENT_INTERVAL]->is_null()) - interval= (interval_type) ((ulonglong) - table->field[ET_FIELD_TRANSIENT_INTERVAL]->val_int() - 1); - else - interval= (interval_type) 0; + { + int i; + char buff[MAX_FIELD_WIDTH]; + String str(buff, sizeof(buff), &my_charset_bin); + LEX_STRING tmp; + + table->field[ET_FIELD_TRANSIENT_INTERVAL]->val_str(&str); + if (!(tmp.length= str.length())) + goto error; + + tmp.str= str.c_ptr_safe(); + + i= find_string_in_array(interval_type_to_name, &tmp, system_charset_info); + if (i < 0) + goto error; + interval= (interval_type) i; + } table->field[ET_FIELD_LAST_EXECUTED]->get_date(&last_executed, TIME_NO_ZERO_DATE); diff --git a/sql/event_db_repository.cc b/sql/event_db_repository.cc index 464c26044c7..3d30aff669b 100644 --- a/sql/event_db_repository.cc +++ b/sql/event_db_repository.cc @@ -188,11 +188,11 @@ mysql_event_fill_row(THD *thd, TABLE *table, Event_parse_data *et, fields[ET_FIELD_INTERVAL_EXPR]->store((longlong)et->expression, TRUE); fields[ET_FIELD_TRANSIENT_INTERVAL]->set_notnull(); - /* - In the enum (C) intervals start from 0 but in mysql enum valid values - start from 1. Thus +1 offset is needed! - */ - fields[ET_FIELD_TRANSIENT_INTERVAL]->store((longlong)et->interval+1, TRUE); + + fields[ET_FIELD_TRANSIENT_INTERVAL]-> + store(interval_type_to_name[et->interval].str, + interval_type_to_name[et->interval].length, + scs); fields[ET_FIELD_EXECUTE_AT]->set_null(); diff --git a/sql/field.cc b/sql/field.cc index 3161026061f..85356994e39 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4875,9 +4875,10 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) { TIME ltime; long tmp; - int error; + int error= 0; + int warning; - if (str_to_time(from, len, <ime, &error)) + if (str_to_time(from, len, <ime, &warning)) { tmp=0L; error= 2; @@ -4886,29 +4887,27 @@ int Field_time::store(const char *from,uint len,CHARSET_INFO *cs) } else { - if (error) + if (warning & MYSQL_TIME_WARN_TRUNCATED) set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, from, len, MYSQL_TIMESTAMP_TIME, 1); - - if (ltime.month) - ltime.day=0; - tmp=(ltime.day*24L+ltime.hour)*10000L+(ltime.minute*100+ltime.second); - if (tmp > 8385959) + if (warning & MYSQL_TIME_WARN_OUT_OF_RANGE) { - tmp=8385959; set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, from, len, MYSQL_TIMESTAMP_TIME, !error); error= 1; } + if (ltime.month) + ltime.day=0; + tmp=(ltime.day*24L+ltime.hour)*10000L+(ltime.minute*100+ltime.second); if (error > 1) error= 2; } if (ltime.neg) tmp= -tmp; - error |= Field_time::store((longlong) tmp, FALSE); + int3store(ptr,tmp); return error; } @@ -4928,16 +4927,16 @@ int Field_time::store(double nr) ASSERT_COLUMN_MARKED_FOR_WRITE; long tmp; int error= 0; - if (nr > 8385959.0) + if (nr > (double)TIME_MAX_VALUE) { - tmp=8385959L; + tmp= TIME_MAX_VALUE; set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME); error= 1; } - else if (nr < -8385959.0) + else if (nr < (double)-TIME_MAX_VALUE) { - tmp= -8385959L; + tmp= -TIME_MAX_VALUE; set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME); error= 1; @@ -4966,17 +4965,17 @@ int Field_time::store(longlong nr, bool unsigned_val) ASSERT_COLUMN_MARKED_FOR_WRITE; long tmp; int error= 0; - if (nr < (longlong) -8385959L && !unsigned_val) + if (nr < (longlong) -TIME_MAX_VALUE && !unsigned_val) { - tmp= -8385959L; + tmp= -TIME_MAX_VALUE; set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME, 1); error= 1; } - else if (nr > (longlong) 8385959 || nr < 0 && unsigned_val) + else if (nr > (longlong) TIME_MAX_VALUE || nr < 0 && unsigned_val) { - tmp=8385959L; + tmp= TIME_MAX_VALUE; set_datetime_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, nr, MYSQL_TIMESTAMP_TIME, 1); diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 13ea471511c..8e802d449b5 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -152,8 +152,7 @@ static byte *ndbcluster_get_key(NDB_SHARE *share,uint *length, static int rename_share(NDB_SHARE *share, const char *new_key); #endif static void ndb_set_fragmentation(NDBTAB &tab, TABLE *table, uint pk_len); - -static int ndb_get_table_statistics(Ndb*, const NDBTAB *, +static int ndb_get_table_statistics(ha_ndbcluster*, bool, Ndb*, const NDBTAB *, struct Ndb_statistics *); @@ -450,16 +449,13 @@ ha_rows ha_ndbcluster::records() Ndb *ndb= get_ndb(); ndb->setDatabaseName(m_dbname); struct Ndb_statistics stat; - if (ndb_get_table_statistics(ndb, m_table, &stat) == 0) + if (ndb_get_table_statistics(this, true, ndb, m_table, &stat) == 0) { retval= stat.row_count; } else { - /** - * Be consistent with BUG#19914 until we fix it properly - */ - DBUG_RETURN(-1); + DBUG_RETURN(HA_POS_ERROR); } THD *thd= current_thd; @@ -469,11 +465,13 @@ ha_rows ha_ndbcluster::records() DBUG_RETURN(retval + info->no_uncommitted_rows_count); } -void ha_ndbcluster::records_update() +int ha_ndbcluster::records_update() { if (m_ha_not_exact_count) - return; + return 0; DBUG_ENTER("ha_ndbcluster::records_update"); + int result= 0; + struct Ndb_local_table_statistics *info= m_table_info; DBUG_PRINT("info", ("id=%d, no_uncommitted_rows_count=%d", ((const NDBTAB *)m_table)->getTableId(), @@ -483,7 +481,8 @@ void ha_ndbcluster::records_update() Ndb *ndb= get_ndb(); struct Ndb_statistics stat; ndb->setDatabaseName(m_dbname); - if (ndb_get_table_statistics(ndb, m_table, &stat) == 0) + result= ndb_get_table_statistics(this, true, ndb, m_table, &stat); + if (result == 0) { stats.mean_rec_length= stat.row_size; stats.data_file_length= stat.fragment_memory; @@ -495,8 +494,9 @@ void ha_ndbcluster::records_update() if (get_thd_ndb(thd)->error) info->no_uncommitted_rows_count= 0; } - stats.records= info->records+ info->no_uncommitted_rows_count; - DBUG_VOID_RETURN; + if(result==0) + stats.records= info->records+ info->no_uncommitted_rows_count; + DBUG_RETURN(result); } void ha_ndbcluster::no_uncommitted_rows_execute_failure() @@ -561,7 +561,14 @@ int ha_ndbcluster::ndb_err(NdbTransaction *trans) if (res == HA_ERR_FOUND_DUPP_KEY) { if (m_rows_to_insert == 1) - m_dupkey= table_share->primary_key; + { + /* + We can only distinguish between primary and non-primary + violations here, so we need to return MAX_KEY for non-primary + to signal that key is unknown + */ + m_dupkey= err.code == 630 ? table_share->primary_key : MAX_KEY; + } else { /* We are batching inserts, offending key is not available */ @@ -1390,9 +1397,8 @@ NDB_INDEX_TYPE ha_ndbcluster::get_index_type_from_key(uint inx, ORDERED_INDEX); } -int ha_ndbcluster::check_index_fields_not_null(uint inx) +int ha_ndbcluster::check_index_fields_not_null(KEY* key_info) { - KEY* key_info= table->key_info + inx; KEY_PART_INFO* key_part= key_info->key_part; KEY_PART_INFO* end= key_part+key_info->key_parts; DBUG_ENTER("ha_ndbcluster::check_index_fields_not_null"); @@ -1883,7 +1889,8 @@ int ha_ndbcluster::peek_indexed_rows(const byte *record) int res; DBUG_ENTER("peek_indexed_rows"); - NdbOperation::LockMode lm= NdbOperation::LM_Read; + NdbOperation::LockMode lm= + (NdbOperation::LockMode)get_ndb_lock_type(m_lock.type); first= NULL; if (table->s->primary_key != MAX_KEY) { @@ -3642,8 +3649,9 @@ void ha_ndbcluster::position(const byte *record) } -void ha_ndbcluster::info(uint flag) +int ha_ndbcluster::info(uint flag) { + int result= 0; DBUG_ENTER("info"); DBUG_PRINT("enter", ("flag: %d", flag)); @@ -3661,18 +3669,19 @@ void ha_ndbcluster::info(uint flag) if (m_ha_not_exact_count) stats.records= 100; else - records_update(); + result= records_update(); } else { if ((my_errno= check_ndb_connection())) - DBUG_VOID_RETURN; + DBUG_RETURN(my_errno); Ndb *ndb= get_ndb(); ndb->setDatabaseName(m_dbname); struct Ndb_statistics stat; ndb->setDatabaseName(m_dbname); if (current_thd->variables.ndb_use_exact_count && - ndb_get_table_statistics(ndb, m_table, &stat) == 0) + (result= ndb_get_table_statistics(this, true, ndb, m_table, &stat)) + == 0) { stats.mean_rec_length= stat.row_size; stats.data_file_length= stat.fragment_memory; @@ -3716,7 +3725,11 @@ void ha_ndbcluster::info(uint flag) stats.auto_increment_value= (ulonglong)auto_increment_value64; } } - DBUG_VOID_RETURN; + + if(result == -1) + result= HA_ERR_NO_CONNECTION; + + DBUG_RETURN(result); } @@ -5002,7 +5015,7 @@ int ha_ndbcluster::create_index(const char *name, KEY *key_info, error= create_unique_index(unique_name, key_info); break; case UNIQUE_INDEX: - if (!(error= check_index_fields_not_null(idx_no))) + if (!(error= check_index_fields_not_null(key_info))) error= create_unique_index(unique_name, key_info); break; case ORDERED_INDEX: @@ -5740,7 +5753,17 @@ int ha_ndbcluster::open(const char *name, int mode, uint test_if_locked) res= get_metadata(name); if (!res) - info(HA_STATUS_VARIABLE | HA_STATUS_CONST); + { + Ndb *ndb= get_ndb(); + ndb->setDatabaseName(m_dbname); + struct Ndb_statistics stat; + res= ndb_get_table_statistics(NULL, false, ndb, m_table, &stat); + stats.mean_rec_length= stat.row_size; + stats.data_file_length= stat.fragment_memory; + stats.records= stat.row_count; + if(!res) + res= info(HA_STATUS_CONST); + } #ifdef HAVE_NDB_BINLOG if (!ndb_binlog_tables_inited && ndb_binlog_running) @@ -6805,7 +6828,7 @@ ha_ndbcluster::records_in_range(uint inx, key_range *min_key, else { Ndb_statistics stat; - if ((res=ndb_get_table_statistics(ndb, m_table, &stat)) != 0) + if ((res=ndb_get_table_statistics(this, true, ndb, m_table, &stat)) != 0) break; table_rows=stat.row_count; DBUG_PRINT("info", ("use db row_count: %llu", table_rows)); @@ -6966,7 +6989,7 @@ uint ndb_get_commitcount(THD *thd, char *dbname, char *tabname, { Ndb_table_guard ndbtab_g(ndb->getDictionary(), tabname); if (ndbtab_g.get_table() == 0 - || ndb_get_table_statistics(ndb, ndbtab_g.get_table(), &stat)) + || ndb_get_table_statistics(NULL, false, ndb, ndbtab_g.get_table(), &stat)) { free_share(&share); DBUG_RETURN(1); @@ -7532,12 +7555,13 @@ void ndbcluster_free_share(NDB_SHARE **share, bool have_lock) static int -ndb_get_table_statistics(Ndb* ndb, const NDBTAB *ndbtab, +ndb_get_table_statistics(ha_ndbcluster* file, bool report_error, Ndb* ndb, const NDBTAB *ndbtab, struct Ndb_statistics * ndbstat) { NdbTransaction* pTrans; NdbError error; int retries= 10; + int reterr= 0; int retry_sleep= 30 * 1000; /* 30 milliseconds */ char buff[22], buff2[22], buff3[22], buff4[22]; DBUG_ENTER("ndb_get_table_statistics"); @@ -7633,6 +7657,22 @@ ndb_get_table_statistics(Ndb* ndb, const NDBTAB *ndbtab, DBUG_RETURN(0); retry: + if(report_error) + { + if (file) + { + reterr= file->ndb_err(pTrans); + } + else + { + const NdbError& tmp= error; + ERR_PRINT(tmp); + reterr= ndb_to_mysql_error(&tmp); + } + } + else + reterr= error.code; + if (pTrans) { ndb->closeTransaction(pTrans); @@ -7645,8 +7685,9 @@ retry: } break; } while(1); - DBUG_PRINT("exit", ("failed, error %u(%s)", error.code, error.message)); - ERR_RETURN(error); + DBUG_PRINT("exit", ("failed, reterr: %u, NdbError %u(%s)", reterr, + error.code, error.message)); + DBUG_RETURN(reterr); } /* @@ -8304,7 +8345,7 @@ pthread_handler_t ndb_util_thread_func(void *arg __attribute__((unused))) { Ndb_table_guard ndbtab_g(ndb->getDictionary(), share->table_name); if (ndbtab_g.get_table() && - ndb_get_table_statistics(ndb, ndbtab_g.get_table(), &stat) == 0) + ndb_get_table_statistics(NULL, false, ndb, ndbtab_g.get_table(), &stat) == 0) { char buff[22], buff2[22]; DBUG_PRINT("ndb_util_thread", @@ -10137,6 +10178,8 @@ bool ha_ndbcluster::check_if_incompatible_data(HA_CREATE_INFO *info, DBUG_RETURN(COMPATIBLE_DATA_NO); } + int pk= 0; + int ai= 0; for (i= 0; i < table->s->fields; i++) { Field *field= table->field[i]; @@ -10152,10 +10195,33 @@ bool ha_ndbcluster::check_if_incompatible_data(HA_CREATE_INFO *info, DBUG_PRINT("info", ("add/drop index not supported for disk stored column")); DBUG_RETURN(COMPATIBLE_DATA_NO); } + + if (field->flags & PRI_KEY_FLAG) + pk=1; + if (field->flags & FIELD_IN_ADD_INDEX) + ai=1; } if (table_changes != IS_EQUAL_YES) DBUG_RETURN(COMPATIBLE_DATA_NO); + /** + * Changing from/to primary key + * + * This is _not_ correct, but check_if_incompatible_data-interface + * doesnt give more info, so I guess that we can't do any + * online add index if not using primary key + * + * This as mysql will handle a unique not null index as primary + * even wo/ user specifiying it... :-( + * + */ + if ((table_share->primary_key == MAX_KEY && pk) || + (table_share->primary_key != MAX_KEY && !pk) || + (table_share->primary_key == MAX_KEY && !pk && ai)) + { + DBUG_RETURN(COMPATIBLE_DATA_NO); + } + /* Check that auto_increment value was not changed */ if ((info->used_fields & HA_CREATE_USED_AUTO) && info->auto_increment_value != 0) @@ -10498,7 +10564,7 @@ static int ndbcluster_fill_files_table(handlerton *hton, while ((id= g_ndb_cluster_connection->get_next_node(iter))) { - uint c= 0; + init_fill_schema_files_row(table); NdbDictionary::Datafile df= dict->getDatafile(id, elt.name); ndberr= dict->getNdbError(); if(ndberr.classification != NdbError::NoError) @@ -10516,76 +10582,48 @@ static int ndbcluster_fill_files_table(handlerton *hton, ERR_RETURN(ndberr); } - table->field[c++]->set_null(); // FILE_ID - table->field[c]->set_notnull(); - table->field[c++]->store(elt.name, strlen(elt.name), - system_charset_info); - table->field[c]->set_notnull(); - table->field[c++]->store("DATAFILE",8,system_charset_info); - table->field[c]->set_notnull(); - table->field[c++]->store(df.getTablespace(), strlen(df.getTablespace()), - system_charset_info); - table->field[c++]->set_null(); // TABLE_CATALOG - table->field[c++]->set_null(); // TABLE_SCHEMA - table->field[c++]->set_null(); // TABLE_NAME - - // LOGFILE_GROUP_NAME - table->field[c]->set_notnull(); - table->field[c++]->store(ts.getDefaultLogfileGroup(), - strlen(ts.getDefaultLogfileGroup()), - system_charset_info); - table->field[c++]->set_null(); // LOGFILE_GROUP_NUMBER - table->field[c]->set_notnull(); - table->field[c++]->store(ndbcluster_hton_name, - ndbcluster_hton_name_length, - system_charset_info); // ENGINE - - table->field[c++]->set_null(); // FULLTEXT_KEYS - table->field[c++]->set_null(); // DELETED_ROWS - table->field[c++]->set_null(); // UPDATE_COUNT - table->field[c]->set_notnull(); - table->field[c++]->store(df.getFree() / ts.getExtentSize()); // FREE_EXTENTS - table->field[c]->set_notnull(); - table->field[c++]->store(df.getSize() / ts.getExtentSize()); // TOTAL_EXTENTS - table->field[c]->set_notnull(); - table->field[c++]->store(ts.getExtentSize()); // EXTENT_SIZE - - table->field[c]->set_notnull(); - table->field[c++]->store(df.getSize()); // INITIAL_SIZE - table->field[c]->set_notnull(); - table->field[c++]->store(df.getSize()); // MAXIMUM_SIZE - table->field[c++]->set_null(); // AUTOEXTEND_SIZE - - table->field[c++]->set_null(); // CREATION_TIME - table->field[c++]->set_null(); // LAST_UPDATE_TIME - table->field[c++]->set_null(); // LAST_ACCESS_TIME - table->field[c++]->set_null(); // RECOVER_TIME - table->field[c++]->set_null(); // TRANSACTION_COUNTER - - table->field[c]->set_notnull(); - table->field[c++]->store(df.getObjectVersion()); // VERSION - - table->field[c]->set_notnull(); - table->field[c++]->store("FIXED", 5, system_charset_info); // ROW_FORMAT - - table->field[c++]->set_null(); // TABLE_ROWS - table->field[c++]->set_null(); // AVG_ROW_LENGTH - table->field[c++]->set_null(); // DATA_LENGTH - table->field[c++]->set_null(); // MAX_DATA_LENGTH - table->field[c++]->set_null(); // INDEX_LENGTH - table->field[c++]->set_null(); // DATA_FREE - table->field[c++]->set_null(); // CREATE_TIME - table->field[c++]->set_null(); // UPDATE_TIME - table->field[c++]->set_null(); // CHECK_TIME - table->field[c++]->set_null(); // CHECKSUM - - table->field[c]->set_notnull(); - table->field[c++]->store("NORMAL", 6, system_charset_info); + table->field[IS_FILES_FILE_NAME]->set_notnull(); + table->field[IS_FILES_FILE_NAME]->store(elt.name, strlen(elt.name), + system_charset_info); + table->field[IS_FILES_FILE_TYPE]->set_notnull(); + table->field[IS_FILES_FILE_TYPE]->store("DATAFILE",8, + system_charset_info); + table->field[IS_FILES_TABLESPACE_NAME]->set_notnull(); + table->field[IS_FILES_TABLESPACE_NAME]->store(df.getTablespace(), + strlen(df.getTablespace()), + system_charset_info); + table->field[IS_FILES_LOGFILE_GROUP_NAME]->set_notnull(); + table->field[IS_FILES_LOGFILE_GROUP_NAME]-> + store(ts.getDefaultLogfileGroup(), + strlen(ts.getDefaultLogfileGroup()), + system_charset_info); + table->field[IS_FILES_ENGINE]->set_notnull(); + table->field[IS_FILES_ENGINE]->store(ndbcluster_hton_name, + ndbcluster_hton_name_length, + system_charset_info); + + table->field[IS_FILES_FREE_EXTENTS]->set_notnull(); + table->field[IS_FILES_FREE_EXTENTS]->store(df.getFree() + / ts.getExtentSize()); + table->field[IS_FILES_TOTAL_EXTENTS]->set_notnull(); + table->field[IS_FILES_TOTAL_EXTENTS]->store(df.getSize() + / ts.getExtentSize()); + table->field[IS_FILES_EXTENT_SIZE]->set_notnull(); + table->field[IS_FILES_EXTENT_SIZE]->store(ts.getExtentSize()); + table->field[IS_FILES_INITIAL_SIZE]->set_notnull(); + table->field[IS_FILES_INITIAL_SIZE]->store(df.getSize()); + table->field[IS_FILES_MAXIMUM_SIZE]->set_notnull(); + table->field[IS_FILES_MAXIMUM_SIZE]->store(df.getSize()); + table->field[IS_FILES_VERSION]->set_notnull(); + table->field[IS_FILES_VERSION]->store(df.getObjectVersion()); + + table->field[IS_FILES_ROW_FORMAT]->set_notnull(); + table->field[IS_FILES_ROW_FORMAT]->store("FIXED", 5, system_charset_info); char extra[30]; int len= my_snprintf(extra, sizeof(extra), "CLUSTER_NODE=%u", id); - table->field[c]->store(extra, len, system_charset_info); - table->field[c]->set_notnull(); + table->field[IS_FILES_EXTRA]->set_notnull(); + table->field[IS_FILES_EXTRA]->store(extra, len, system_charset_info); schema_table_store_record(thd, table); } } @@ -10624,76 +10662,43 @@ static int ndbcluster_fill_files_table(handlerton *hton, ERR_RETURN(ndberr); } - int c= 0; - table->field[c++]->set_null(); // FILE_ID - table->field[c]->set_notnull(); - table->field[c++]->store(elt.name, strlen(elt.name), - system_charset_info); - table->field[c]->set_notnull(); - table->field[c++]->store("UNDO LOG", 8, system_charset_info); - table->field[c++]->set_null(); // TABLESPACE NAME - table->field[c++]->set_null(); // TABLE_CATALOG - table->field[c++]->set_null(); // TABLE_SCHEMA - table->field[c++]->set_null(); // TABLE_NAME - - // LOGFILE_GROUP_NAME + init_fill_schema_files_row(table); + table->field[IS_FILES_FILE_NAME]->set_notnull(); + table->field[IS_FILES_FILE_NAME]->store(elt.name, strlen(elt.name), + system_charset_info); + table->field[IS_FILES_FILE_TYPE]->set_notnull(); + table->field[IS_FILES_FILE_TYPE]->store("UNDO LOG", 8, + system_charset_info); NdbDictionary::ObjectId objid; uf.getLogfileGroupId(&objid); - table->field[c]->set_notnull(); - table->field[c++]->store(uf.getLogfileGroup(), - strlen(uf.getLogfileGroup()), - system_charset_info); - table->field[c]->set_notnull(); - table->field[c++]->store(objid.getObjectId()); // LOGFILE_GROUP_NUMBER - table->field[c]->set_notnull(); - table->field[c++]->store(ndbcluster_hton_name, - ndbcluster_hton_name_length, - system_charset_info); // ENGINE - - table->field[c++]->set_null(); // FULLTEXT_KEYS - table->field[c++]->set_null(); // DELETED_ROWS - table->field[c++]->set_null(); // UPDATE_COUNT - table->field[c++]->set_null(); // FREE_EXTENTS - table->field[c]->set_notnull(); - table->field[c++]->store(uf.getSize()/4); // TOTAL_EXTENTS - table->field[c]->set_notnull(); - table->field[c++]->store(4); // EXTENT_SIZE - - table->field[c]->set_notnull(); - table->field[c++]->store(uf.getSize()); // INITIAL_SIZE - table->field[c]->set_notnull(); - table->field[c++]->store(uf.getSize()); // MAXIMUM_SIZE - table->field[c++]->set_null(); // AUTOEXTEND_SIZE - - table->field[c++]->set_null(); // CREATION_TIME - table->field[c++]->set_null(); // LAST_UPDATE_TIME - table->field[c++]->set_null(); // LAST_ACCESS_TIME - table->field[c++]->set_null(); // RECOVER_TIME - table->field[c++]->set_null(); // TRANSACTION_COUNTER - - table->field[c]->set_notnull(); - table->field[c++]->store(uf.getObjectVersion()); // VERSION - - table->field[c++]->set_null(); // ROW FORMAT - - table->field[c++]->set_null(); // TABLE_ROWS - table->field[c++]->set_null(); // AVG_ROW_LENGTH - table->field[c++]->set_null(); // DATA_LENGTH - table->field[c++]->set_null(); // MAX_DATA_LENGTH - table->field[c++]->set_null(); // INDEX_LENGTH - table->field[c++]->set_null(); // DATA_FREE - table->field[c++]->set_null(); // CREATE_TIME - table->field[c++]->set_null(); // UPDATE_TIME - table->field[c++]->set_null(); // CHECK_TIME - table->field[c++]->set_null(); // CHECKSUM - - table->field[c]->set_notnull(); - table->field[c++]->store("NORMAL", 6, system_charset_info); + table->field[IS_FILES_LOGFILE_GROUP_NAME]->set_notnull(); + table->field[IS_FILES_LOGFILE_GROUP_NAME]->store(uf.getLogfileGroup(), + strlen(uf.getLogfileGroup()), + system_charset_info); + table->field[IS_FILES_LOGFILE_GROUP_NUMBER]->set_notnull(); + table->field[IS_FILES_LOGFILE_GROUP_NUMBER]->store(objid.getObjectId()); + table->field[IS_FILES_ENGINE]->set_notnull(); + table->field[IS_FILES_ENGINE]->store(ndbcluster_hton_name, + ndbcluster_hton_name_length, + system_charset_info); + + table->field[IS_FILES_TOTAL_EXTENTS]->set_notnull(); + table->field[IS_FILES_TOTAL_EXTENTS]->store(uf.getSize()/4); + table->field[IS_FILES_EXTENT_SIZE]->set_notnull(); + table->field[IS_FILES_EXTENT_SIZE]->store(4); + + table->field[IS_FILES_INITIAL_SIZE]->set_notnull(); + table->field[IS_FILES_INITIAL_SIZE]->store(uf.getSize()); + table->field[IS_FILES_MAXIMUM_SIZE]->set_notnull(); + table->field[IS_FILES_MAXIMUM_SIZE]->store(uf.getSize()); + + table->field[IS_FILES_VERSION]->set_notnull(); + table->field[IS_FILES_VERSION]->store(uf.getObjectVersion()); char extra[100]; int len= my_snprintf(extra,sizeof(extra),"CLUSTER_NODE=%u;UNDO_BUFFER_SIZE=%lu",id,lfg.getUndoBufferSize()); - table->field[c]->set_notnull(); - table->field[c]->store(extra, len, system_charset_info); + table->field[IS_FILES_EXTRA]->set_notnull(); + table->field[IS_FILES_EXTRA]->store(extra, len, system_charset_info); schema_table_store_record(thd, table); } } @@ -10719,69 +10724,36 @@ static int ndbcluster_fill_files_table(handlerton *hton, ERR_RETURN(ndberr); } - int c= 0; - table->field[c++]->set_null(); // FILE_ID - table->field[c++]->set_null(); // name - table->field[c]->set_notnull(); - table->field[c++]->store("UNDO LOG", 8, system_charset_info); - table->field[c++]->set_null(); // TABLESPACE NAME - table->field[c++]->set_null(); // TABLE_CATALOG - table->field[c++]->set_null(); // TABLE_SCHEMA - table->field[c++]->set_null(); // TABLE_NAME - - // LOGFILE_GROUP_NAME - table->field[c]->set_notnull(); - table->field[c++]->store(elt.name, strlen(elt.name), - system_charset_info); - table->field[c]->set_notnull(); - table->field[c++]->store(lfg.getObjectId()); // LOGFILE_GROUP_NUMBER - table->field[c]->set_notnull(); - table->field[c++]->store(ndbcluster_hton_name, - ndbcluster_hton_name_length, - system_charset_info); // ENGINE - - table->field[c++]->set_null(); // FULLTEXT_KEYS - table->field[c++]->set_null(); // DELETED_ROWS - table->field[c++]->set_null(); // UPDATE_COUNT - table->field[c]->set_notnull(); - table->field[c++]->store(lfg.getUndoFreeWords()); // FREE_EXTENTS - table->field[c++]->set_null(); //store(uf.getSize()/4); // TOTAL_EXTENTS - table->field[c]->set_notnull(); - table->field[c++]->store(4); // EXTENT_SIZE - - table->field[c++]->set_null();//store(uf.getSize()); // INITIAL_SIZE - table->field[c++]->set_null(); //store(uf.getSize()); // MAXIMUM_SIZE - table->field[c++]->set_null(); // AUTOEXTEND_SIZE - - table->field[c++]->set_null(); // CREATION_TIME - table->field[c++]->set_null(); // LAST_UPDATE_TIME - table->field[c++]->set_null(); // LAST_ACCESS_TIME - table->field[c++]->set_null(); // RECOVER_TIME - table->field[c++]->set_null(); // TRANSACTION_COUNTER - - table->field[c]->set_notnull(); - table->field[c++]->store(lfg.getObjectVersion()); // VERSION - - table->field[c++]->set_null(); // ROW FORMAT - - table->field[c++]->set_null(); // TABLE_ROWS - table->field[c++]->set_null(); // AVG_ROW_LENGTH - table->field[c++]->set_null(); // DATA_LENGTH - table->field[c++]->set_null(); // MAX_DATA_LENGTH - table->field[c++]->set_null(); // INDEX_LENGTH - table->field[c++]->set_null(); // DATA_FREE - table->field[c++]->set_null(); // CREATE_TIME - table->field[c++]->set_null(); // UPDATE_TIME - table->field[c++]->set_null(); // CHECK_TIME - table->field[c++]->set_null(); // CHECKSUM - - table->field[c]->set_notnull(); - table->field[c++]->store("NORMAL", 6, system_charset_info); + init_fill_schema_files_row(table); + table->field[IS_FILES_FILE_TYPE]->set_notnull(); + table->field[IS_FILES_FILE_TYPE]->store("UNDO LOG", 8, + system_charset_info); + + table->field[IS_FILES_LOGFILE_GROUP_NAME]->set_notnull(); + table->field[IS_FILES_LOGFILE_GROUP_NAME]->store(elt.name, + strlen(elt.name), + system_charset_info); + table->field[IS_FILES_LOGFILE_GROUP_NUMBER]->set_notnull(); + table->field[IS_FILES_LOGFILE_GROUP_NUMBER]->store(lfg.getObjectId()); + table->field[IS_FILES_ENGINE]->set_notnull(); + table->field[IS_FILES_ENGINE]->store(ndbcluster_hton_name, + ndbcluster_hton_name_length, + system_charset_info); + + table->field[IS_FILES_FREE_EXTENTS]->set_notnull(); + table->field[IS_FILES_FREE_EXTENTS]->store(lfg.getUndoFreeWords()); + table->field[IS_FILES_EXTENT_SIZE]->set_notnull(); + table->field[IS_FILES_EXTENT_SIZE]->store(4); + + table->field[IS_FILES_VERSION]->set_notnull(); + table->field[IS_FILES_VERSION]->store(lfg.getObjectVersion()); char extra[100]; - int len= my_snprintf(extra,sizeof(extra),"UNDO_BUFFER_SIZE=%lu",id,lfg.getUndoBufferSize()); - table->field[c]->set_notnull(); - table->field[c]->store(extra, len, system_charset_info); + int len= my_snprintf(extra,sizeof(extra), + "UNDO_BUFFER_SIZE=%lu", + lfg.getUndoBufferSize()); + table->field[IS_FILES_EXTRA]->set_notnull(); + table->field[IS_FILES_EXTRA]->store(extra, len, system_charset_info); schema_table_store_record(thd, table); } DBUG_RETURN(0); diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index 19ff513f9b1..4f0db20d0b0 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -673,7 +673,7 @@ class ha_ndbcluster: public handler bool get_error_message(int error, String *buf); ha_rows records(); - void info(uint); + int info(uint); void get_dynamic_partition_info(PARTITION_INFO *stat_info, uint part_id); int extra(enum ha_extra_function operation); int extra_opt(enum ha_extra_function operation, ulong cache_size); @@ -772,6 +772,12 @@ static void set_tabname(const char *pathname, char *tabname); void cond_pop(); uint8 table_cache_type(); + + /* + * Internal to ha_ndbcluster, used by C functions + */ + int ndb_err(NdbTransaction*); + my_bool register_query_cache_table(THD *thd, char *table_key, uint key_length, qc_engine_callback *engine_callback, @@ -808,7 +814,7 @@ private: NDB_INDEX_TYPE get_index_type_from_table(uint index_no) const; NDB_INDEX_TYPE get_index_type_from_key(uint index_no, KEY *key_info, bool primary) const; - int check_index_fields_not_null(uint index_no); + int check_index_fields_not_null(KEY *key_info); uint set_up_partition_info(partition_info *part_info, TABLE *table, @@ -868,7 +874,6 @@ private: ulonglong nb_desired_values, ulonglong *first_value, ulonglong *nb_reserved_values); - int ndb_err(NdbTransaction*); bool uses_blob_value(); char *update_table_comment(const char * comment); @@ -878,7 +883,7 @@ private: int check_ndb_connection(THD* thd= current_thd); void set_rec_per_key(); - void records_update(); + int records_update(); void no_uncommitted_rows_execute_failure(); void no_uncommitted_rows_update(int); void no_uncommitted_rows_reset(THD *); diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 713be1b7b5d..3edd3923779 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -4241,7 +4241,7 @@ void ha_partition::include_partition_fields_in_used_fields() retrieving statistics data. */ -void ha_partition::info(uint flag) +int ha_partition::info(uint flag) { handler *file, **file_array; DBUG_ENTER("ha_partition:info"); @@ -4405,7 +4405,7 @@ void ha_partition::info(uint flag) stats.update_time= file->stats.update_time; } while (*(++file_array)); } - DBUG_VOID_RETURN; + DBUG_RETURN(0); } diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 008bda01bc9..c0c99a7a82b 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -450,7 +450,7 @@ public: purposes. ------------------------------------------------------------------------- */ - virtual void info(uint); + virtual int info(uint); void get_dynamic_partition_info(PARTITION_INFO *stat_info, uint part_id); virtual int extra(enum ha_extra_function operation); diff --git a/sql/handler.cc b/sql/handler.cc index fc8bc939961..31d13dd03a3 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1483,8 +1483,9 @@ bool handler::check_if_log_table_locking_is_allowed(uint sql_command, { /* Deny locking of the log tables, which is incompatible with - concurrent insert. Unless called from a logger THD: - general_log_thd or slow_log_thd. + concurrent insert. The routine is not called if the table is + being locked from a logger THD (general_log_thd or slow_log_thd) + or from a privileged thread (see log.cc for details) */ if (table->s->log_table && sql_command != SQLCOM_TRUNCATE && @@ -2031,16 +2032,27 @@ void handler::print_keydup_error(uint key_nr, const char *msg) /* Write the duplicated key in the error message */ char key[MAX_KEY_LENGTH]; String str(key,sizeof(key),system_charset_info); - /* Table is opened and defined at this point */ - key_unpack(&str,table,(uint) key_nr); - uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg); - if (str.length() >= max_length) + + if (key_nr == MAX_KEY) + { + /* Key is unknown */ + str.copy("", 0, system_charset_info); + my_printf_error(ER_DUP_ENTRY, msg, + MYF(0), str.c_ptr(), "*UNKNOWN*"); + } + else { - str.length(max_length-4); - str.append(STRING_WITH_LEN("...")); + /* Table is opened and defined at this point */ + key_unpack(&str,table,(uint) key_nr); + uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg); + if (str.length() >= max_length) + { + str.length(max_length-4); + str.append(STRING_WITH_LEN("...")); + } + my_printf_error(ER_DUP_ENTRY, msg, + MYF(0), str.c_ptr(), table->key_info[key_nr].name); } - my_printf_error(ER_DUP_ENTRY, msg, - MYF(0), str.c_ptr(), table->key_info[key_nr].name); } diff --git a/sql/handler.h b/sql/handler.h index 5e26d9c7b63..1756693ed3d 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -975,6 +975,10 @@ public: thd Handler of the thread, trying to lock the table table Table handler to check count Number of locks already granted to the table + called_by_privileged_thread TRUE if called from a logger THD + (general_log_thd or slow_log_thd) + or by a privileged thread, which + has the right to lock log tables. DESCRIPTION Check whether a handler allows to lock the table. For instance, @@ -990,7 +994,7 @@ public: virtual bool check_if_locking_is_allowed(uint sql_command, ulong type, TABLE *table, uint count, - bool called_by_logger_thread) + bool called_by_privileged_thread) { return TRUE; } @@ -1243,7 +1247,7 @@ public: key_range *max_key) { return (ha_rows) 10; } virtual void position(const byte *record)=0; - virtual void info(uint)=0; // see my_base.h for full description + virtual int info(uint)=0; // see my_base.h for full description virtual void get_dynamic_partition_info(PARTITION_INFO *stat_info, uint part_id); virtual int extra(enum ha_extra_function operation) diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 7a82dd753b3..bf837f6720b 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2965,6 +2965,7 @@ String *Item_func_compress::val_str(String *str) null_value= 1; return 0; } + null_value= 0; if (res->is_empty()) return res; /* diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 73e2c5e6935..b2ff62028c1 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1065,6 +1065,7 @@ longlong Item_sum_count::val_int() void Item_sum_count::cleanup() { DBUG_ENTER("Item_sum_count::cleanup"); + count= 0; Item_sum_int::cleanup(); used_table_cache= ~(table_map) 0; DBUG_VOID_RETURN; @@ -2693,6 +2694,7 @@ bool Item_sum_count_distinct::add() longlong Item_sum_count_distinct::val_int() { + int error; DBUG_ASSERT(fixed == 1); if (!table) // Empty query return LL(0); @@ -2706,7 +2708,14 @@ longlong Item_sum_count_distinct::val_int() tree->walk(count_distinct_walk, (void*) &count); return (longlong) count; } - table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); + + error= table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); + + if(error) + { + table->file->print_error(error, MYF(0)); + } + return table->file->stats.records; } diff --git a/sql/item_sum.h b/sql/item_sum.h index 3679780db60..eb4c21bbe06 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -260,9 +260,30 @@ public: Item_sum(THD *thd, Item_sum *item); enum Type type() const { return SUM_FUNC_ITEM; } virtual enum Sumfunctype sum_func () const=0; + + /* + This method is similar to add(), but it is called when the current + aggregation group changes. Thus it performs a combination of + clear() and add(). + */ inline bool reset() { clear(); return add(); }; + + /* + Prepare this item for evaluation of an aggregate value. This is + called by reset() when a group changes, or, for correlated + subqueries, between subquery executions. E.g. for COUNT(), this + method should set count= 0; + */ virtual void clear()= 0; + + /* + This method is called for the next row in the same group. Its + purpose is to aggregate the new value to the previous values in + the group (i.e. since clear() was called last time). For example, + for COUNT(), do count++. + */ virtual bool add()=0; + /* Called when new group is started and results are being saved in a temporary table. Similar to reset(), but must also store value in @@ -306,7 +327,17 @@ public: void make_field(Send_field *field); void print(String *str); void fix_num_length_and_dec(); - void no_rows_in_result() { reset(); } + + /* + This function is called by the execution engine to assign 'NO ROWS + FOUND' value to an aggregate item, when the underlying result set + has no rows. Such value, in a general case, may be different from + the default value of the item after 'clear()': e.g. a numeric item + may be initialized to 0 by clear() and to NULL by + no_rows_in_result(). + */ + void no_rows_in_result() { clear(); } + virtual bool setup(THD *thd) {return 0;} virtual void make_unique() {} Item *get_tmp_table_item(THD *thd); @@ -610,6 +641,11 @@ public: const char *func_name() const { return "avg("; } Item *copy_or_same(THD* thd); Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length); + void cleanup() + { + count= 0; + Item_sum_sum::cleanup(); + } }; class Item_sum_variance; @@ -689,6 +725,12 @@ public: Item *copy_or_same(THD* thd); Field *create_tmp_field(bool group, TABLE *table, uint convert_blob_length); enum Item_result result_type () const { return REAL_RESULT; } + void cleanup() + { + cur_dec= 0; + count= 0; + Item_sum_num::cleanup(); + } }; class Item_sum_std; @@ -819,6 +861,11 @@ public: void update_field(); void fix_length_and_dec() { decimals= 0; max_length=21; unsigned_flag= 1; maybe_null= null_value= 0; } + void cleanup() + { + bits= reset_bits; + Item_sum_int::cleanup(); + } }; diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index d32adde5e64..f378e5037dc 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -96,6 +96,125 @@ static bool make_datetime(date_time_format_types format, TIME *ltime, /* + Wrapper over make_datetime() with validation of the input TIME value + + NOTE + see make_datetime() for more information + + RETURN + 1 if there was an error during converion + 0 otherwise +*/ + +static bool make_datetime_with_warn(date_time_format_types format, TIME *ltime, + String *str) +{ + int warning= 0; + bool rc; + + if (make_datetime(format, ltime, str)) + return 1; + if (check_time_range(ltime, &warning)) + return 1; + if (!warning) + return 0; + + make_truncated_value_warning(current_thd, str->ptr(), str->length(), + MYSQL_TIMESTAMP_TIME, NullS); + return make_datetime(format, ltime, str); +} + + +/* + Wrapper over make_time() with validation of the input TIME value + + NOTE + see make_time() for more info + + RETURN + 1 if there was an error during conversion + 0 otherwise +*/ + +static bool make_time_with_warn(const DATE_TIME_FORMAT *format, + TIME *l_time, String *str) +{ + int warning= 0; + make_time(format, l_time, str); + if (check_time_range(l_time, &warning)) + return 1; + if (warning) + { + make_truncated_value_warning(current_thd, str->ptr(), str->length(), + MYSQL_TIMESTAMP_TIME, NullS); + make_time(format, l_time, str); + } + + return 0; +} + + +/* + Convert seconds to TIME value with overflow checking + + SYNOPSIS: + sec_to_time() + seconds number of seconds + unsigned_flag 1, if 'seconds' is unsigned, 0, otherwise + ltime output TIME value + + DESCRIPTION + If the 'seconds' argument is inside TIME data range, convert it to a + corresponding value. + Otherwise, truncate the resulting value to the nearest endpoint, and + produce a warning message. + + RETURN + 1 if the value was truncated during conversion + 0 otherwise +*/ + +static bool sec_to_time(longlong seconds, bool unsigned_flag, TIME *ltime) +{ + uint sec; + + bzero((char *)ltime, sizeof(*ltime)); + + if (seconds < 0) + { + if (unsigned_flag) + goto overflow; + ltime->neg= 1; + if (seconds < -3020399) + goto overflow; + seconds= -seconds; + } + else if (seconds > 3020399) + goto overflow; + + sec= (uint) ((ulonglong) seconds % 3600); + ltime->hour= (uint) (seconds/3600); + ltime->minute= sec/60; + ltime->second= sec % 60; + + return 0; + +overflow: + ltime->hour= TIME_MAX_HOUR; + ltime->minute= TIME_MAX_MINUTE; + ltime->second= TIME_MAX_SECOND; + + char buf[22]; + int len= (int)(longlong10_to_str(seconds, buf, unsigned_flag ? 10 : -10) + - buf); + make_truncated_value_warning(current_thd, buf, len, MYSQL_TIMESTAMP_TIME, + NullS); + + return 1; +} + + +/* Date formats corresponding to compound %r and %T conversion specifiers Note: We should init at least first element of "positions" array @@ -1546,8 +1665,6 @@ int Item_func_sysdate_local::save_in_field(Field *to, bool no_conversions) String *Item_func_sec_to_time::val_str(String *str) { DBUG_ASSERT(fixed == 1); - longlong seconds=(longlong) args[0]->val_int(); - uint sec; TIME ltime; if ((null_value=args[0]->null_value) || str->alloc(19)) @@ -1556,19 +1673,8 @@ String *Item_func_sec_to_time::val_str(String *str) return (String*) 0; } - ltime.neg= 0; - if (seconds < 0) - { - seconds= -seconds; - ltime.neg= 1; - } - - sec= (uint) ((ulonglong) seconds % 3600); - ltime.day= 0; - ltime.hour= (uint) (seconds/3600); - ltime.minute= sec/60; - ltime.second= sec % 60; - + sec_to_time(args[0]->val_int(), args[0]->unsigned_flag, <ime); + make_time((DATE_TIME_FORMAT *) 0, <ime, str); return str; } @@ -1577,16 +1683,15 @@ String *Item_func_sec_to_time::val_str(String *str) longlong Item_func_sec_to_time::val_int() { DBUG_ASSERT(fixed == 1); - longlong seconds=args[0]->val_int(); - longlong sign=1; + TIME ltime; + if ((null_value=args[0]->null_value)) return 0; - if (seconds < 0) - { - seconds= -seconds; - sign= -1; - } - return sign*((seconds / 3600)*10000+((seconds/60) % 60)*100+ (seconds % 60)); + + sec_to_time(args[0]->val_int(), args[0]->unsigned_flag, <ime); + + return (ltime.neg ? -1 : 1) * + ((ltime.hour)*10000 + ltime.minute*100 + ltime.second); } @@ -2030,11 +2135,15 @@ bool Item_date_add_interval::eq(const Item *item, bool binary_cmp) const (date_sub_interval == other->date_sub_interval)); } +/* + 'interval_names' reflects the order of the enumeration interval_type. + See item_timefunc.h + */ static const char *interval_names[]= { - "year", "quarter", "month", "day", "hour", - "minute", "week", "second", "microsecond", + "year", "quarter", "month", "week", "day", + "hour", "minute", "second", "microsecond", "year_month", "day_hour", "day_minute", "day_second", "hour_minute", "hour_second", "minute_second", "day_microsecond", @@ -2571,7 +2680,9 @@ String *Item_func_add_time::val_str(String *str) } if (l_time1.neg != l_time2.neg) l_sign= -l_sign; - + + bzero((char *)&l_time3, sizeof(l_time3)); + l_time3.neg= calc_time_diff(&l_time1, &l_time2, -l_sign, &seconds, µseconds); @@ -2600,9 +2711,9 @@ String *Item_func_add_time::val_str(String *str) } l_time3.hour+= days*24; - if (!make_datetime(l_time1.second_part || l_time2.second_part ? - TIME_MICROSECOND : TIME_ONLY, - &l_time3, str)) + if (!make_datetime_with_warn(l_time1.second_part || l_time2.second_part ? + TIME_MICROSECOND : TIME_ONLY, + &l_time3, str)) return str; null_date: @@ -2657,6 +2768,8 @@ String *Item_func_timediff::val_str(String *str) if (l_time1.neg != l_time2.neg) l_sign= -l_sign; + bzero((char *)&l_time3, sizeof(l_time3)); + l_time3.neg= calc_time_diff(&l_time1, &l_time2, l_sign, &seconds, µseconds); @@ -2670,9 +2783,9 @@ String *Item_func_timediff::val_str(String *str) calc_time_from_sec(&l_time3, (long) seconds, microseconds); - if (!make_datetime(l_time1.second_part || l_time2.second_part ? - TIME_MICROSECOND : TIME_ONLY, - &l_time3, str)) + if (!make_datetime_with_warn(l_time1.second_part || l_time2.second_part ? + TIME_MICROSECOND : TIME_ONLY, + &l_time3, str)) return str; null_date: @@ -2690,29 +2803,58 @@ String *Item_func_maketime::val_str(String *str) { DBUG_ASSERT(fixed == 1); TIME ltime; + bool overflow= 0; - long hour= (long) args[0]->val_int(); - long minute= (long) args[1]->val_int(); - long second= (long) args[2]->val_int(); + longlong hour= args[0]->val_int(); + longlong minute= args[1]->val_int(); + longlong second= args[2]->val_int(); if ((null_value=(args[0]->null_value || - args[1]->null_value || - args[2]->null_value || - minute > 59 || minute < 0 || - second > 59 || second < 0 || - str->alloc(19)))) + args[1]->null_value || + args[2]->null_value || + minute < 0 || minute > 59 || + second < 0 || second > 59 || + str->alloc(19)))) return 0; + bzero((char *)<ime, sizeof(ltime)); ltime.neg= 0; + + /* Check for integer overflows */ if (hour < 0) { - ltime.neg= 1; - hour= -hour; + if (args[0]->unsigned_flag) + overflow= 1; + else + ltime.neg= 1; + } + if (-hour > UINT_MAX || hour > UINT_MAX) + overflow= 1; + + if (!overflow) + { + ltime.hour= (uint) ((hour < 0 ? -hour : hour)); + ltime.minute= (uint) minute; + ltime.second= (uint) second; + } + else + { + ltime.hour= TIME_MAX_HOUR; + ltime.minute= TIME_MAX_MINUTE; + ltime.second= TIME_MAX_SECOND; + char buf[28]; + char *ptr= longlong10_to_str(hour, buf, args[0]->unsigned_flag ? 10 : -10); + int len = (int)(ptr - buf) + + my_sprintf(ptr, (ptr, ":%02u:%02u", (uint)minute, (uint)second)); + make_truncated_value_warning(current_thd, buf, len, MYSQL_TIMESTAMP_TIME, + NullS); + } + + if (make_time_with_warn((DATE_TIME_FORMAT *) 0, <ime, str)) + { + null_value= 1; + return 0; } - ltime.hour= (ulong) hour; - ltime.minute= (ulong) minute; - ltime.second= (ulong) second; - make_time((DATE_TIME_FORMAT *) 0, <ime, str); return str; } @@ -3056,7 +3198,7 @@ bool Item_func_str_to_date::get_date(TIME *ltime, uint fuzzy_date) goto null_date; null_value= 0; - bzero((char*) ltime, sizeof(ltime)); + bzero((char*) ltime, sizeof(*ltime)); date_time_format.format.str= (char*) format->ptr(); date_time_format.format.length= format->length(); if (extract_date_time(&date_time_format, val->ptr(), val->length(), diff --git a/sql/lex.h b/sql/lex.h index f19c9413e0e..711becc123f 100644 --- a/sql/lex.h +++ b/sql/lex.h @@ -45,6 +45,10 @@ SYM_GROUP sym_group_rtree= {"RTree keys", "HAVE_RTREE_KEYS"}; Symbols are broken into separated arrays to allow field names with same name as functions. These are kept sorted for human lookup (the symbols are hashed). + + NOTE! The symbol tables should be the same regardless of what features + are compiled into the server. Don't add ifdef'ed symbols to the + lists */ static SYMBOL symbols[] = { @@ -383,11 +387,9 @@ static SYMBOL symbols[] = { { "PACK_KEYS", SYM(PACK_KEYS_SYM)}, { "PARSER", SYM(PARSER_SYM)}, { "PARTIAL", SYM(PARTIAL)}, -#ifdef WITH_PARTITION_STORAGE_ENGINE { "PARTITION", SYM(PARTITION_SYM)}, { "PARTITIONING", SYM(PARTITIONING_SYM)}, { "PARTITIONS", SYM(PARTITIONS_SYM)}, -#endif { "PASSWORD", SYM(PASSWORD)}, { "PHASE", SYM(PHASE_SYM)}, { "PLUGIN", SYM(PLUGIN_SYM)}, diff --git a/sql/lock.cc b/sql/lock.cc index 06f538a2a03..f36ecf58620 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -691,7 +691,8 @@ static MYSQL_LOCK *get_lock_data(THD *thd, TABLE **table_ptr, uint count, check_if_locking_is_allowed(thd->lex->sql_command, thd->lex->type, table_ptr[i], count, (thd == logger.get_general_log_thd()) || - (thd == logger.get_slow_log_thd()))) + (thd == logger.get_slow_log_thd()) || + (thd == logger.get_privileged_thread()))) DBUG_RETURN(0); } diff --git a/sql/log.cc b/sql/log.cc index 9ca71fa74d0..571b9a8f63e 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -173,6 +173,33 @@ public: handlerton *binlog_hton; + +/* Check if a given table is opened log table */ +int check_if_log_table(uint db_len, const char *db, uint table_name_len, + const char *table_name, uint check_if_opened) +{ + if (db_len == 5 && + !(lower_case_table_names ? + my_strcasecmp(system_charset_info, db, "mysql") : + strcmp(db, "mysql"))) + { + if (table_name_len == 11 && !(lower_case_table_names ? + my_strcasecmp(system_charset_info, + table_name, "general_log") : + strcmp(table_name, "general_log")) && + (!check_if_opened || logger.is_log_table_enabled(QUERY_LOG_GENERAL))) + return QUERY_LOG_GENERAL; + else + if (table_name_len == 8 && !(lower_case_table_names ? + my_strcasecmp(system_charset_info, table_name, "slow_log") : + strcmp(table_name, "slow_log")) && + (!check_if_opened ||logger.is_log_table_enabled(QUERY_LOG_SLOW))) + return QUERY_LOG_SLOW; + } + return 0; +} + + /* Open log table of a given type (general or slow log) @@ -273,6 +300,12 @@ bool Log_to_csv_event_handler::open_log_table(uint log_table_type) my_pthread_setspecific_ptr(THR_MALLOC, 0); } + /* + After a log table was opened, we should clear privileged thread + flag (which allows locking of a log table by a special thread, usually + the one who closed log tables temporarily). + */ + privileged_thread= 0; DBUG_RETURN(error); } @@ -284,11 +317,15 @@ Log_to_csv_event_handler::Log_to_csv_event_handler() /* logger thread always works with mysql database */ general_log_thd->db= my_strdup("mysql", MYF(0)); general_log_thd->db_length= 5; + general_log.table= 0; slow_log_thd= new THD; /* logger thread always works with mysql database */ slow_log_thd->db= my_strdup("mysql", MYF(0));; slow_log_thd->db_length= 5; + slow_log.table= 0; + /* no privileged thread exists at the moment */ + privileged_thread= 0; } @@ -341,6 +378,7 @@ bool Log_to_csv_event_handler::reopen_log_table(uint log_table_type) return open_log_table(log_table_type); } + void Log_to_csv_event_handler::cleanup() { if (opt_log) @@ -407,9 +445,6 @@ bool Log_to_csv_event_handler:: filled by the Logger (=> no need to load default ones). */ - /* log table entries are not replicated at the moment */ - tmp_disable_binlog(current_thd); - /* Set current time. Required for CURRENT_TIMESTAMP to work */ general_log_thd->start_time= event_time; @@ -418,21 +453,36 @@ bool Log_to_csv_event_handler:: default value (which is CURRENT_TIMESTAMP). */ - table->field[1]->store(user_host, user_host_len, client_cs); + /* check that all columns exist */ + if (!table->field[1] || !table->field[2] || !table->field[3] || + !table->field[4] || !table->field[5]) + goto err; + + /* do a write */ + if (table->field[1]->store(user_host, user_host_len, client_cs) || + table->field[2]->store((longlong) thread_id, TRUE) || + table->field[3]->store((longlong) server_id, TRUE) || + table->field[4]->store(command_type, command_type_len, client_cs) || + table->field[5]->store(sql_text, sql_text_len, client_cs)) + goto err; + + /* mark tables as not null */ table->field[1]->set_notnull(); - table->field[2]->store((longlong) thread_id, TRUE); table->field[2]->set_notnull(); - table->field[3]->store((longlong) server_id, TRUE); table->field[3]->set_notnull(); - table->field[4]->store(command_type, command_type_len, client_cs); table->field[4]->set_notnull(); - table->field[5]->store(sql_text, sql_text_len, client_cs); table->field[5]->set_notnull(); + + /* log table entries are not replicated at the moment */ + tmp_disable_binlog(current_thd); + table->file->ha_write_row(table->record[0]); reenable_binlog(current_thd); return FALSE; +err: + return TRUE; } @@ -481,9 +531,6 @@ bool Log_to_csv_event_handler:: if (unlikely(!logger.is_log_tables_initialized)) return FALSE; - /* log table entries are not replicated at the moment */ - tmp_disable_binlog(current_thd); - /* Set start time for CURRENT_TIMESTAMP to the start of the query. This will be default value for the field[0] @@ -496,19 +543,30 @@ bool Log_to_csv_event_handler:: default value. */ + if (!table->field[1] || !table->field[2] || !table->field[3] || + !table->field[4] || !table->field[5] || !table->field[6] || + !table->field[7] || !table->field[8] || !table->field[9] || + !table->field[10]) + goto err; + /* store the value */ - table->field[1]->store(user_host, user_host_len, client_cs); + if (table->field[1]->store(user_host, user_host_len, client_cs)) + goto err; if (query_start_arg) { /* fill in query_time field */ - table->field[2]->store(query_time, TRUE); + if (table->field[2]->store(query_time, TRUE)) + goto err; /* lock_time */ - table->field[3]->store(lock_time, TRUE); + if (table->field[3]->store(lock_time, TRUE)) + goto err; /* rows_sent */ - table->field[4]->store((longlong) thd->sent_row_count, TRUE); + if (table->field[4]->store((longlong) thd->sent_row_count, TRUE)) + goto err; /* rows_examined */ - table->field[5]->store((longlong) thd->examined_row_count, TRUE); + if (table->field[5]->store((longlong) thd->examined_row_count, TRUE)) + goto err; } else { @@ -521,14 +579,18 @@ bool Log_to_csv_event_handler:: /* fill database field */ if (thd->db) { - table->field[6]->store(thd->db, thd->db_length, client_cs); + if (table->field[6]->store(thd->db, thd->db_length, client_cs)) + goto err; table->field[6]->set_notnull(); } if (thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt) { - table->field[7]->store((longlong) - thd->first_successful_insert_id_in_prev_stmt_for_binlog, TRUE); + if (table-> + field[7]->store((longlong) + thd->first_successful_insert_id_in_prev_stmt_for_binlog, + TRUE)) + goto err; table->field[7]->set_notnull(); } @@ -540,16 +602,23 @@ bool Log_to_csv_event_handler:: */ if (thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements() > 0) { - table->field[8]->store((longlong) - thd->auto_inc_intervals_in_cur_stmt_for_binlog.minimum(), TRUE); + if (table-> + field[8]->store((longlong) + thd->auto_inc_intervals_in_cur_stmt_for_binlog.minimum(), TRUE)) + goto err; table->field[8]->set_notnull(); } - table->field[9]->store((longlong) server_id, TRUE); + if (table->field[9]->store((longlong) server_id, TRUE)) + goto err; table->field[9]->set_notnull(); /* sql_text */ - table->field[10]->store(sql_text,sql_text_len, client_cs); + if (table->field[10]->store(sql_text,sql_text_len, client_cs)) + goto err; + + /* log table entries are not replicated at the moment */ + tmp_disable_binlog(current_thd); /* write the row */ table->file->ha_write_row(table->record[0]); @@ -557,6 +626,8 @@ bool Log_to_csv_event_handler:: reenable_binlog(current_thd); DBUG_RETURN(0); +err: + DBUG_RETURN(1); } bool Log_to_csv_event_handler:: @@ -745,61 +816,48 @@ bool LOGGER::reopen_log_table(uint log_table_type) return table_log_handler->reopen_log_table(log_table_type); } - -bool LOGGER::flush_logs(THD *thd) +bool LOGGER::reopen_log_tables() { - TABLE_LIST close_slow_log, close_general_log; + /* + we use | and not || here, to ensure that both reopen_log_table + are called, even if the first one fails + */ + if ((opt_slow_log && logger.reopen_log_table(QUERY_LOG_SLOW)) | + (opt_log && logger.reopen_log_table(QUERY_LOG_GENERAL))) + return TRUE; + return FALSE; +} - /* reopen log tables */ - bzero((char*) &close_slow_log, sizeof(TABLE_LIST)); - close_slow_log.alias= close_slow_log.table_name=(char*) "slow_log"; - close_slow_log.table_name_length= 8; - close_slow_log.db= (char*) "mysql"; - close_slow_log.db_length= 5; - bzero((char*) &close_general_log, sizeof(TABLE_LIST)); - close_general_log.alias= close_general_log.table_name=(char*) "general_log"; - close_general_log.table_name_length= 11; - close_general_log.db= (char*) "mysql"; - close_general_log.db_length= 5; +void LOGGER::tmp_close_log_tables(THD *thd) +{ + table_log_handler->tmp_close_log_tables(thd); +} - /* lock tables, in the case they are enabled */ - if (logger.is_log_tables_initialized) - { - /* - This will lock and wait for all but the logger thread to release the - tables. Then we could reopen log tables. Then release the name locks. - - NOTE: in fact, the first parameter used in lock_and_wait_for_table_name() - and table_log_handler->flush() could be any non-NULL THD, as the - underlying code makes certain assumptions about this. - Here we use one of the logger handler THD's. Simply because it - seems appropriate. - */ - if (opt_slow_log) - lock_and_wait_for_table_name(table_log_handler->general_log_thd, - &close_slow_log); - if (opt_log) - lock_and_wait_for_table_name(table_log_handler->general_log_thd, - &close_general_log); - } +bool LOGGER::flush_logs(THD *thd) +{ + int rc= 0; /* - Deny others from logging to general and slow log, - while reopening tables. + Now we lock logger, as nobody should be able to use logging routines while + log tables are closed */ logger.lock(); + if (logger.is_log_tables_initialized) + table_log_handler->tmp_close_log_tables(thd); // the locking happens here /* reopen log files */ file_log_handler->flush(); - /* flush tables, in the case they are enabled */ + /* reopen tables in the case they were enabled */ if (logger.is_log_tables_initialized) - table_log_handler->flush(table_log_handler->general_log_thd, - &close_slow_log, &close_general_log); + { + if (reopen_log_tables()) + rc= TRUE; + } /* end of log flush */ logger.unlock(); - return FALSE; + return rc; } @@ -1107,31 +1165,50 @@ void LOGGER::deactivate_log_handler(THD *thd, uint log_type) } -bool Log_to_csv_event_handler::flush(THD *thd, TABLE_LIST *close_slow_log, - TABLE_LIST *close_general_log) +/* + Close log tables temporarily. The thread which closed + them this way can lock them in any mode it needs. + NOTE: one should call logger.lock() before entering this + function. +*/ +void Log_to_csv_event_handler::tmp_close_log_tables(THD *thd) { + TABLE_LIST close_slow_log, close_general_log; + + /* fill lists, we will need to perform operations on tables */ + bzero((char*) &close_slow_log, sizeof(TABLE_LIST)); + close_slow_log.alias= close_slow_log.table_name=(char*) "slow_log"; + close_slow_log.table_name_length= 8; + close_slow_log.db= (char*) "mysql"; + close_slow_log.db_length= 5; + + bzero((char*) &close_general_log, sizeof(TABLE_LIST)); + close_general_log.alias= close_general_log.table_name=(char*) "general_log"; + close_general_log.table_name_length= 11; + close_general_log.db= (char*) "mysql"; + close_general_log.db_length= 5; + + privileged_thread= thd; + VOID(pthread_mutex_lock(&LOCK_open)); + /* + NOTE: in fact, the first parameter used in query_cache_invalidate3() + could be any non-NULL THD, as the underlying code makes certain + assumptions about this. + Here we use one of the logger handler THD's. Simply because it + seems appropriate. + */ if (opt_log) { close_log_table(QUERY_LOG_GENERAL, TRUE); - query_cache_invalidate3(thd, close_general_log, 0); - unlock_table_name(thd, close_general_log); + query_cache_invalidate3(general_log_thd, &close_general_log, 0); } if (opt_slow_log) { close_log_table(QUERY_LOG_SLOW, TRUE); - query_cache_invalidate3(thd, close_slow_log, 0); - unlock_table_name(thd, close_slow_log); + query_cache_invalidate3(general_log_thd, &close_slow_log, 0); } VOID(pthread_mutex_unlock(&LOCK_open)); - /* - we use | and not || here, to ensure that both reopen_log_table - are called, even if the first one fails - */ - if ((opt_slow_log && reopen_log_table(QUERY_LOG_SLOW)) | - (opt_log && reopen_log_table(QUERY_LOG_GENERAL))) - return 1; - return 0; } /* the parameters are unused for the log tables */ @@ -1199,16 +1276,15 @@ void Log_to_csv_event_handler:: THD *log_thd, *curr= current_thd; TABLE_LIST *table; + if (!logger.is_log_table_enabled(log_table_type)) + return; /* do nothing */ + switch (log_table_type) { case QUERY_LOG_GENERAL: - if (!logger.is_general_log_table_enabled()) - return; /* do nothing */ log_thd= general_log_thd; table= &general_log; break; case QUERY_LOG_SLOW: - if (!logger.is_slow_log_table_enabled()) - return; /* do nothing */ log_thd= slow_log_thd; table= &slow_log; break; diff --git a/sql/log.h b/sql/log.h index 8f75601f02b..f39b52f5db2 100644 --- a/sql/log.h +++ b/sql/log.h @@ -404,6 +404,9 @@ public: }; +int check_if_log_table(uint db_len, const char *db, uint table_name_len, + const char *table_name, uint check_if_opened); + class Log_to_csv_event_handler: public Log_event_handler { /* @@ -412,6 +415,16 @@ class Log_to_csv_event_handler: public Log_event_handler THD's of the query. The reason is the locking order and duration. */ THD *general_log_thd, *slow_log_thd; + /* + This is for the thread, which called tmp_close_log_tables. The thread + will be allowed to write-lock the log tables (as it explicitly disabled + logging). This is used for such operations as REPAIR, which require + exclusive lock on the log tables. + NOTE: there can be only one priviliged thread, as one should + lock logger with logger.lock() before calling tmp_close_log_tables(). + So no other thread could get privileged status at the same time. + */ + THD *privileged_thread; friend class LOGGER; TABLE_LIST general_log, slow_log; @@ -436,13 +449,20 @@ public: const char *command_type, uint command_type_len, const char *sql_text, uint sql_text_len, CHARSET_INFO *client_cs); - bool flush(THD *thd, TABLE_LIST *close_slow_Log, - TABLE_LIST* close_general_log); + void tmp_close_log_tables(THD *thd); void close_log_table(uint log_type, bool lock_in_use); bool reopen_log_table(uint log_type); + THD* get_privileged_thread() + { + return privileged_thread; + } }; +/* type of the log table */ +#define QUERY_LOG_SLOW 1 +#define QUERY_LOG_GENERAL 2 + class Log_to_file_event_handler: public Log_event_handler { MYSQL_QUERY_LOG mysql_log; @@ -498,13 +518,18 @@ public: {} void lock() { (void) pthread_mutex_lock(&LOCK_logger); } void unlock() { (void) pthread_mutex_unlock(&LOCK_logger); } - bool is_general_log_table_enabled() + void tmp_close_log_tables(THD *thd); + bool is_log_table_enabled(uint log_table_type) { - return table_log_handler && table_log_handler->general_log.table != 0; - } - bool is_slow_log_table_enabled() - { - return table_log_handler && table_log_handler->slow_log.table != 0; + switch (log_table_type) { + case QUERY_LOG_SLOW: + return table_log_handler && table_log_handler->slow_log.table != 0; + case QUERY_LOG_GENERAL: + return table_log_handler && table_log_handler->general_log.table != 0; + default: + DBUG_ASSERT(0); + return FALSE; /* make compiler happy */ + } } /* We want to initialize all log mutexes as soon as possible, @@ -542,6 +567,7 @@ public: void close_log_table(uint log_type, bool lock_in_use); bool reopen_log_table(uint log_type); + bool reopen_log_tables(); /* we use this function to setup all enabled log event handlers */ int set_handlers(uint error_log_printer, @@ -564,6 +590,13 @@ public: return file_log_handler->get_mysql_log(); return NULL; } + THD* get_privileged_thread() + { + if (table_log_handler) + return table_log_handler->get_privileged_thread(); + else + return NULL; + } }; enum enum_binlog_format { diff --git a/sql/log_event.cc b/sql/log_event.cc index d62d8738eba..bf5bdd7a057 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -7127,8 +7127,8 @@ int Update_rows_log_event::do_prepare_row(THD *thd, RELAY_LOG_INFO *rli, row_start, &m_cols, row_end, &m_master_reclength, table->write_set, UPDATE_ROWS_EVENT); - DBUG_DUMP("record[0]", (char *)table->record[0], table->s->reclength); - DBUG_DUMP("m_after_image", (char *)m_after_image, table->s->reclength); + DBUG_DUMP("record[0]", (const char *)table->record[0], table->s->reclength); + DBUG_DUMP("m_after_image", (const char *)m_after_image, table->s->reclength); /* diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index b7ef2cd97df..81931f6e8f2 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -140,6 +140,8 @@ MY_LOCALE *my_locale_by_name(const char *name); #define MAX_ACCEPT_RETRY 10 // Test accept this many times #define MAX_FIELDS_BEFORE_HASH 32 #define USER_VARS_HASH_SIZE 16 +#define TABLE_OPEN_CACHE_MIN 64 +#define TABLE_OPEN_CACHE_DEFAULT 64 /* Value of 9236 discovered through binary search 2006-09-26 on Ubuntu Dapper @@ -1451,10 +1453,6 @@ typedef void (*sql_print_message_func)(const char *format, ...) ATTRIBUTE_FORMAT(printf, 1, 2); extern sql_print_message_func sql_print_message_handlers[]; -/* type of the log table */ -#define QUERY_LOG_SLOW 1 -#define QUERY_LOG_GENERAL 2 - int error_log_print(enum loglevel level, const char *format, va_list args); @@ -1485,6 +1483,8 @@ uint find_type2(TYPELIB *lib, const char *find, uint length, CHARSET_INFO *cs); void unhex_type2(TYPELIB *lib); uint check_word(TYPELIB *lib, const char *val, const char *end, const char **end_of_word); +int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle, + CHARSET_INFO * const cs); bool is_keyword(const char *name, uint len); @@ -2011,6 +2011,45 @@ inline void kill_delayed_threads(void) {} #endif /* Used by handlers to store things in schema tables */ +#define IS_FILES_FILE_ID 0 +#define IS_FILES_FILE_NAME 1 +#define IS_FILES_FILE_TYPE 2 +#define IS_FILES_TABLESPACE_NAME 3 +#define IS_FILES_TABLE_CATALOG 4 +#define IS_FILES_TABLE_SCHEMA 5 +#define IS_FILES_TABLE_NAME 6 +#define IS_FILES_LOGFILE_GROUP_NAME 7 +#define IS_FILES_LOGFILE_GROUP_NUMBER 8 +#define IS_FILES_ENGINE 9 +#define IS_FILES_FULLTEXT_KEYS 10 +#define IS_FILES_DELETED_ROWS 11 +#define IS_FILES_UPDATE_COUNT 12 +#define IS_FILES_FREE_EXTENTS 13 +#define IS_FILES_TOTAL_EXTENTS 14 +#define IS_FILES_EXTENT_SIZE 15 +#define IS_FILES_INITIAL_SIZE 16 +#define IS_FILES_MAXIMUM_SIZE 17 +#define IS_FILES_AUTOEXTEND_SIZE 18 +#define IS_FILES_CREATION_TIME 19 +#define IS_FILES_LAST_UPDATE_TIME 20 +#define IS_FILES_LAST_ACCESS_TIME 21 +#define IS_FILES_RECOVER_TIME 22 +#define IS_FILES_TRANSACTION_COUNTER 23 +#define IS_FILES_VERSION 24 +#define IS_FILES_ROW_FORMAT 25 +#define IS_FILES_TABLE_ROWS 26 +#define IS_FILES_AVG_ROW_LENGTH 27 +#define IS_FILES_DATA_LENGTH 28 +#define IS_FILES_MAX_DATA_LENGTH 29 +#define IS_FILES_INDEX_LENGTH 30 +#define IS_FILES_DATA_FREE 31 +#define IS_FILES_CREATE_TIME 32 +#define IS_FILES_UPDATE_TIME 33 +#define IS_FILES_CHECK_TIME 34 +#define IS_FILES_CHECKSUM 35 +#define IS_FILES_STATUS 36 +#define IS_FILES_EXTRA 37 +void init_fill_schema_files_row(TABLE* table); bool schema_table_store_record(THD *thd, TABLE *table); #endif /* MYSQL_SERVER */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6674dd87757..a6b063a47d4 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2663,19 +2663,43 @@ static int init_common_variables(const char *conf_file_name, int argc, /* connections and databases needs lots of files */ { - uint files, wanted_files; + uint files, wanted_files, max_open_files; - wanted_files= 10+(uint) max(max_connections*5, - max_connections+table_cache_size*2); - set_if_bigger(wanted_files, open_files_limit); - files= my_set_max_open_files(wanted_files); + /* MyISAM requires two file handles per table. */ + wanted_files= 10+max_connections+table_cache_size*2; + /* + We are trying to allocate no less than max_connections*5 file + handles (i.e. we are trying to set the limit so that they will + be available). In addition, we allocate no less than how much + was already allocated. However below we report a warning and + recompute values only if we got less file handles than were + explicitly requested. No warning and re-computation occur if we + can't get max_connections*5 but still got no less than was + requested (value of wanted_files). + */ + max_open_files= max(max(wanted_files, max_connections*5), + open_files_limit); + files= my_set_max_open_files(max_open_files); if (files < wanted_files) { if (!open_files_limit) { - max_connections= (ulong) min((files-10),max_connections); - table_cache_size= (ulong) max((files-10-max_connections)/2,64); + /* + If we have requested too much file handles than we bring + max_connections in supported bounds. + */ + max_connections= (ulong) min(files-10-TABLE_OPEN_CACHE_MIN*2, + max_connections); + /* + Decrease table_cache_size according to max_connections, but + not below TABLE_OPEN_CACHE_MIN. Outer min() ensures that we + never increase table_cache_size automatically (that could + happen if max_connections is decreased above). + */ + table_cache_size= (ulong) min(max((files-10-max_connections)/2, + TABLE_OPEN_CACHE_MIN), + table_cache_size); DBUG_PRINT("warning", ("Changed limits: max_open_files: %u max_connections: %ld table_cache: %ld", files, max_connections, table_cache_size)); @@ -4704,7 +4728,6 @@ enum options_mysqld OPT_NDB_MGMD, OPT_NDB_NODEID, OPT_NDB_DISTRIBUTION, OPT_NDB_INDEX_STAT_ENABLE, - OPT_NDB_INDEX_STAT_CACHE_ENTRIES, OPT_NDB_INDEX_STAT_UPDATE_FREQ, OPT_NDB_EXTRA_LOGGING, OPT_NDB_REPORT_THRESH_BINLOG_EPOCH_SLIP, OPT_NDB_REPORT_THRESH_BINLOG_MEM_USAGE, @@ -5414,19 +5437,7 @@ Disable with --skip-ndbcluster (will save memory).", "Use ndb index statistics in query optimization.", (gptr*) &global_system_variables.ndb_index_stat_enable, (gptr*) &max_system_variables.ndb_index_stat_enable, - 0, GET_BOOL, OPT_ARG, 1, 0, 1, 0, 0, 0}, - {"ndb-index-stat-cache-entries", OPT_NDB_INDEX_STAT_CACHE_ENTRIES, - "Number of start/end keys to store in statistics memory cache." - " Zero means no cache and forces query of db nodes always.", - (gptr*) &global_system_variables.ndb_index_stat_cache_entries, - (gptr*) &max_system_variables.ndb_index_stat_cache_entries, - 0, GET_ULONG, OPT_ARG, 32, 0, ~0L, 0, 0, 0}, - {"ndb-index-stat-update-freq", OPT_NDB_INDEX_STAT_UPDATE_FREQ, - "How often, in the long run, to query db nodes instead of statistics cache." - " For example 20 means every 20th time.", - (gptr*) &global_system_variables.ndb_index_stat_update_freq, - (gptr*) &max_system_variables.ndb_index_stat_update_freq, - 0, GET_ULONG, OPT_ARG, 20, 0, ~0L, 0, 0, 0}, + 0, GET_BOOL, OPT_ARG, 0, 0, 1, 0, 0, 0}, #endif {"ndb-use-copying-alter-table", OPT_NDB_USE_COPYING_ALTER_TABLE, @@ -6198,15 +6209,15 @@ The minimum value for this variable is 4096.", {"table_cache", OPT_TABLE_OPEN_CACHE, "Deprecated; use --table_open_cache instead.", (gptr*) &table_cache_size, (gptr*) &table_cache_size, 0, GET_ULONG, - REQUIRED_ARG, 64, 1, 512*1024L, 0, 1, 0}, + REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, 1, 512*1024L, 0, 1, 0}, {"table_definition_cache", OPT_TABLE_DEF_CACHE, "The number of cached table definitions.", (gptr*) &table_def_size, (gptr*) &table_def_size, 0, GET_ULONG, REQUIRED_ARG, 128, 1, 512*1024L, 0, 1, 0}, {"table_open_cache", OPT_TABLE_OPEN_CACHE, "The number of cached open tables.", - (gptr*) &table_cache_size, (gptr*) &table_cache_size, - 0, GET_ULONG, REQUIRED_ARG, 64, 1, 512*1024L, 0, 1, 0}, + (gptr*) &table_cache_size, (gptr*) &table_cache_size, 0, GET_ULONG, + REQUIRED_ARG, TABLE_OPEN_CACHE_DEFAULT, 1, 512*1024L, 0, 1, 0}, {"table_lock_wait_timeout", OPT_TABLE_LOCK_WAIT_TIMEOUT, "Timeout in seconds to wait for a table level lock before returning an " "error. Used only if the connection has active cursors.", @@ -6581,6 +6592,10 @@ static int show_ssl_get_cipher_list(THD *thd, SHOW_VAR *var, char *buff) #endif /* HAVE_OPENSSL */ +/* + Variables shown by SHOW STATUS in alphabetical order +*/ + SHOW_VAR status_vars[]= { {"Aborted_clients", (char*) &aborted_threads, SHOW_LONG}, {"Aborted_connects", (char*) &aborted_connects, SHOW_LONG}, @@ -7055,7 +7070,7 @@ static void mysql_init_variables(void) #endif #ifdef WITH_NDBCLUSTER_STORAGE_ENGINE have_ndbcluster=SHOW_OPTION_DISABLED; - global_system_variables.ndb_index_stat_enable=TRUE; + global_system_variables.ndb_index_stat_enable=FALSE; max_system_variables.ndb_index_stat_enable=TRUE; global_system_variables.ndb_index_stat_cache_entries=32; max_system_variables.ndb_index_stat_cache_entries=~0L; @@ -8088,16 +8103,20 @@ void refresh_status(THD *thd) { pthread_mutex_lock(&LOCK_status); - /* We must update the global status before cleaning up the thread */ + /* Add thread's status variabes to global status */ add_to_status(&global_status_var, &thd->status_var); + + /* Reset thread's status variables */ bzero((char*) &thd->status_var, sizeof(thd->status_var)); + /* Reset some global variables */ for (SHOW_VAR *ptr= status_vars; ptr->name; ptr++) { /* Note that SHOW_LONG_NOFLUSH variables are not reset */ if (ptr->type == SHOW_LONG) *(ulong*) ptr->value= 0; } + /* Reset the counters of all key caches (default and named). */ process_key_caches(reset_key_cache_counters); pthread_mutex_unlock(&LOCK_status); diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 5878771c096..79b3e023a5f 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -2101,6 +2101,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use, key_parts->null_bit= key_part_info->null_bit; key_parts->image_type = (key_info->flags & HA_SPATIAL) ? Field::itMBR : Field::itRAW; + key_parts->flag= key_part_info->key_part_flag; } param.real_keynr[param.keys++]=idx; } @@ -3236,6 +3237,11 @@ static bool create_partition_index_description(PART_PRUNE_PARAM *ppar) key_part->field= (*field); key_part->image_type = Field::itRAW; + /* + We set keypart flag to 0 here as the only HA_PART_KEY_SEG is checked + in the RangeAnalysisModule. + */ + key_part->flag= 0; /* We don't set key_parts->null_bit as it will not be used */ ppar->is_part_keypart[part]= !in_subpart_fields; @@ -5655,7 +5661,9 @@ get_mm_leaf(RANGE_OPT_PARAM *param, COND *conf_func, Field *field, } break; case Item_func::GT_FUNC: - if (field_is_equal_to_item(field,value)) + /* Don't use open ranges for partial key_segments */ + if (field_is_equal_to_item(field,value) && + !(key_part->flag & HA_PART_KEY_SEG)) tree->min_flag=NEAR_MIN; /* fall through */ case Item_func::GE_FUNC: @@ -7644,6 +7652,7 @@ QUICK_RANGE_SELECT *get_quick_select_for_ref(THD *thd, TABLE *table, key_part->length= key_info->key_part[part].length; key_part->store_length= key_info->key_part[part].store_length; key_part->null_bit= key_info->key_part[part].null_bit; + key_part->flag= key_info->key_part[part].key_part_flag; } if (insert_dynamic(&quick->ranges,(gptr)&range)) goto err; diff --git a/sql/opt_range.h b/sql/opt_range.h index a88c79e8bab..170766c7c10 100644 --- a/sql/opt_range.h +++ b/sql/opt_range.h @@ -27,6 +27,8 @@ typedef struct st_key_part { uint16 key,part, store_length, length; uint8 null_bit; + /* Keypart flags (0 if partition pruning is used) */ + uint8 flag; Field *field; Field::imagetype image_type; } KEY_PART; diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 7d6305594fd..cb8b53ac6a7 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -167,7 +167,12 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds) } else { - tl->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); + error= tl->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); + if(error) + { + tl->table->file->print_error(error, MYF(0)); + return error; + } count*= tl->table->file->stats.records; } } diff --git a/sql/parse_file.h b/sql/parse_file.h index 33871588e11..5fb65b4c7ec 100644 --- a/sql/parse_file.h +++ b/sql/parse_file.h @@ -107,4 +107,20 @@ public: bool bad_format_errors); }; + +/* + Custom version of standard offsetof() macro which can be used to get + offsets of members in class for non-POD types (according to the current + version of C++ standard offsetof() macro can't be used in such cases and + attempt to do so causes warnings to be emitted, OTOH in many cases it is + still OK to assume that all instances of the class has the same offsets + for the same members). + + This is temporary solution which should be removed once File_parser class + and related routines are refactored. +*/ + +#define my_offsetof(TYPE, MEMBER) \ + ((size_t)((char *)&(((TYPE *)0x10)->MEMBER) - (char*)0x10)) + #endif /* _PARSE_FILE_H_ */ diff --git a/sql/set_var.cc b/sql/set_var.cc index 4369c288cd5..40e74be2cf0 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -743,7 +743,7 @@ static int show_slave_skip_errors(THD *thd, SHOW_VAR *var, char *buff) #endif /* HAVE_REPLICATION */ /* - Variables shown by SHOW variables in alphabetical order + Variables shown by SHOW VARIABLES in alphabetical order */ SHOW_VAR init_vars[]= { @@ -3141,6 +3141,7 @@ static byte *get_warning_count(THD *thd) { thd->sys_var_tmp.long_value= (thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_NOTE] + + thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_ERROR] + thd->warn_count[(uint) MYSQL_ERROR::WARN_LEVEL_WARN]); return (byte*) &thd->sys_var_tmp.long_value; } diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 0bcd15c2b82..3b64684b5da 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -6004,4 +6004,6 @@ ER_BAD_LOG_STATEMENT ger "Sie können eine Logtabelle nicht '%s', wenn Loggen angeschaltet ist" ER_NON_INSERTABLE_TABLE eng "The target table %-.100s of the %s is not insertable-into" +ER_CANT_RENAME_LOG_TABLE + eng "Cannot rename '%s'. When logging enabled, rename to/from log table must rename two tables: the log table to an archive table and another table back to '%s'" diff --git a/sql/sp.cc b/sql/sp.cc index 3411a18c17a..45a177d3e7a 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -653,6 +653,17 @@ db_drop_routine(THD *thd, int type, sp_name *name) if (table->file->ha_delete_row(table->record[0])) ret= SP_DELETE_ROW_FAILED; } + + if (ret == SP_OK) + { + if (mysql_bin_log.is_open()) + { + thd->clear_error(); + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + } + close_thread_tables(thd); DBUG_RETURN(ret); } @@ -687,6 +698,17 @@ db_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics) if ((table->file->ha_update_row(table->record[1],table->record[0]))) ret= SP_WRITE_ROW_FAILED; } + + if (ret == SP_OK) + { + if (mysql_bin_log.is_open()) + { + thd->clear_error(); + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + } + close_thread_tables(thd); DBUG_RETURN(ret); } @@ -765,6 +787,7 @@ print_field_values(THD *thd, TABLE *table, return SP_INTERNAL_ERROR; } } + return SP_OK; } @@ -1371,6 +1394,10 @@ static bool add_used_routine(LEX *lex, Query_arena *arena, const LEX_STRING *key, TABLE_LIST *belong_to_view) { + hash_init_opt(&lex->sroutines, system_charset_info, + Query_tables_list::START_SROUTINES_HASH_SIZE, + 0, 0, sp_sroutine_key, 0, 0); + if (!hash_search(&lex->sroutines, (byte *)key->str, key->length)) { Sroutine_hash_entry *rn= diff --git a/sql/sp_head.cc b/sql/sp_head.cc index a061ae12dd1..b31cf8b73bc 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1029,8 +1029,7 @@ sp_head::execute(THD *thd) save_sql_mode= thd->variables.sql_mode; thd->variables.sql_mode= m_sql_mode; save_abort_on_warning= thd->abort_on_warning; - thd->abort_on_warning= - (m_sql_mode & (MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)); + thd->abort_on_warning= 0; /* It is also more efficient to save/restore current thd->lex once when diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index c55fc744cd0..aa13c2f08f4 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3140,9 +3140,22 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, grant_option=TRUE; thd->mem_root= old_root; pthread_mutex_unlock(&acl_cache->lock); + + if (!result) /* success */ + { + if (mysql_bin_log.is_open()) + { + thd->clear_error(); + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + } + rw_unlock(&LOCK_grant); - if (!result) + + if (!result) /* success */ send_ok(thd); + /* Tables are automatically closed */ DBUG_RETURN(result); } @@ -3294,9 +3307,21 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, grant_option=TRUE; thd->mem_root= old_root; pthread_mutex_unlock(&acl_cache->lock); + if (!result && !no_error) + { + if (mysql_bin_log.is_open()) + { + thd->clear_error(); + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + } + rw_unlock(&LOCK_grant); + if (!result && !no_error) send_ok(thd); + /* Tables are automatically closed */ DBUG_RETURN(result); } @@ -3394,11 +3419,23 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list, } } VOID(pthread_mutex_unlock(&acl_cache->lock)); + + if (!result) + { + if (mysql_bin_log.is_open()) + { + thd->clear_error(); + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + } + rw_unlock(&LOCK_grant); close_thread_tables(thd); if (!result) send_ok(thd); + DBUG_RETURN(result); } @@ -5398,6 +5435,13 @@ bool mysql_create_user(THD *thd, List <LEX_USER> &list) } VOID(pthread_mutex_unlock(&acl_cache->lock)); + + if (mysql_bin_log.is_open()) + { + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + rw_unlock(&LOCK_grant); close_thread_tables(thd); if (result) @@ -5454,6 +5498,13 @@ bool mysql_drop_user(THD *thd, List <LEX_USER> &list) rebuild_check_host(); VOID(pthread_mutex_unlock(&acl_cache->lock)); + + if (mysql_bin_log.is_open()) + { + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + rw_unlock(&LOCK_grant); close_thread_tables(thd); if (result) @@ -5523,6 +5574,13 @@ bool mysql_rename_user(THD *thd, List <LEX_USER> &list) rebuild_check_host(); VOID(pthread_mutex_unlock(&acl_cache->lock)); + + if (mysql_bin_log.is_open()) + { + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + rw_unlock(&LOCK_grant); close_thread_tables(thd); if (result) @@ -5697,6 +5755,13 @@ bool mysql_revoke_all(THD *thd, List <LEX_USER> &list) } VOID(pthread_mutex_unlock(&acl_cache->lock)); + + if (mysql_bin_log.is_open()) + { + thd->binlog_query(THD::MYSQL_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + rw_unlock(&LOCK_grant); close_thread_tables(thd); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 3e7bcf7798a..c2cf170dbe3 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -1365,6 +1365,10 @@ TABLE_LIST *find_table_in_list(TABLE_LIST *table, Also SELECT::exclude_from_table_unique_test used to exclude from check tables of main SELECT of multi-delete and multi-update + We also skip tables with TABLE_LIST::prelocking_placeholder set, + because we want to allow SELECTs from them, and their modification + will rise the error anyway. + TODO: when we will have table/view change detection we can do this check only once for PS/SP @@ -1411,12 +1415,13 @@ TABLE_LIST* unique_table(THD *thd, TABLE_LIST *table, TABLE_LIST *table_list) if (((! (res= find_table_in_global_list(table_list, d_name, t_name))) && (! (res= mysql_lock_have_duplicate(thd, table, table_list)))) || ((!res->table || res->table != table->table) && - res->select_lex && !res->select_lex->exclude_from_table_unique_test)) + res->select_lex && !res->select_lex->exclude_from_table_unique_test && + !res->prelocking_placeholder)) break; /* - If we found entry of this table or or table of SELECT which already + If we found entry of this table or table of SELECT which already processed in derived table or top select of multi-update/multi-delete - (exclude_from_table_unique_test). + (exclude_from_table_unique_test) or prelocking placeholder. */ table_list= res->next_global; DBUG_PRINT("info", diff --git a/sql/sql_class.cc b/sql/sql_class.cc index e96c96cd869..67c51a1986b 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -241,6 +241,7 @@ THD::THD() // Must be reset to handle error with THD's created for init of mysqld lex->current_select= 0; start_time=(time_t) 0; + time_after_lock=(time_t) 0; current_linfo = 0; slave_thread = 0; variables.pseudo_thread_id= 0; @@ -512,14 +513,13 @@ THD::~THD() void add_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var) { - ulong *end= (ulong*) ((byte*) to_var + offsetof(STATUS_VAR, - last_system_status_var) + + ulong *end= (ulong*) ((byte*) to_var + + offsetof(STATUS_VAR, last_system_status_var) + sizeof(ulong)); ulong *to= (ulong*) to_var, *from= (ulong*) from_var; while (to != end) *(to++)+= *(from++); - /* it doesn't make sense to add last_query_cost values */ } /* @@ -858,7 +858,6 @@ int THD::send_explain_fields(select_result *result) field_list.push_back(new Item_empty_string("select_type", 19, cs)); field_list.push_back(item= new Item_empty_string("table", NAME_LEN, cs)); item->maybe_null= 1; -#ifdef WITH_PARTITION_STORAGE_ENGINE if (lex->describe & DESCRIBE_PARTITIONS) { /* Maximum length of string that make_used_partitions_str() can produce */ @@ -867,7 +866,6 @@ int THD::send_explain_fields(select_result *result) field_list.push_back(item); item->maybe_null= 1; } -#endif field_list.push_back(item= new Item_empty_string("type", 10, cs)); item->maybe_null= 1; field_list.push_back(item=new Item_empty_string("possible_keys", @@ -2632,10 +2630,10 @@ int THD::binlog_update_row(TABLE* table, bool is_trans, my_size_t const after_size= pack_row(table, cols, after_row, after_record); - DBUG_DUMP("before_record", (char *)before_record, table->s->reclength); - DBUG_DUMP("after_record", (char *)after_record, table->s->reclength); - DBUG_DUMP("before_row", (char *)before_row, before_size); - DBUG_DUMP("after_row", (char *)after_row, after_size); + DBUG_DUMP("before_record", (const char *)before_record, table->s->reclength); + DBUG_DUMP("after_record", (const char *)after_record, table->s->reclength); + DBUG_DUMP("before_row", (const char *)before_row, before_size); + DBUG_DUMP("after_row", (const char *)after_row, after_size); Rows_log_event* const ev= binlog_prepare_pending_rows_event(table, server_id, cols, colcnt, diff --git a/sql/sql_class.h b/sql/sql_class.h index 95283ec2fc8..9fec77bdbf7 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -337,12 +337,17 @@ typedef struct system_status_var ulong com_stmt_reset; ulong com_stmt_close; + /* + Status variables which it does not make sense to add to + global status variable counter + */ double last_query_cost; } STATUS_VAR; /* - This is used for 'show status'. It must be updated to the last ulong - variable in system_status_var + This is used for 'SHOW STATUS'. It must be updated to the last ulong + variable in system_status_var which is makes sens to add to the global + counter */ #define last_system_status_var com_stmt_close diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 3960236e828..37096fd897e 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -705,6 +705,7 @@ bool mysql_create_db(THD *thd, char *db, HA_CREATE_INFO *create_info, qinfo.db = db; qinfo.db_len = strlen(db); + /* These DDL methods and logging protected with LOCK_mysql_create_db */ mysql_bin_log.write(&qinfo); } send_ok(thd, result); @@ -783,6 +784,7 @@ bool mysql_alter_db(THD *thd, const char *db, HA_CREATE_INFO *create_info) qinfo.db_len = strlen(db); thd->clear_error(); + /* These DDL methods and logging protected with LOCK_mysql_create_db */ mysql_bin_log.write(&qinfo); } send_ok(thd, result); @@ -905,6 +907,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) qinfo.db_len = strlen(db); thd->clear_error(); + /* These DDL methods and logging protected with LOCK_mysql_create_db */ mysql_bin_log.write(&qinfo); } thd->server_status|= SERVER_STATUS_DB_DROPPED; @@ -931,6 +934,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) tbl_name_len= strlen(tbl->table_name) + 3; if (query_pos + tbl_name_len + 1 >= query_end) { + /* These DDL methods and logging protected with LOCK_mysql_create_db */ write_to_binlog(thd, query, query_pos -1 - query, db, db_len); query_pos= query_data_start; } @@ -943,6 +947,7 @@ bool mysql_rm_db(THD *thd,char *db,bool if_exists, bool silent) if (query_pos != query_data_start) { + /* These DDL methods and logging protected with LOCK_mysql_create_db */ write_to_binlog(thd, query, query_pos -1 - query, db, db_len); } } diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index f128b5e8706..a0cd419e6c6 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -350,7 +350,7 @@ cleanup: mysql_unlock_tables(thd, thd->lock); thd->lock=0; } - if (error < 0) + if (error < 0 || (thd->lex->ignore && !thd->is_fatal_error)) { thd->row_count_func= deleted; send_ok(thd,deleted); @@ -862,6 +862,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) bool error; uint closed_log_tables= 0, lock_logger= 0; uint path_length; + uint log_type; DBUG_ENTER("mysql_truncate"); bzero((char*) &create_info,sizeof(create_info)); @@ -913,28 +914,16 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) DBUG_RETURN(TRUE); } + log_type= check_if_log_table(table_list->db_length, table_list->db, + table_list->table_name_length, + table_list->table_name, 1); /* close log tables in use */ - if (!my_strcasecmp(system_charset_info, table_list->db, "mysql")) + if (log_type) { - if (opt_log && - !my_strcasecmp(system_charset_info, table_list->table_name, - "general_log")) - { - lock_logger= 1; - logger.lock(); - logger.close_log_table(QUERY_LOG_GENERAL, FALSE); - closed_log_tables= closed_log_tables | QUERY_LOG_GENERAL; - } - else - if (opt_slow_log && - !my_strcasecmp(system_charset_info, table_list->table_name, - "slow_log")) - { - lock_logger= 1; - logger.lock(); - logger.close_log_table(QUERY_LOG_SLOW, FALSE); - closed_log_tables= closed_log_tables | QUERY_LOG_SLOW; - } + lock_logger= 1; + logger.lock(); + logger.close_log_table(log_type, FALSE); + closed_log_tables= closed_log_tables | log_type; } // Remove the .frm extension AIX 5.2 64-bit compiler bug (BUG#16155): this diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index dd358492d0d..62782370c76 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -151,7 +151,6 @@ void lex_start(THD *thd, const uchar *buf, uint length) lex->safe_to_cache_query= 1; lex->time_zone_tables_used= 0; lex->leaf_tables_insert= 0; - lex->variables_used= 0; lex->empty_field_list_on_rset= 0; lex->select_lex.select_number= 1; lex->next_state=MY_LEX_START; @@ -1644,9 +1643,18 @@ void Query_tables_list::reset_query_tables_list(bool init) query_tables_last= &query_tables; query_tables_own_last= 0; if (init) - hash_init(&sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key, 0, 0); + { + /* + We delay real initialization of hash (and therefore related + memory allocation) until first insertion into this hash. + */ + hash_clear(&sroutines); + } else if (sroutines.records) + { + /* Non-zero sroutines.records means that hash was initialized. */ my_hash_reset(&sroutines); + } sroutines_list.empty(); sroutines_list_own_last= sroutines_list.next; sroutines_list_own_elements= 0; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 1815774526f..ee6e500ef76 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -792,7 +792,11 @@ public: 0 - indicates that this query does not need prelocking. */ TABLE_LIST **query_tables_own_last; - /* Set of stored routines called by statement. */ + /* + Set of stored routines called by statement. + (Note that we use lazy-initialization for this hash). + */ + enum { START_SROUTINES_HASH_SIZE= 16 }; HASH sroutines; /* List linking elements of 'sroutines' set. Allows you to add new elements @@ -867,6 +871,25 @@ public: }; +/* + st_parsing_options contains the flags for constructions that are + allowed in the current statement. +*/ + +struct st_parsing_options +{ + bool allows_variable; + bool allows_select_into; + bool allows_select_procedure; + bool allows_derived; + + st_parsing_options() + : allows_variable(TRUE), allows_select_into(TRUE), + allows_select_procedure(TRUE), allows_derived(TRUE) + {} +}; + + /* The state of the lex parsing. This is saved in the THD struct */ typedef struct st_lex : public Query_tables_list @@ -1023,7 +1046,7 @@ typedef struct st_lex : public Query_tables_list bool stmt_prepare_mode; bool safe_to_cache_query; bool subqueries, ignore; - bool variables_used; + st_parsing_options parsing_options; ALTER_INFO alter_info; /* Prepared statements SQL syntax:*/ LEX_STRING prepared_stmt_name; /* Statement name (in all queries) */ diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 51fa86affc2..ae334f382f5 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1214,7 +1214,14 @@ pthread_handler_t handle_one_connection(void *arg) { execute_init_command(thd, &sys_init_connect, &LOCK_sys_init_connect); if (thd->query_error) + { thd->killed= THD::KILL_CONNECTION; + sql_print_warning(ER(ER_NEW_ABORTING_CONNECTION), + thd->thread_id,(thd->db ? thd->db : "unconnected"), + sctx->user ? sctx->user : "unauthenticated", + sctx->host_or_ip, "init_connect command failed"); + sql_print_warning("%s", net->last_error); + } thd->proc_info=0; thd->set_time(); thd->init_for_queries(); @@ -3091,11 +3098,6 @@ end_with_restore_list: case SQLCOM_ALTER_TABLE: DBUG_ASSERT(first_table == all_tables && first_table != 0); -#if defined(DONT_ALLOW_SHOW_COMMANDS) - my_message(ER_NOT_ALLOWED_COMMAND, ER(ER_NOT_ALLOWED_COMMAND), - MYF(0)); /* purecov: inspected */ - goto error; -#else { ulong priv=0; ulong priv_needed= ALTER_ACL; @@ -3164,7 +3166,6 @@ end_with_restore_list: lex->ignore, &lex->alter_info, 1); break; } -#endif /*DONT_ALLOW_SHOW_COMMANDS*/ case SQLCOM_RENAME_TABLE: { DBUG_ASSERT(first_table == all_tables && first_table != 0); @@ -3253,6 +3254,7 @@ end_with_restore_list: /* ! we write after unlocking the table */ if (!res && !lex->no_write_to_binlog) { + /* Presumably, REPAIR and binlog writing doesn't require synchronization */ if (mysql_bin_log.is_open()) { thd->clear_error(); // No binlog error generated @@ -3285,6 +3287,7 @@ end_with_restore_list: /* ! we write after unlocking the table */ if (!res && !lex->no_write_to_binlog) { + /* Presumably, ANALYZE and binlog writing doesn't require synchronization */ if (mysql_bin_log.is_open()) { thd->clear_error(); // No binlog error generated @@ -3309,6 +3312,7 @@ end_with_restore_list: /* ! we write after unlocking the table */ if (!res && !lex->no_write_to_binlog) { + /* Presumably, OPTIMIZE and binlog writing doesn't require synchronization */ if (mysql_bin_log.is_open()) { thd->clear_error(); // No binlog error generated @@ -3410,9 +3414,17 @@ end_with_restore_list: res= mysql_insert(thd, all_tables, lex->field_list, lex->many_values, lex->update_list, lex->value_list, lex->duplicates, lex->ignore); - /* do not show last insert ID if VIEW does not have auto_inc */ + + /* + If we have inserted into a VIEW, and the base table has + AUTO_INCREMENT column, but this column is not accessible through + a view, then we should restore LAST_INSERT_ID to the value it + had before the statement. + */ if (first_table->view && !first_table->contain_auto_increment) - thd->first_successful_insert_id_in_cur_stmt= 0; + thd->first_successful_insert_id_in_cur_stmt= + thd->first_successful_insert_id_in_prev_stmt; + break; } case SQLCOM_REPLACE_SELECT: @@ -3472,9 +3484,17 @@ end_with_restore_list: /* revert changes for SP */ select_lex->table_list.first= (byte*) first_table; } - /* do not show last insert ID if VIEW does not have auto_inc */ + + /* + If we have inserted into a VIEW, and the base table has + AUTO_INCREMENT column, but this column is not accessible through + a view, then we should restore LAST_INSERT_ID to the value it + had before the statement. + */ if (first_table->view && !first_table->contain_auto_increment) - thd->first_successful_insert_id_in_cur_stmt= 0; + thd->first_successful_insert_id_in_cur_stmt= + thd->first_successful_insert_id_in_prev_stmt; + break; } case SQLCOM_TRUNCATE: @@ -3596,6 +3616,7 @@ end_with_restore_list: /* So that DROP TEMPORARY TABLE gets to binlog at commit/rollback */ thd->options|= OPTION_KEEP_LOG; } + /* DDL and binlog write order protected by LOCK_open */ res= mysql_rm_table(thd, first_table, lex->drop_if_exists, lex->drop_temporary); } @@ -3995,13 +4016,9 @@ end_with_restore_list: break; if (end_active_trans(thd)) goto error; + /* Conditionally writes to binlog */ if (!(res= mysql_create_user(thd, lex->users_list))) - { - if (mysql_bin_log.is_open()) - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); send_ok(thd); - } break; } case SQLCOM_DROP_USER: @@ -4011,15 +4028,9 @@ end_with_restore_list: break; if (end_active_trans(thd)) goto error; + /* Conditionally writes to binlog */ if (!(res= mysql_drop_user(thd, lex->users_list))) - { - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } send_ok(thd); - } break; } case SQLCOM_RENAME_USER: @@ -4029,15 +4040,9 @@ end_with_restore_list: break; if (end_active_trans(thd)) goto error; + /* Conditionally writes to binlog */ if (!(res= mysql_rename_user(thd, lex->users_list))) - { - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } send_ok(thd); - } break; } case SQLCOM_REVOKE_ALL: @@ -4045,15 +4050,9 @@ end_with_restore_list: if (check_access(thd, UPDATE_ACL, "mysql", 0, 1, 1, 0) && check_global_access(thd,CREATE_USER_ACL)) break; + /* Conditionally writes to binlog */ if (!(res = mysql_revoke_all(thd, lex->users_list))) - { - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } send_ok(thd); - } break; } case SQLCOM_REVOKE: @@ -4112,6 +4111,7 @@ end_with_restore_list: check_grant_routine(thd, grants | GRANT_ACL, all_tables, lex->type == TYPE_ENUM_PROCEDURE, 0)) goto error; + /* Conditionally writes to binlog */ res= mysql_routine_grant(thd, all_tables, lex->type == TYPE_ENUM_PROCEDURE, lex->users_list, grants, @@ -4124,16 +4124,11 @@ end_with_restore_list: GRANT_ACL), all_tables, 0, UINT_MAX, 0)) goto error; + /* Conditionally writes to binlog */ res= mysql_table_grant(thd, all_tables, lex->users_list, lex->columns, lex->grant, lex->sql_command == SQLCOM_REVOKE); } - if (!res && mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } } else { @@ -4144,16 +4139,11 @@ end_with_restore_list: goto error; } else + /* Conditionally writes to binlog */ res = mysql_grant(thd, select_lex->db, lex->users_list, lex->grant, lex->sql_command == SQLCOM_REVOKE); if (!res) { - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } if (lex->sql_command == SQLCOM_GRANT) { List_iterator <LEX_USER> str_list(lex->users_list); @@ -4191,6 +4181,7 @@ end_with_restore_list: We WANT to write and we CAN write. ! we write after unlocking the table. */ + /* Presumably, RESET and binlog writing doesn't require synchronization */ if (!lex->no_write_to_binlog && write_to_binlog) { if (mysql_bin_log.is_open()) @@ -4707,20 +4698,16 @@ end_with_restore_list: already puts on CREATE FUNCTION. */ if (lex->sql_command == SQLCOM_ALTER_PROCEDURE) + /* Conditionally writes to binlog */ result= sp_update_procedure(thd, lex->spname, &lex->sp_chistics); else + /* Conditionally writes to binlog */ result= sp_update_function(thd, lex->spname, &lex->sp_chistics); } } switch (result) { case SP_OK: - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } send_ok(thd); break; case SP_KEY_NOT_FOUND: @@ -4765,9 +4752,11 @@ end_with_restore_list: } #endif if (lex->sql_command == SQLCOM_DROP_PROCEDURE) - result= sp_drop_procedure(thd, lex->spname); + /* Conditionally writes to binlog */ + result= sp_drop_procedure(thd, lex->spname); /* Conditionally writes to binlog */ else - result= sp_drop_function(thd, lex->spname); + /* Conditionally writes to binlog */ + result= sp_drop_function(thd, lex->spname); /* Conditionally writes to binlog */ } else { @@ -4780,6 +4769,8 @@ end_with_restore_list: { if (check_access(thd, DELETE_ACL, "mysql", 0, 1, 0, 0)) goto error; + + /* Does NOT write to binlog */ if (!(res = mysql_drop_function(thd, &lex->spname->m_name))) { send_ok(thd); @@ -4800,12 +4791,6 @@ end_with_restore_list: switch (result) { case SP_OK: - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } send_ok(thd); break; case SP_KEY_NOT_FOUND: @@ -4904,49 +4889,7 @@ end_with_restore_list: if (end_active_trans(thd)) goto error; - if (!(res= mysql_create_view(thd, thd->lex->create_view_mode)) && - mysql_bin_log.is_open()) - { - String buff; - const LEX_STRING command[3]= - {{ C_STRING_WITH_LEN("CREATE ") }, - { C_STRING_WITH_LEN("ALTER ") }, - { C_STRING_WITH_LEN("CREATE OR REPLACE ") }}; - thd->clear_error(); - - buff.append(command[thd->lex->create_view_mode].str, - command[thd->lex->create_view_mode].length); - view_store_options(thd, first_table, &buff); - buff.append(STRING_WITH_LEN("VIEW ")); - /* Test if user supplied a db (ie: we did not use thd->db) */ - if (first_table->db && first_table->db[0] && - (thd->db == NULL || strcmp(first_table->db, thd->db))) - { - append_identifier(thd, &buff, first_table->db, - first_table->db_length); - buff.append('.'); - } - append_identifier(thd, &buff, first_table->table_name, - first_table->table_name_length); - if (lex->view_list.elements) - { - List_iterator_fast<LEX_STRING> names(lex->view_list); - LEX_STRING *name; - int i; - - for (i= 0; name= names++; i++) - { - buff.append(i ? ", " : "("); - append_identifier(thd, &buff, name->str, name->length); - } - buff.append(')'); - } - buff.append(STRING_WITH_LEN(" AS ")); - buff.append(first_table->source.str, first_table->source.length); - - thd->binlog_query(THD::STMT_QUERY_TYPE, - buff.ptr(), buff.length(), FALSE, FALSE); - } + res= mysql_create_view(thd, first_table, thd->lex->create_view_mode); break; } case SQLCOM_DROP_VIEW: @@ -4954,13 +4897,8 @@ end_with_restore_list: if (check_table_access(thd, DROP_ACL, all_tables, 0) || end_active_trans(thd)) goto error; - if (!(res= mysql_drop_view(thd, first_table, thd->lex->drop_mode)) && - mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + /* Conditionally writes to binlog. */ + res= mysql_drop_view(thd, first_table, thd->lex->drop_mode); break; } case SQLCOM_CREATE_TRIGGER: @@ -4968,6 +4906,7 @@ end_with_restore_list: if (end_active_trans(thd)) goto error; + /* Conditionally writes to binlog. */ res= mysql_create_or_drop_trigger(thd, all_tables, 1); /* We don't care about trigger body after this point */ @@ -4980,6 +4919,7 @@ end_with_restore_list: if (end_active_trans(thd)) goto error; + /* Conditionally writes to binlog. */ res= mysql_create_or_drop_trigger(thd, all_tables, 0); break; } @@ -6104,14 +6044,19 @@ void mysql_parse(THD *thd, char *inBuf, uint length) DBUG_ASSERT(thd->net.report_error); DBUG_PRINT("info",("Command aborted. Fatal_error: %d", thd->is_fatal_error)); - query_cache_abort(&thd->net); - lex->unit.cleanup(); + + /* + The first thing we do after parse error is freeing sp_head to + ensure that we have restored original memroot. + */ if (lex->sphead) { /* Clean up after failed stored procedure/function */ delete lex->sphead; lex->sphead= NULL; } + query_cache_abort(&thd->net); + lex->unit.cleanup(); } thd->proc_info="freeing items"; thd->end_statement(); diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 63a129918d0..013c3a17fd6 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -2287,6 +2287,14 @@ void mysql_stmt_execute(THD *thd, char *packet_arg, uint packet_length) #endif if (!(specialflag & SPECIAL_NO_PRIOR)) my_pthread_setprio(pthread_self(),QUERY_PRIOR); + + /* + If the free_list is not empty, we'll wrongly free some externally + allocated items when cleaning up after validation of the prepared + statement. + */ + DBUG_ASSERT(thd->free_list == NULL); + error= stmt->execute(&expanded_query, test(flags & (ulong) CURSOR_TYPE_READ_ONLY)); if (!(specialflag & SPECIAL_NO_PRIOR)) @@ -2349,6 +2357,13 @@ void mysql_sql_stmt_execute(THD *thd) DBUG_PRINT("info",("stmt: %p", stmt)); + /* + If the free_list is not empty, we'll wrongly free some externally + allocated items when cleaning up after validation of the prepared + statement. + */ + DBUG_ASSERT(thd->free_list == NULL); + if (stmt->set_params_from_vars(stmt, lex->prepared_stmt_params, &expanded_query)) goto set_params_data_err; @@ -2811,7 +2826,19 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len) error= MYSQLparse((void *)thd) || thd->is_fatal_error || thd->net.report_error || init_param_array(this); + + /* + The first thing we do after parse error is freeing sp_head to + ensure that we have restored original memroot. + */ + if (error && lex->sphead) + { + delete lex->sphead; + lex->sphead= NULL; + } + lex->safe_to_cache_query= FALSE; + /* While doing context analysis of the query (in check_prepared_statement) we allocate a lot of additional memory: for open tables, JOINs, derived @@ -2827,16 +2854,17 @@ bool Prepared_statement::prepare(const char *packet, uint packet_len) external changes when cleaning up after validation. */ DBUG_ASSERT(thd->change_list.is_empty()); - /* - If the free_list is not empty, we'll wrongly free some externally - allocated items when cleaning up after validation of the prepared - statement. + + /* + The only case where we should have items in the thd->free_list is + after stmt->set_params_from_vars(), which may in some cases create + Item_null objects. */ - DBUG_ASSERT(thd->free_list == NULL); if (error == 0) error= check_prepared_statement(this, name.str != 0); + /* Free sp_head if check_prepared_statement() failed. */ if (error && lex->sphead) { delete lex->sphead; @@ -2930,7 +2958,13 @@ bool Prepared_statement::execute(String *expanded_query, bool open_cursor) allocated items when cleaning up after execution of this statement. */ DBUG_ASSERT(thd->change_list.is_empty()); - DBUG_ASSERT(thd->free_list == NULL); + + /* + The only case where we should have items in the thd->free_list is + after stmt->set_params_from_vars(), which may in some cases create + Item_null objects. + */ + thd->set_n_backup_statement(this, &stmt_backup); if (expanded_query->length() && alloc_query(thd, (char*) expanded_query->ptr(), diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index bf2e2d506cd..cd2c3c348d4 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -35,7 +35,10 @@ static TABLE_LIST *reverse_table_list(TABLE_LIST *table_list); bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) { bool error= 1; - TABLE_LIST *ren_table= 0; + TABLE_LIST *ren_table= 0, *new_table; + int to_table; + char *rename_log_table[2]= {NULL, NULL}; + int disable_logs= 0; DBUG_ENTER("mysql_rename_tables"); /* @@ -52,6 +55,96 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) if (wait_if_global_read_lock(thd,0,1)) DBUG_RETURN(1); + + if (logger.is_log_table_enabled(QUERY_LOG_GENERAL) || + logger.is_log_table_enabled(QUERY_LOG_SLOW)) + { + + /* + Rules for rename of a log table: + + IF 1. Log tables are enabled + AND 2. Rename operates on the log table and nothing is being + renamed to the log table. + DO 3. Throw an error message. + ELSE 4. Perform rename. + */ + + for (to_table= 0, ren_table= table_list; ren_table; + to_table= 1 - to_table, ren_table= ren_table->next_local) + { + int log_table_rename= 0; + + if ((log_table_rename= + check_if_log_table(ren_table->db_length, ren_table->db, + ren_table->table_name_length, + ren_table->table_name, 1))) + { + /* + Log table encoutered we will need to disable and lock logs + for duration of rename. + */ + disable_logs= TRUE; + + /* + as we use log_table_rename as an array index, we need it to start + with 0, while QUERY_LOG_SLOW == 1 and QUERY_LOG_GENERAL == 2. + So, we shift the value to start with 0; + */ + log_table_rename--; + if (rename_log_table[log_table_rename]) + { + if (to_table) + rename_log_table[log_table_rename]= NULL; + else + { + /* + Two renames of "log_table TO" w/o rename "TO log_table" in + between. + */ + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), ren_table->table_name, + ren_table->table_name); + DBUG_RETURN(1); + } + } + else + { + if (to_table) + { + /* + Attempt to rename a table TO log_table w/o renaming + log_table TO some table. + */ + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), ren_table->table_name, + ren_table->table_name); + DBUG_RETURN(1); + } + else + { + /* save the name of the log table to report an error */ + rename_log_table[log_table_rename]= ren_table->table_name; + } + } + } + } + if (rename_log_table[0] || rename_log_table[1]) + { + if (rename_log_table[0]) + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), rename_log_table[0], + rename_log_table[0]); + else + my_error(ER_CANT_RENAME_LOG_TABLE, MYF(0), rename_log_table[1], + rename_log_table[1]); + DBUG_RETURN(1); + } + + if (disable_logs) + { + logger.lock(); + logger.tmp_close_log_tables(thd); + } + } + VOID(pthread_mutex_lock(&LOCK_open)); if (lock_table_names(thd, table_list)) goto err; @@ -95,6 +188,13 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) err: pthread_mutex_unlock(&LOCK_open); + /* enable logging back if needed */ + if (disable_logs) + { + if (logger.reopen_log_tables()) + error= TRUE; + logger.unlock(); + } start_waiting_global_read_lock(thd); DBUG_RETURN(error); } diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7908bb8c95f..2065d418fd4 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -679,6 +679,8 @@ JOIN::optimize() { if (res > 1) { + thd->fatal_error(); + error= res; DBUG_PRINT("error",("Error from opt_sum_query")); DBUG_RETURN(1); } @@ -2149,7 +2151,12 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, s->needed_reg.init(); table_vector[i]=s->table=table=tables->table; table->pos_in_table_list= tables; - table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);// record count + error= table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); + if(error) + { + table->file->print_error(error, MYF(0)); + DBUG_RETURN(1); + } table->quick_keys.clear_all(); table->reginfo.join_tab=s; table->reginfo.not_exists_optimize=0; @@ -2200,7 +2207,7 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, continue; } #ifdef WITH_PARTITION_STORAGE_ENGINE - bool no_partitions_used= table->no_partitions_used; + const bool no_partitions_used= table->no_partitions_used; #else const bool no_partitions_used= FALSE; #endif @@ -11784,7 +11791,7 @@ part_of_refkey(TABLE *table,Field *field) for (uint part=0 ; part < ref_parts ; part++,key_part++) if (field->eq(key_part->field) && - !(key_part->key_part_flag & HA_PART_KEY_SEG)) + !(key_part->key_part_flag & (HA_PART_KEY_SEG | HA_NULL_PART))) return table->reginfo.join_tab->ref.items[part]; } return (Item*) 0; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 30bbc40f21b..dc8946df876 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1667,7 +1667,9 @@ void mysqld_list_processes(THD *thd,const char *user, bool verbose) "%s:%u", tmp_sctx->host_or_ip, tmp->peer_port); } else - thd_info->host= thd->strdup(tmp_sctx->host_or_ip); + thd_info->host= thd->strdup(tmp_sctx->host_or_ip[0] ? + tmp_sctx->host_or_ip : + tmp_sctx->host ? tmp_sctx->host : ""); if ((thd_info->db=tmp->db)) // Safe test thd_info->db=thd->strdup(thd_info->db); thd_info->command=(int) tmp->command; @@ -5250,7 +5252,7 @@ ST_FIELD_INFO columns_fields_info[]= {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"COLUMN_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Field"}, {"ORDINAL_POSITION", 21 , MYSQL_TYPE_LONG, 0, 0, 0}, - {"COLUMN_DEFAULT", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, "Default"}, + {"COLUMN_DEFAULT", MAX_FIELD_VARCHARLENGTH, MYSQL_TYPE_STRING, 0, 1, "Default"}, {"IS_NULLABLE", 3, MYSQL_TYPE_STRING, 0, 0, "Null"}, {"DATA_TYPE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"CHARACTER_MAXIMUM_LENGTH", 21 , MYSQL_TYPE_LONG, 0, 1, 0}, @@ -5645,6 +5647,16 @@ ST_FIELD_INFO files_fields_info[]= {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} }; +void init_fill_schema_files_row(TABLE* table) +{ + int i; + for(i=0; files_fields_info[i].field_name!=NULL; i++) + table->field[i]->set_null(); + + table->field[IS_FILES_STATUS]->set_notnull(); + table->field[IS_FILES_STATUS]->store("NORMAL", 6, system_charset_info); +} + ST_FIELD_INFO referential_constraints_fields_info[]= { {"CONSTRAINT_CATALOG", FN_REFLEN, MYSQL_TYPE_STRING, 0, 1, 0}, diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c024ee8ddbe..511d9fa6677 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1639,11 +1639,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists, /* Disable drop of enabled log tables */ if (share && share->log_table && - ((!my_strcasecmp(system_charset_info, table->table_name, - "general_log") && opt_log && - logger.is_general_log_table_enabled()) || - (!my_strcasecmp(system_charset_info, table->table_name, "slow_log") - && opt_slow_log && logger.is_slow_log_table_enabled()))) + check_if_log_table(table->db_length, table->db, + table->table_name_length, table->table_name, 1)) { my_error(ER_BAD_LOG_STATEMENT, MYF(0), "DROP"); DBUG_RETURN(1); @@ -4043,7 +4040,7 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, Item *item; Protocol *protocol= thd->protocol; LEX *lex= thd->lex; - int result_code; + int result_code, disable_logs= 0; DBUG_ENTER("mysql_admin_table"); if (end_active_trans(thd)) @@ -4088,6 +4085,23 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, thd->no_warnings_for_error= no_warnings_for_error; if (view_operator_func == NULL) table->required_type=FRMTYPE_TABLE; + + /* + If we want to perform an admin operation on the log table + (E.g. rename) and lock_type >= TL_READ_NO_INSERT disable + log tables + */ + + if (check_if_log_table(table->db_length, table->db, + table->table_name_length, + table->table_name, 1) && + lock_type >= TL_READ_NO_INSERT) + { + disable_logs= 1; + logger.lock(); + logger.tmp_close_log_tables(thd); + } + open_and_lock_tables(thd, table); thd->no_warnings_for_error= 0; table->next_global= save_next_global; @@ -4404,11 +4418,24 @@ send_result_message: } send_eof(thd); + if (disable_logs) + { + if (logger.reopen_log_tables()) + my_error(ER_CANT_ACTIVATE_LOG, MYF(0)); + logger.unlock(); + } DBUG_RETURN(FALSE); err: ha_autocommit_or_rollback(thd, 1); close_thread_tables(thd); // Shouldn't be needed + /* enable logging back if needed */ + if (disable_logs) + { + if (logger.reopen_log_tables()) + my_error(ER_CANT_ACTIVATE_LOG, MYF(0)); + logger.unlock(); + } if (table) table->table=0; DBUG_RETURN(TRUE); @@ -4573,17 +4600,18 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, { TABLE *tmp_table; char src_path[FN_REFLEN], dst_path[FN_REFLEN], tmp_path[FN_REFLEN]; + char src_table_name_buff[FN_REFLEN], src_db_name_buff[FN_REFLEN]; uint dst_path_length; char *db= table->db; char *table_name= table->table_name; char *src_db; char *src_table= table_ident->table.str; int err; - bool res= TRUE; + bool res= TRUE, unlock_dst_table= FALSE; enum legacy_db_type not_used; HA_CREATE_INFO *create_info; - TABLE_LIST src_tables_list; + TABLE_LIST src_tables_list, dst_tables_list; DBUG_ENTER("mysql_create_like_table"); if (!(create_info= copy_create_info(lex_create_info))) @@ -4609,13 +4637,6 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, DBUG_RETURN(-1); } - bzero((gptr)&src_tables_list, sizeof(src_tables_list)); - src_tables_list.db= src_db; - src_tables_list.table_name= src_table; - - if (lock_and_wait_for_table_name(thd, &src_tables_list)) - goto err; - if ((tmp_table= find_temporary_table(thd, src_db, src_table))) strxmov(src_path, tmp_table->s->path.str, reg_ext, NullS); else @@ -4642,6 +4663,34 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, goto err; } + if (lower_case_table_names) + { + if (src_db) + { + strmake(src_db_name_buff, src_db, + min(sizeof(src_db_name_buff) - 1, table_ident->db.length)); + my_casedn_str(files_charset_info, src_db_name_buff); + src_db= src_db_name_buff; + } + if (src_table) + { + strmake(src_table_name_buff, src_table, + min(sizeof(src_table_name_buff) - 1, table_ident->table.length)); + my_casedn_str(files_charset_info, src_table_name_buff); + src_table= src_table_name_buff; + } + } + + bzero((gptr)&src_tables_list, sizeof(src_tables_list)); + src_tables_list.db= src_db; + src_tables_list.db_length= table_ident->db.length; + src_tables_list.lock_type= TL_READ; + src_tables_list.table_name= src_table; + src_tables_list.alias= src_table; + + if (simple_open_n_lock_tables(thd, &src_tables_list)) + DBUG_RETURN(TRUE); + /* Validate the destination table @@ -4745,17 +4794,29 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table, char buf[2048]; String query(buf, sizeof(buf), system_charset_info); query.length(0); // Have to zero it since constructor doesn't - TABLE *table_ptr; - int error; + uint counter; /* - Let's open and lock the table: it will be closed (and - unlocked) by close_thread_tables() at the end of the - statement anyway. - */ - if (!(table_ptr= open_ltable(thd, table, TL_READ_NO_INSERT))) + Here we open the destination table. This is needed for + store_create_info() to work. The table will be closed + by close_thread_tables() at the end of the statement. + */ + if (open_tables(thd, &table, &counter, 0)) goto err; + bzero((gptr)&dst_tables_list, sizeof(dst_tables_list)); + dst_tables_list.db= table->db; + dst_tables_list.table_name= table->table_name; + + /* + lock destination table name, to make sure that nobody + can drop/alter the table while we execute store_create_info() + */ + if (lock_and_wait_for_table_name(thd, &dst_tables_list)) + goto err; + else + unlock_dst_table= TRUE; + int result= store_create_info(thd, table, &query, create_info); DBUG_ASSERT(result == 0); // store_create_info() always return 0 @@ -4788,9 +4849,12 @@ table_exists: my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name); err: - pthread_mutex_lock(&LOCK_open); - unlock_table_name(thd, &src_tables_list); - pthread_mutex_unlock(&LOCK_open); + if (unlock_dst_table) + { + pthread_mutex_lock(&LOCK_open); + unlock_table_name(thd, &dst_tables_list); + pthread_mutex_unlock(&LOCK_open); + } DBUG_RETURN(res); } @@ -5179,33 +5243,23 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, LINT_INIT(index_add_buffer); LINT_INIT(index_drop_buffer); - if (table_list && table_list->db && - !my_strcasecmp(system_charset_info, table_list->db, "mysql") && - table_list->table_name) + if (table_list && table_list->db && table_list->table_name) { - enum enum_table_kind { NOT_LOG_TABLE= 1, GENERAL_LOG, SLOW_LOG } - table_kind= NOT_LOG_TABLE; + int table_kind= 0; - if (!my_strcasecmp(system_charset_info, table_list->table_name, - "general_log")) - table_kind= GENERAL_LOG; - else - if (!my_strcasecmp(system_charset_info, table_list->table_name, - "slow_log")) - table_kind= SLOW_LOG; + table_kind= check_if_log_table(table_list->db_length, table_list->db, + table_list->table_name_length, + table_list->table_name, 0); /* Disable alter of enabled log tables */ - if ((table_kind == GENERAL_LOG && opt_log && - logger.is_general_log_table_enabled()) || - (table_kind == SLOW_LOG && opt_slow_log && - logger.is_slow_log_table_enabled())) + if (table_kind && logger.is_log_table_enabled(table_kind)) { my_error(ER_BAD_LOG_STATEMENT, MYF(0), "ALTER"); DBUG_RETURN(TRUE); } /* Disable alter of log tables to unsupported engine */ - if ((table_kind == GENERAL_LOG || table_kind == SLOW_LOG) && + if (table_kind && (lex_create_info->used_fields & HA_CREATE_USED_ENGINE) && (!lex_create_info->db_type || /* unknown engine */ !(lex_create_info->db_type->flags & HTON_SUPPORT_LOG_TABLES))) @@ -5234,6 +5288,7 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */ if (alter_info->tablespace_op != NO_TABLESPACE_OP) + /* Conditionally writes to binlog. */ DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list, alter_info->tablespace_op)); strxnmov(new_name_buff, sizeof (new_name_buff) - 1, mysql_data_home, "/", db, @@ -5389,10 +5444,10 @@ view_err: !table->s->tmp_table) // no need to touch frm { error=0; + VOID(pthread_mutex_lock(&LOCK_open)); if (new_name != table_name || new_db != db) { thd->proc_info="rename"; - VOID(pthread_mutex_lock(&LOCK_open)); /* Then do a 'simple' rename of the table */ error=0; if (!access(new_name_buff,F_OK)) @@ -5415,7 +5470,6 @@ view_err: error= -1; } } - VOID(pthread_mutex_unlock(&LOCK_open)); } if (!error) @@ -5424,16 +5478,12 @@ view_err: case LEAVE_AS_IS: break; case ENABLE: - VOID(pthread_mutex_lock(&LOCK_open)); wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); - VOID(pthread_mutex_unlock(&LOCK_open)); error= table->file->enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE); /* COND_refresh will be signaled in close_thread_tables() */ break; case DISABLE: - VOID(pthread_mutex_lock(&LOCK_open)); wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN); - VOID(pthread_mutex_unlock(&LOCK_open)); error=table->file->disable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE); /* COND_refresh will be signaled in close_thread_tables() */ break; @@ -5458,6 +5508,7 @@ view_err: table->file->print_error(error, MYF(0)); error= -1; } + VOID(pthread_mutex_unlock(&LOCK_open)); table_list->table=0; // For query cache query_cache_invalidate3(thd, table_list, 0); DBUG_RETURN(error); @@ -6458,7 +6509,7 @@ end_temporary: thd->some_tables_deleted=0; DBUG_RETURN(FALSE); - err1: +err1: if (new_table) { /* close_temporary_table() frees the new_table pointer. */ @@ -6467,7 +6518,7 @@ end_temporary: else VOID(quick_rm_table(new_db_type, new_db, tmp_name, FN_IS_TMP)); - err: +err: DBUG_RETURN(TRUE); } /* mysql_alter_table */ diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index acb7d5b61df..fb56b7ae3b0 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -36,17 +36,17 @@ static File_option triggers_file_parameters[]= { { { C_STRING_WITH_LEN("triggers") }, - offsetof(class Table_triggers_list, definitions_list), + my_offsetof(class Table_triggers_list, definitions_list), FILE_OPTIONS_STRLIST }, { { C_STRING_WITH_LEN("sql_modes") }, - offsetof(class Table_triggers_list, definition_modes_list), + my_offsetof(class Table_triggers_list, definition_modes_list), FILE_OPTIONS_ULLLIST }, { { C_STRING_WITH_LEN("definers") }, - offsetof(class Table_triggers_list, definers_list), + my_offsetof(class Table_triggers_list, definers_list), FILE_OPTIONS_STRLIST }, { { 0, 0 }, 0, FILE_OPTIONS_STRING } @@ -55,7 +55,7 @@ static File_option triggers_file_parameters[]= File_option sql_modes_parameters= { { C_STRING_WITH_LEN("sql_modes") }, - offsetof(class Table_triggers_list, definition_modes_list), + my_offsetof(class Table_triggers_list, definition_modes_list), FILE_OPTIONS_ULLLIST }; @@ -276,8 +276,6 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) table->triggers->drop_trigger(thd, tables, &stmt_query)); end: - VOID(pthread_mutex_unlock(&LOCK_open)); - start_waiting_global_read_lock(thd); if (!result) { @@ -286,13 +284,16 @@ end: thd->clear_error(); /* Such a statement can always go directly to binlog, no trans cache. */ - Query_log_event qinfo(thd, stmt_query.ptr(), stmt_query.length(), 0, - FALSE); - mysql_bin_log.write(&qinfo); + thd->binlog_query(THD::STMT_QUERY_TYPE, + stmt_query.ptr(), stmt_query.length(), FALSE, FALSE); } + } + + VOID(pthread_mutex_unlock(&LOCK_open)); + start_waiting_global_read_lock(thd); + if (!result) send_ok(thd); - } DBUG_RETURN(result); } diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 3e6a3944093..722a99eb2d1 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -496,7 +496,12 @@ bool st_select_lex_unit::exec() DBUG_RETURN(res); } /* Needed for the following test and for records_at_start in next loop */ - table->file->info(HA_STATUS_VARIABLE); + int error= table->file->info(HA_STATUS_VARIABLE); + if(error) + { + table->file->print_error(error, MYF(0)); + DBUG_RETURN(1); + } if (found_rows_for_union && !sl->braces && select_limit_cnt != HA_POS_ERROR) { @@ -689,7 +694,17 @@ bool st_select_lex_unit::change_result(select_subselect *result, List<Item> *st_select_lex_unit::get_unit_column_types() { - bool is_union= test(first_select()->next_select()); + SELECT_LEX *sl= first_select(); + bool is_union= test(sl->next_select()); + bool is_procedure= test(sl->join->procedure); + + if (is_procedure) + { + /* Types for "SELECT * FROM t1 procedure analyse()" + are generated during execute */ + return &sl->join->procedure_fields_list; + } + if (is_union) { @@ -697,7 +712,8 @@ List<Item> *st_select_lex_unit::get_unit_column_types() /* Types are generated during prepare */ return &types; } - return &first_select()->item_list; + + return &sl->item_list; } bool st_select_lex::cleanup() diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 32aba5ab74f..2c7c46a8ecb 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -212,6 +212,7 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view) SYNOPSIS mysql_create_view() thd - thread handler + views - views to create mode - VIEW_CREATE_NEW, VIEW_ALTER, VIEW_CREATE_OR_REPLACE RETURN VALUE @@ -219,7 +220,7 @@ fill_defined_view_parts (THD *thd, TABLE_LIST *view) TRUE Error */ -bool mysql_create_view(THD *thd, +bool mysql_create_view(THD *thd, TABLE_LIST *views, enum_view_create_mode mode) { LEX *lex= thd->lex; @@ -236,25 +237,9 @@ bool mysql_create_view(THD *thd, bool res= FALSE; DBUG_ENTER("mysql_create_view"); - if (lex->proc_list.first || - lex->result) - { - my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), (lex->result ? - "INTO" : - "PROCEDURE")); - res= TRUE; - goto err; - } - if (lex->derived_tables || - lex->variables_used || lex->param_list.elements) - { - int err= (lex->derived_tables ? - ER_VIEW_SELECT_DERIVED : - ER_VIEW_SELECT_VARIABLE); - my_message(err, ER(err), MYF(0)); - res= TRUE; - goto err; - } + /* This is ensured in the parser. */ + DBUG_ASSERT(!lex->proc_list.first && !lex->result && + !lex->param_list.elements && !lex->derived_tables); if (mode != VIEW_CREATE_NEW) { @@ -548,6 +533,49 @@ bool mysql_create_view(THD *thd, } VOID(pthread_mutex_lock(&LOCK_open)); res= mysql_register_view(thd, view, mode); + + if (mysql_bin_log.is_open()) + { + String buff; + const LEX_STRING command[3]= + {{ C_STRING_WITH_LEN("CREATE ") }, + { C_STRING_WITH_LEN("ALTER ") }, + { C_STRING_WITH_LEN("CREATE OR REPLACE ") }}; + + buff.append(command[thd->lex->create_view_mode].str, + command[thd->lex->create_view_mode].length); + view_store_options(thd, views, &buff); + buff.append(STRING_WITH_LEN("VIEW ")); + /* Test if user supplied a db (ie: we did not use thd->db) */ + if (views->db && views->db[0] && + (thd->db == NULL || strcmp(views->db, thd->db))) + { + append_identifier(thd, &buff, views->db, + views->db_length); + buff.append('.'); + } + append_identifier(thd, &buff, views->table_name, + views->table_name_length); + if (lex->view_list.elements) + { + List_iterator_fast<LEX_STRING> names(lex->view_list); + LEX_STRING *name; + int i; + + for (i= 0; name= names++; i++) + { + buff.append(i ? ", " : "("); + append_identifier(thd, &buff, name->str, name->length); + } + buff.append(')'); + } + buff.append(STRING_WITH_LEN(" AS ")); + buff.append(views->source.str, views->source.length); + + thd->binlog_query(THD::STMT_QUERY_TYPE, + buff.ptr(), buff.length(), FALSE, FALSE); + } + VOID(pthread_mutex_unlock(&LOCK_open)); if (view->revision != 1) query_cache_invalidate3(thd, view, 0); @@ -582,40 +610,40 @@ static const int num_view_backups= 3; */ static File_option view_parameters[]= {{{ C_STRING_WITH_LEN("query")}, - offsetof(TABLE_LIST, query), + my_offsetof(TABLE_LIST, query), FILE_OPTIONS_ESTRING}, {{ C_STRING_WITH_LEN("md5")}, - offsetof(TABLE_LIST, md5), + my_offsetof(TABLE_LIST, md5), FILE_OPTIONS_STRING}, {{ C_STRING_WITH_LEN("updatable")}, - offsetof(TABLE_LIST, updatable_view), + my_offsetof(TABLE_LIST, updatable_view), FILE_OPTIONS_ULONGLONG}, {{ C_STRING_WITH_LEN("algorithm")}, - offsetof(TABLE_LIST, algorithm), + my_offsetof(TABLE_LIST, algorithm), FILE_OPTIONS_ULONGLONG}, {{ C_STRING_WITH_LEN("definer_user")}, - offsetof(TABLE_LIST, definer.user), + my_offsetof(TABLE_LIST, definer.user), FILE_OPTIONS_STRING}, {{ C_STRING_WITH_LEN("definer_host")}, - offsetof(TABLE_LIST, definer.host), + my_offsetof(TABLE_LIST, definer.host), FILE_OPTIONS_STRING}, {{ C_STRING_WITH_LEN("suid")}, - offsetof(TABLE_LIST, view_suid), + my_offsetof(TABLE_LIST, view_suid), FILE_OPTIONS_ULONGLONG}, {{ C_STRING_WITH_LEN("with_check_option")}, - offsetof(TABLE_LIST, with_check), + my_offsetof(TABLE_LIST, with_check), FILE_OPTIONS_ULONGLONG}, {{ C_STRING_WITH_LEN("revision")}, - offsetof(TABLE_LIST, revision), + my_offsetof(TABLE_LIST, revision), FILE_OPTIONS_REV}, {{ C_STRING_WITH_LEN("timestamp")}, - offsetof(TABLE_LIST, timestamp), + my_offsetof(TABLE_LIST, timestamp), FILE_OPTIONS_TIMESTAMP}, {{ C_STRING_WITH_LEN("create-version")}, - offsetof(TABLE_LIST, file_version), + my_offsetof(TABLE_LIST, file_version), FILE_OPTIONS_ULONGLONG}, {{ C_STRING_WITH_LEN("source")}, - offsetof(TABLE_LIST, source), + my_offsetof(TABLE_LIST, source), FILE_OPTIONS_ESTRING}, {{NullS, 0}, 0, FILE_OPTIONS_STRING} @@ -1318,13 +1346,13 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) enum legacy_db_type not_used; DBUG_ENTER("mysql_drop_view"); + VOID(pthread_mutex_lock(&LOCK_open)); for (view= views; view; view= view->next_local) { TABLE_SHARE *share; frm_type_enum type= FRMTYPE_ERROR; build_table_filename(path, sizeof(path), view->db, view->table_name, reg_ext, 0); - VOID(pthread_mutex_lock(&LOCK_open)); if (access(path, F_OK) || FRMTYPE_VIEW != (type= mysql_frm_type(thd, path, ¬_used))) @@ -1336,7 +1364,6 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR), name); - VOID(pthread_mutex_unlock(&LOCK_open)); continue; } if (type == FRMTYPE_TABLE) @@ -1353,7 +1380,6 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) non_existant_views.append(','); non_existant_views.append(String(view->table_name,system_charset_info)); } - VOID(pthread_mutex_unlock(&LOCK_open)); continue; } if (my_delete(path, MYF(MY_WME))) @@ -1374,24 +1400,36 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) } query_cache_invalidate3(thd, view, 0); sp_cache_invalidate(); - VOID(pthread_mutex_unlock(&LOCK_open)); } + if (error) { + VOID(pthread_mutex_unlock(&LOCK_open)); DBUG_RETURN(TRUE); } if (wrong_object_name) { + VOID(pthread_mutex_unlock(&LOCK_open)); my_error(ER_WRONG_OBJECT, MYF(0), wrong_object_db, wrong_object_name, "VIEW"); DBUG_RETURN(TRUE); } if (non_existant_views.length()) { + VOID(pthread_mutex_unlock(&LOCK_open)); my_error(ER_BAD_TABLE_ERROR, MYF(0), non_existant_views.c_ptr()); DBUG_RETURN(TRUE); } + + if (mysql_bin_log.is_open()) + { + thd->clear_error(); + thd->binlog_query(THD::STMT_QUERY_TYPE, + thd->query, thd->query_length, FALSE, FALSE); + } + send_ok(thd); + VOID(pthread_mutex_unlock(&LOCK_open)); DBUG_RETURN(FALSE); } diff --git a/sql/sql_view.h b/sql/sql_view.h index 7e54d57cfdf..fc480167216 100644 --- a/sql/sql_view.h +++ b/sql/sql_view.h @@ -16,7 +16,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -bool mysql_create_view(THD *thd, +bool mysql_create_view(THD *thd, TABLE_LIST *view, enum_view_create_mode mode); bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 26dea00029a..adada9252f9 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -793,7 +793,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %type <item> literal text_literal insert_ident order_ident simple_ident select_item2 expr opt_expr opt_else sum_expr in_sum_expr - bool_term bool_factor bool_test bool_pri + variable variable_aux bool_term bool_factor bool_test bool_pri predicate bit_expr bit_term bit_factor value_expr term factor table_wild simple_expr udf_expr expr_or_default set_expr_or_default interval_expr @@ -1421,6 +1421,7 @@ opt_ev_comment: /* empty */ { $$= 0; } | COMMENT_SYM TEXT_STRING_sys { Lex->comment= Lex->event_parse_data->comment= $2; + $$= 1; } ; @@ -1724,15 +1725,20 @@ call: lex->value_list.empty(); sp_add_used_routine(lex, YYTHD, $2, TYPE_ENUM_PROCEDURE); } - '(' sp_cparam_list ')' {} + opt_sp_cparam_list {} ; /* CALL parameters */ -sp_cparam_list: +opt_sp_cparam_list: /* Empty */ - | sp_cparams + | '(' opt_sp_cparams ')' ; +opt_sp_cparams: + /* Empty */ + | sp_cparams + ; + sp_cparams: sp_cparams ',' expr { @@ -3225,6 +3231,7 @@ opt_partitioning: partitioning: PARTITION_SYM { +#ifdef WITH_PARTITION_STORAGE_ENGINE LEX *lex= Lex; lex->part_info= new partition_info(); if (!lex->part_info) @@ -3236,6 +3243,12 @@ partitioning: { lex->alter_info.flags|= ALTER_PARTITION; } +#else + my_error(ER_FEATURE_DISABLED, MYF(0), + "partitioning", "--with-partition"); + YYABORT; +#endif + } partition ; @@ -5953,32 +5966,7 @@ simple_expr: } | literal | param_marker - | '@' ident_or_text SET_VAR expr - { - $$= new Item_func_set_user_var($2,$4); - LEX *lex= Lex; - lex->uncacheable(UNCACHEABLE_RAND); - lex->variables_used= 1; - } - | '@' ident_or_text - { - $$= new Item_func_get_user_var($2); - LEX *lex= Lex; - lex->uncacheable(UNCACHEABLE_RAND); - lex->variables_used= 1; - } - | '@' '@' opt_var_ident_type ident_or_text opt_component - { - - if ($4.str && $5.str && check_reserved_words(&$4)) - { - yyerror(ER(ER_SYNTAX_ERROR)); - YYABORT; - } - if (!($$= get_system_var(YYTHD, $3, $4, $5))) - YYABORT; - Lex->variables_used= 1; - } + | variable | sum_expr | simple_expr OR_OR_SYM simple_expr { $$= new Item_func_concat($1, $3); } @@ -6701,6 +6689,46 @@ sum_expr: $5->empty(); }; +variable: + '@' + { + if (! Lex->parsing_options.allows_variable) + { + my_error(ER_VIEW_SELECT_VARIABLE, MYF(0)); + YYABORT; + } + } + variable_aux + { + $$= $3; + } + ; + +variable_aux: + ident_or_text SET_VAR expr + { + $$= new Item_func_set_user_var($1, $3); + LEX *lex= Lex; + lex->uncacheable(UNCACHEABLE_RAND); + } + | ident_or_text + { + $$= new Item_func_get_user_var($1); + LEX *lex= Lex; + lex->uncacheable(UNCACHEABLE_RAND); + } + | '@' opt_var_ident_type ident_or_text opt_component + { + if ($3.str && $4.str && check_reserved_words(&$3)) + { + yyerror(ER(ER_SYNTAX_ERROR)); + YYABORT; + } + if (!($$= get_system_var(YYTHD, $2, $3, $4))) + YYABORT; + } + ; + opt_distinct: /* empty */ { $$ = 0; } |DISTINCT { $$ = 1; }; @@ -6807,7 +6835,7 @@ when_list2: /* Warning - may return NULL in case of incomplete SELECT */ table_ref: table_factor { $$=$1; } - | join_table { $$=$1; } + | join_table { LEX *lex= Lex; if (!($$= lex->current_select->nest_last_join(lex->thd))) @@ -6849,7 +6877,7 @@ join_table: | table_ref normal_join table_ref ON { - YYERROR_UNLESS($1 && ($$=$3)); + YYERROR_UNLESS($1 && $3); /* Change the current name resolution context to a local context. */ if (push_new_name_resolution_context(YYTHD, $1, $3)) YYABORT; @@ -6864,7 +6892,7 @@ join_table: | table_ref STRAIGHT_JOIN table_factor ON { - YYERROR_UNLESS($1 && ($$=$3)); + YYERROR_UNLESS($1 && $3); /* Change the current name resolution context to a local context. */ if (push_new_name_resolution_context(YYTHD, $1, $3)) YYABORT; @@ -7130,6 +7158,13 @@ select_derived_init: SELECT_SYM { LEX *lex= Lex; + + if (! lex->parsing_options.allows_derived) + { + my_error(ER_VIEW_SELECT_DERIVED, MYF(0)); + YYABORT; + } + SELECT_LEX *sel= lex->current_select; TABLE_LIST *embedding; if (!sel->embedding || sel->end_nested_join(lex->thd)) @@ -7514,6 +7549,13 @@ procedure_clause: | PROCEDURE ident /* Procedure name */ { LEX *lex=Lex; + + if (! lex->parsing_options.allows_select_procedure) + { + my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "PROCEDURE"); + YYABORT; + } + if (&lex->select_lex != lex->current_select) { my_error(ER_WRONG_USAGE, MYF(0), "PROCEDURE", "subquery"); @@ -7613,28 +7655,40 @@ select_var_ident: ; into: - INTO OUTFILE TEXT_STRING_filesystem + INTO + { + if (! Lex->parsing_options.allows_select_into) + { + my_error(ER_VIEW_SELECT_CLAUSE, MYF(0), "INTO"); + YYABORT; + } + } + into_destination + ; + +into_destination: + OUTFILE TEXT_STRING_filesystem { LEX *lex= Lex; lex->uncacheable(UNCACHEABLE_SIDEEFFECT); - if (!(lex->exchange= new sql_exchange($3.str, 0)) || + if (!(lex->exchange= new sql_exchange($2.str, 0)) || !(lex->result= new select_export(lex->exchange))) YYABORT; } opt_field_term opt_line_term - | INTO DUMPFILE TEXT_STRING_filesystem + | DUMPFILE TEXT_STRING_filesystem { LEX *lex=Lex; if (!lex->describe) { lex->uncacheable(UNCACHEABLE_SIDEEFFECT); - if (!(lex->exchange= new sql_exchange($3.str,1))) + if (!(lex->exchange= new sql_exchange($2.str,1))) YYABORT; if (!(lex->result= new select_dump(lex->exchange))) YYABORT; } } - | INTO select_var_list_init + | select_var_list_init { Lex->uncacheable(UNCACHEABLE_SIDEEFFECT); } @@ -8843,8 +8897,13 @@ param_marker: { THD *thd=YYTHD; LEX *lex= thd->lex; - Item_param *item= new Item_param((uint) (lex->tok_start - - (uchar *) thd->query)); + Item_param *item; + if (! lex->parsing_options.allows_variable) + { + my_error(ER_VIEW_SELECT_VARIABLE, MYF(0)); + YYABORT; + } + item= new Item_param((uint) (lex->tok_start - (uchar *) thd->query)); if (!($$= item) || lex->param_list.push_back(item)) { my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0)); @@ -8964,6 +9023,12 @@ simple_ident: if (spc && (spv = spc->find_variable(&$1))) { /* We're compiling a stored procedure and found a variable */ + if (! lex->parsing_options.allows_variable) + { + my_error(ER_VIEW_SELECT_VARIABLE, MYF(0)); + YYABORT; + } + Item_splocal *splocal; splocal= new Item_splocal($1, spv->offset, spv->type, lex->tok_start_prev - @@ -8973,7 +9038,6 @@ simple_ident: splocal->m_sp= lex->sphead; #endif $$ = (Item*) splocal; - lex->variables_used= 1; lex->safe_to_cache_query=0; } else @@ -10872,6 +10936,24 @@ view_list: ; view_select: + { + LEX *lex= Lex; + lex->parsing_options.allows_variable= FALSE; + lex->parsing_options.allows_select_into= FALSE; + lex->parsing_options.allows_select_procedure= FALSE; + lex->parsing_options.allows_derived= FALSE; + } + view_select_aux + { + LEX *lex= Lex; + lex->parsing_options.allows_variable= TRUE; + lex->parsing_options.allows_select_into= TRUE; + lex->parsing_options.allows_select_procedure= TRUE; + lex->parsing_options.allows_derived= TRUE; + } + ; + +view_select_aux: SELECT_SYM remember_name select_init2 { THD *thd=YYTHD; diff --git a/sql/stacktrace.c b/sql/stacktrace.c index a2fe2ab88f1..77e7707592d 100644 --- a/sql/stacktrace.c +++ b/sql/stacktrace.c @@ -186,7 +186,7 @@ terribly wrong...\n"); #if defined(__alpha__) && defined(__GNUC__) uchar** new_fp = find_prev_fp(pc, fp); - if (frame_count == SIGRETURN_FRAME_COUNT - 1) + if (frame_count == sigreturn_frame_count - 1) { new_fp += 90; } diff --git a/sql/strfunc.cc b/sql/strfunc.cc index 2525703172f..ef769a5b16e 100644 --- a/sql/strfunc.cc +++ b/sql/strfunc.cc @@ -312,3 +312,33 @@ outp: return (uint32) (to - to_start); } + + +/* + Searches for a LEX_STRING in an LEX_STRING array. + + SYNOPSIS + find_string_in_array() + heap The array + needle The string to search for + + NOTE + The last LEX_STRING in the array should have str member set to NULL + + RETURN VALUES + -1 Not found + >=0 Ordinal position +*/ + +int find_string_in_array(LEX_STRING * const haystack, LEX_STRING * const needle, + CHARSET_INFO * const cs) +{ + const LEX_STRING *pos; + for (pos= haystack; pos->str; pos++) + if (!cs->coll->strnncollsp(cs, (uchar *) pos->str, pos->length, + (uchar *) needle->str, needle->length, 0)) + { + return (pos - haystack); + } + return -1; +} diff --git a/sql/table.cc b/sql/table.cc index 8505b15459b..df09b322ff8 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -363,25 +363,24 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) error= open_binary_frm(thd, share, head, file); *root_ptr= old_root; - if (share->db.length == 5 && - !my_strcasecmp(system_charset_info, share->db.str, "mysql")) + if (share->db.length == 5 && !(lower_case_table_names ? + my_strcasecmp(system_charset_info, share->db.str, "mysql") : + strcmp(share->db.str, "mysql"))) { /* We can't mark all tables in 'mysql' database as system since we don't allow to lock such tables for writing with any other tables (even with other system tables) and some privilege tables need this. */ - if (!my_strcasecmp(system_charset_info, share->table_name.str, "proc")) + if (!(lower_case_table_names ? + my_strcasecmp(system_charset_info, share->table_name.str, "proc") : + strcmp(share->table_name.str, "proc"))) share->system_table= 1; else { - if (!my_strcasecmp(system_charset_info, share->table_name.str, - "general_log")) - share->log_table= QUERY_LOG_GENERAL; - else - if (!my_strcasecmp(system_charset_info, share->table_name.str, - "slow_log")) - share->log_table= QUERY_LOG_SLOW; + share->log_table= check_if_log_table(share->db.length, share->db.str, + share->table_name.length, + share->table_name.str, 0); } } error_given= 1; @@ -1182,7 +1181,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, as we need to test for NULL = NULL. */ if (field->real_maybe_null()) - key_part->key_part_flag|= HA_PART_KEY_SEG; + key_part->key_part_flag|= HA_NULL_PART; } keyinfo->usable_key_parts= usable_parts; // Filesort diff --git a/sql/time.cc b/sql/time.cc index 0461f7723c6..25a1995dd01 100644 --- a/sql/time.cc +++ b/sql/time.cc @@ -25,14 +25,25 @@ #ifndef TESTTIME +/* + Name description of interval names used in statements. + + 'interval_type_to_name' is ordered and sorted on interval size and + interval complexity. + Order of elements in 'interval_type_to_name' should correspond to + the order of elements in 'interval_type' enum + + See also interval_type, interval_names +*/ + LEX_STRING interval_type_to_name[INTERVAL_LAST] = { { C_STRING_WITH_LEN("YEAR")}, { C_STRING_WITH_LEN("QUARTER")}, { C_STRING_WITH_LEN("MONTH")}, + { C_STRING_WITH_LEN("WEEK")}, { C_STRING_WITH_LEN("DAY")}, { C_STRING_WITH_LEN("HOUR")}, { C_STRING_WITH_LEN("MINUTE")}, - { C_STRING_WITH_LEN("WEEK")}, { C_STRING_WITH_LEN("SECOND")}, { C_STRING_WITH_LEN("MICROSECOND")}, { C_STRING_WITH_LEN("YEAR_MONTH")}, @@ -278,9 +289,9 @@ my_time_t TIME_to_timestamp(THD *thd, const TIME *t, my_bool *in_dst_time_gap) bool str_to_time_with_warn(const char *str, uint length, TIME *l_time) { - int was_cut; - bool ret_val= str_to_time(str, length, l_time, &was_cut); - if (was_cut) + int warning; + bool ret_val= str_to_time(str, length, l_time, &warning); + if (ret_val || warning) make_truncated_value_warning(current_thd, str, length, MYSQL_TIMESTAMP_TIME, NullS); return ret_val; diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index b7673fc96ea..b2b07981bdb 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -1433,7 +1433,7 @@ void ha_archive::update_create_info(HA_CREATE_INFO *create_info) /* Hints for optimizer, see ha_tina for more information */ -void ha_archive::info(uint flag) +int ha_archive::info(uint flag) { DBUG_ENTER("ha_archive::info"); /* @@ -1461,7 +1461,7 @@ void ha_archive::info(uint flag) if (flag & HA_STATUS_AUTO) stats.auto_increment_value= share->auto_increment_value; - DBUG_VOID_RETURN; + DBUG_RETURN(0); } diff --git a/storage/archive/ha_archive.h b/storage/archive/ha_archive.h index 1a601c8451a..75ca29e640a 100644 --- a/storage/archive/ha_archive.h +++ b/storage/archive/ha_archive.h @@ -121,7 +121,7 @@ public: int read_data_header(azio_stream *file_to_read); int write_data_header(azio_stream *file_to_write); void position(const byte *record); - void info(uint); + int info(uint); void update_create_info(HA_CREATE_INFO *create_info); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); int optimize(THD* thd, HA_CHECK_OPT* check_opt); diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index 2515f059e02..64e716584a7 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -120,14 +120,14 @@ void ha_blackhole::position(const byte *record) } -void ha_blackhole::info(uint flag) +int ha_blackhole::info(uint flag) { DBUG_ENTER("ha_blackhole::info"); bzero((char*) &stats, sizeof(stats)); if (flag & HA_STATUS_AUTO) stats.auto_increment_value= 1; - DBUG_VOID_RETURN; + DBUG_RETURN(0); } int ha_blackhole::external_lock(THD *thd, int lock_type) diff --git a/storage/blackhole/ha_blackhole.h b/storage/blackhole/ha_blackhole.h index 54cec41fd26..667c18a594b 100644 --- a/storage/blackhole/ha_blackhole.h +++ b/storage/blackhole/ha_blackhole.h @@ -75,7 +75,7 @@ public: int index_first(byte * buf); int index_last(byte * buf); void position(const byte *record); - void info(uint flag); + int info(uint flag); int external_lock(THD *thd, int lock_type); uint lock_count(void) const; int create(const char *name, TABLE *table_arg, diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index dad28a74af6..f7e5aa9d50c 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -826,9 +826,9 @@ void ha_tina::update_status() bool ha_tina::check_if_locking_is_allowed(uint sql_command, ulong type, TABLE *table, uint count, - bool called_by_logger_thread) + bool called_by_privileged_thread) { - if (!called_by_logger_thread) + if (!called_by_privileged_thread) return check_if_log_table_locking_is_allowed(sql_command, type, table); return TRUE; @@ -1128,13 +1128,13 @@ int ha_tina::rnd_pos(byte * buf, byte *pos) Currently this table handler doesn't implement most of the fields really needed. SHOW also makes use of this data */ -void ha_tina::info(uint flag) +int ha_tina::info(uint flag) { DBUG_ENTER("ha_tina::info"); /* This is a lie, but you don't want the optimizer to see zero or 1 */ if (!records_is_known && stats.records < 2) stats.records= 2; - DBUG_VOID_RETURN; + DBUG_RETURN(0); } /* diff --git a/storage/csv/ha_tina.h b/storage/csv/ha_tina.h index f408e8f4a7d..def88e8c471 100644 --- a/storage/csv/ha_tina.h +++ b/storage/csv/ha_tina.h @@ -189,7 +189,7 @@ public: /* This is required for SQL layer to know that we support autorepair */ bool auto_repair() const { return 1; } void position(const byte *record); - void info(uint); + int info(uint); int extra(enum ha_extra_function operation); int delete_all_rows(void); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index 212def8c18e..6d199d4391f 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -530,10 +530,10 @@ int ha_example::rnd_pos(byte * buf, byte *pos) sql_update.cc */ -void ha_example::info(uint flag) +int ha_example::info(uint flag) { DBUG_ENTER("ha_example::info"); - DBUG_VOID_RETURN; + DBUG_RETURN(0); } diff --git a/storage/example/ha_example.h b/storage/example/ha_example.h index 2f5dbc29c56..f98377ee157 100644 --- a/storage/example/ha_example.h +++ b/storage/example/ha_example.h @@ -136,7 +136,7 @@ public: int rnd_next(byte *buf); //required int rnd_pos(byte * buf, byte *pos); //required void position(const byte *record); //required - void info(uint); //required + int info(uint); //required int extra(enum ha_extra_function operation); int reset(void); diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index 00b2ac87cd4..51c9f4c192e 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -2490,7 +2490,7 @@ int ha_federated::rnd_pos(byte *buf, byte *pos) */ -void ha_federated::info(uint flag) +int ha_federated::info(uint flag) { char error_buffer[FEDERATED_QUERY_BUFFER_SIZE]; char status_buf[FEDERATED_QUERY_BUFFER_SIZE]; @@ -2571,7 +2571,7 @@ void ha_federated::info(uint flag) if (result) mysql_free_result(result); - DBUG_VOID_RETURN; + DBUG_RETURN(0); error: if (result) @@ -2580,7 +2580,7 @@ error: my_sprintf(error_buffer, (error_buffer, ": %d : %s", mysql_errno(mysql), mysql_error(mysql))); my_error(error_code, MYF(0), error_buffer); - DBUG_VOID_RETURN; + DBUG_RETURN(error_code); } diff --git a/storage/federated/ha_federated.h b/storage/federated/ha_federated.h index ade1e5b181e..d1b485d63e2 100644 --- a/storage/federated/ha_federated.h +++ b/storage/federated/ha_federated.h @@ -206,7 +206,7 @@ public: int rnd_next(byte *buf); //required int rnd_pos(byte *buf, byte *pos); //required void position(const byte *record); //required - void info(uint); //required + int info(uint); //required void update_auto_increment(void); int repair(THD* thd, HA_CHECK_OPT* check_opt); diff --git a/storage/federated/plug.in b/storage/federated/plug.in index 81c56cb672f..23b607d699b 100644 --- a/storage/federated/plug.in +++ b/storage/federated/plug.in @@ -2,3 +2,4 @@ MYSQL_STORAGE_ENGINE(federated,,[Federated Storage Engine], [Connects to tables on remote MySQL servers], [max,max-no-ndb]) MYSQL_PLUGIN_STATIC(federated, [libfederated.a]) MYSQL_PLUGIN_DYNAMIC(federated, [ha_federated.la]) +MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS(federated, [ha_federated.cc]) diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index 8e8744c2d34..dc49e8978c0 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -342,7 +342,7 @@ void ha_heap::position(const byte *record) *(HEAP_PTR*) ref= heap_position(file); // Ref is aligned } -void ha_heap::info(uint flag) +int ha_heap::info(uint flag) { HEAPINFO info; (void) heap_info(file,&info,flag); @@ -364,6 +364,7 @@ void ha_heap::info(uint flag) */ if (key_stat_version != file->s->key_stat_version) update_key_stats(); + return 0; } diff --git a/storage/heap/ha_heap.h b/storage/heap/ha_heap.h index 0f6386655cb..f0c01d5e3a5 100644 --- a/storage/heap/ha_heap.h +++ b/storage/heap/ha_heap.h @@ -89,7 +89,7 @@ public: int rnd_next(byte *buf); int rnd_pos(byte * buf, byte *pos); void position(const byte *record); - void info(uint); + int info(uint); int extra(enum ha_extra_function operation); int reset(); int external_lock(THD *thd, int lock_type); diff --git a/storage/heap/plug.in b/storage/heap/plug.in index 9e744b6ac0d..50f31c60f2b 100644 --- a/storage/heap/plug.in +++ b/storage/heap/plug.in @@ -3,4 +3,5 @@ MYSQL_STORAGE_ENGINE(heap,no, [Memory Storage Engine], MYSQL_PLUGIN_DIRECTORY(heap, [storage/heap]) MYSQL_PLUGIN_STATIC(heap, [libheap.a]) MYSQL_PLUGIN_MANDATORY(heap) dnl Memory tables +MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS(heap, [ha_heap.cc]) diff --git a/storage/innobase/btr/btr0btr.c b/storage/innobase/btr/btr0btr.c index ffaf2065045..7a8e5626e25 100644 --- a/storage/innobase/btr/btr0btr.c +++ b/storage/innobase/btr/btr0btr.c @@ -571,9 +571,6 @@ btr_page_get_father_for_rec( tuple = dict_index_build_node_ptr(index, user_rec, 0, heap, btr_page_get_level(page, mtr)); - /* In the following, we choose just any index from the tree as the - first parameter for btr_cur_search_to_nth_level. */ - btr_cur_search_to_nth_level(index, btr_page_get_level(page, mtr) + 1, tuple, PAGE_CUR_LE, diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index 44a374fe550..7c2fc18accd 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -3547,6 +3547,7 @@ syntax_error: /*==================== END OF FOREIGN KEY PROCESSING ====================*/ +#ifdef UNIV_DEBUG /************************************************************************** Returns an index object if it is found in the dictionary cache. */ @@ -3556,7 +3557,6 @@ dict_index_get_if_in_cache( /* out: index, NULL if not found */ dulint index_id) /* in: index id */ { - dict_table_t* table; dict_index_t* index; if (dict_sys == NULL) { @@ -3565,29 +3565,13 @@ dict_index_get_if_in_cache( mutex_enter(&(dict_sys->mutex)); - table = UT_LIST_GET_FIRST(dict_sys->table_LRU); - - while (table) { - index = UT_LIST_GET_FIRST(table->indexes); - - while (index) { - if (0 == ut_dulint_cmp(index->id, index_id)) { - - goto found; - } + index = dict_index_find_on_id_low(index_id); - index = UT_LIST_GET_NEXT(indexes, index); - } - - table = UT_LIST_GET_NEXT(table_LRU, table); - } - - index = NULL; -found: mutex_exit(&(dict_sys->mutex)); return(index); } +#endif /* UNIV_DEBUG */ #ifdef UNIV_DEBUG /************************************************************************** @@ -4162,18 +4146,8 @@ dict_print_info_on_foreign_key_in_create_format( dict_remove_db_name( foreign->referenced_table_name)); } else { - /* Look for the '/' in the table name */ - - i = 0; - while (foreign->referenced_table_name[i] != '/') { - i++; - } - - ut_print_namel(file, trx, TRUE, - foreign->referenced_table_name, i); - putc('.', file); ut_print_name(file, trx, TRUE, - foreign->referenced_table_name + i + 1); + foreign->referenced_table_name); } putc(' ', file); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 066c0ce48d4..ec86b9a2e68 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -5485,7 +5485,7 @@ ha_innobase::read_time( Returns statistics information of the table to the MySQL interpreter, in various fields of the handle object. */ -void +int ha_innobase::info( /*==============*/ uint flag) /* in: what information MySQL requests */ @@ -5508,7 +5508,7 @@ ha_innobase::info( if (srv_force_recovery >= SRV_FORCE_NO_IBUF_MERGE) { - DBUG_VOID_RETURN; + DBUG_RETURN(HA_ERR_CRASHED); } /* We do not know if MySQL can call this function before calling @@ -5700,7 +5700,7 @@ ha_innobase::info( prebuilt->trx->op_info = (char*)""; - DBUG_VOID_RETURN; + DBUG_RETURN(0); } /************************************************************************** @@ -6630,7 +6630,7 @@ innodb_mutex_show_status( mutex->count_spin_rounds, mutex->count_os_wait, mutex->count_os_yield, - mutex->lspent_time/1000); + (ulong) mutex->lspent_time/1000); if (stat_print(thd, innobase_hton_name, hton_name_len, buf1, buf1len, @@ -6660,7 +6660,7 @@ innodb_mutex_show_status( rw_lock_count, rw_lock_count_spin_loop, rw_lock_count_spin_rounds, rw_lock_count_os_wait, rw_lock_count_os_yield, - rw_lock_wait_time/1000); + (ulong) rw_lock_wait_time/1000); if (stat_print(thd, innobase_hton_name, hton_name_len, STRING_WITH_LEN("rw_lock_mutexes"), buf2, buf2len)) { @@ -6812,7 +6812,8 @@ ha_innobase::store_lock( && lock_type != TL_IGNORE)) { /* The OR cases above are in this order: - 1) MySQL is doing LOCK TABLES ... READ LOCAL, or + 1) MySQL is doing LOCK TABLES ... READ LOCAL, or we + are processing a stored procedure or function, or 2) (we do not know when TL_READ_HIGH_PRIORITY is used), or 3) this is a SELECT ... IN SHARE MODE, or 4) we are doing a complex SQL statement like @@ -6880,7 +6881,8 @@ ha_innobase::store_lock( single transaction stored procedure call deterministic (if it does not use a consistent read). */ - if (lock_type == TL_READ && thd->in_lock_tables) { + if (lock_type == TL_READ + && thd->lex->sql_command == SQLCOM_LOCK_TABLES) { /* We come here if MySQL is processing LOCK TABLES ... READ LOCAL. MyISAM under that table lock type reads the table as it was at the time the lock was @@ -6939,8 +6941,7 @@ ha_innobase::store_lock( (MySQL does have thd->in_lock_tables TRUE there). */ if (lock_type == TL_READ_NO_INSERT - && (!thd->in_lock_tables - || thd->lex->sql_command == SQLCOM_CALL)) { + && thd->lex->sql_command != SQLCOM_LOCK_TABLES) { lock_type = TL_READ; } diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index d6c9b8a0d9f..ea1cf7a32af 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -143,7 +143,7 @@ class ha_innobase: public handler int rnd_pos(byte * buf, byte *pos); void position(const byte *record); - void info(uint); + int info(uint); int analyze(THD* thd,HA_CHECK_OPT* check_opt); int optimize(THD* thd,HA_CHECK_OPT* check_opt); int discard_or_import_tablespace(my_bool discard); diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h index a9775ab3d40..2582effbb29 100644 --- a/storage/innobase/include/dict0dict.h +++ b/storage/innobase/include/dict0dict.h @@ -778,9 +778,8 @@ const dict_col_t* dict_field_get_col( /*===============*/ const dict_field_t* field); -/************************************************************************** -In an index tree, finds the index corresponding to a record in the tree. */ +#ifdef UNIV_DEBUG /************************************************************************** Returns an index object if it is found in the dictionary cache. */ @@ -789,7 +788,6 @@ dict_index_get_if_in_cache( /*=======================*/ /* out: index, NULL if not found */ dulint index_id); /* in: index id */ -#ifdef UNIV_DEBUG /************************************************************************** Checks that a tuple has n_fields_cmp value in a sensible range, so that no comparison can occur with the page number field in a node pointer. */ diff --git a/storage/innobase/include/mem0dbg.h b/storage/innobase/include/mem0dbg.h index 0f4441f4f9d..36cd7a89565 100644 --- a/storage/innobase/include/mem0dbg.h +++ b/storage/innobase/include/mem0dbg.h @@ -30,6 +30,7 @@ check fields at the both ends of the field. */ #define MEM_SPACE_NEEDED(N) ut_calc_align((N), UNIV_MEM_ALIGNMENT) #endif +#if defined UNIV_MEM_DEBUG || defined UNIV_DEBUG /******************************************************************* Checks a memory heap for consistency and prints the contents if requested. Outputs the sum of sizes of buffers given to the user (only in @@ -59,15 +60,8 @@ mem_heap_validate_or_print( ulint* n_blocks); /* out: number of blocks in the heap, if a NULL pointer is passed as this argument, it is ignored */ -#ifdef UNIV_MEM_DEBUG -/****************************************************************** -Prints the contents of a memory heap. */ - -void -mem_heap_print( -/*===========*/ - mem_heap_t* heap); /* in: memory heap */ -#endif /* UNIV_MEM_DEBUG */ +#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */ +#ifdef UNIV_DEBUG /****************************************************************** Checks that an object is a memory heap (or a block of it) */ @@ -76,6 +70,7 @@ mem_heap_check( /*===========*/ /* out: TRUE if ok */ mem_heap_t* heap); /* in: memory heap */ +#endif /* UNIV_DEBUG */ /****************************************************************** Validates the contents of a memory heap. */ diff --git a/storage/innobase/include/mtr0mtr.h b/storage/innobase/include/mtr0mtr.h index 9e8250cb545..2a160d27e0c 100644 --- a/storage/innobase/include/mtr0mtr.h +++ b/storage/innobase/include/mtr0mtr.h @@ -265,6 +265,7 @@ mtr_memo_release( mtr_t* mtr, /* in: mtr */ void* object, /* in: object */ ulint type); /* in: object type: MTR_MEMO_S_LOCK, ... */ +#ifdef UNIV_DEBUG /************************************************************** Checks if memo contains the given item. */ UNIV_INLINE @@ -282,6 +283,7 @@ void mtr_print( /*======*/ mtr_t* mtr); /* in: mtr */ +#endif /* UNIV_DEBUG */ /*######################################################################*/ #define MTR_BUF_MEMO_SIZE 200 /* number of slots in memo */ diff --git a/storage/innobase/include/mtr0mtr.ic b/storage/innobase/include/mtr0mtr.ic index d81f6cb9c0d..81eec3bfc92 100644 --- a/storage/innobase/include/mtr0mtr.ic +++ b/storage/innobase/include/mtr0mtr.ic @@ -113,6 +113,7 @@ mtr_release_s_latch_at_savepoint( slot->object = NULL; } +#ifdef UNIV_DEBUG /************************************************************** Checks if memo contains the given item. */ UNIV_INLINE @@ -148,6 +149,7 @@ mtr_memo_contains( return(FALSE); } +#endif /* UNIV_DEBUG */ /******************************************************************* Returns the log object of a mini-transaction buffer. */ diff --git a/storage/innobase/include/sync0rw.h b/storage/innobase/include/sync0rw.h index d8f3c400918..7c0241f2e02 100644 --- a/storage/innobase/include/sync0rw.h +++ b/storage/innobase/include/sync0rw.h @@ -358,8 +358,9 @@ rw_lock_print( Prints debug info of currently locked rw-locks. */ void -rw_lock_list_print_info(void); -/*=========================*/ +rw_lock_list_print_info( +/*====================*/ + FILE* file); /* in: file where to print */ /******************************************************************* Returns the number of currently locked rw-locks. Works only in the debug version. */ diff --git a/storage/innobase/include/sync0sync.h b/storage/innobase/include/sync0sync.h index 7d795e60efd..a1184d44257 100644 --- a/storage/innobase/include/sync0sync.h +++ b/storage/innobase/include/sync0sync.h @@ -224,12 +224,6 @@ Counts currently reserved mutexes. Works only in the debug version. */ ulint mutex_n_reserved(void); /*==================*/ -/********************************************************************** -Prints debug info of currently reserved mutexes. */ - -void -mutex_list_print_info(void); -/*========================*/ #endif /* UNIV_SYNC_DEBUG */ /********************************************************************** NOT to be used outside this module except in debugging! Gets the value diff --git a/storage/innobase/include/univ.i b/storage/innobase/include/univ.i index 63fdabbe823..f471fe136b0 100644 --- a/storage/innobase/include/univ.i +++ b/storage/innobase/include/univ.i @@ -10,18 +10,18 @@ Created 1/20/1994 Heikki Tuuri #define univ_i #if (defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)) && !defined(MYSQL_SERVER) && !defined(__WIN__) -#undef __WIN__ -#define __WIN__ +# undef __WIN__ +# define __WIN__ -#include <windows.h> +# include <windows.h> -#if !defined(WIN64) && !defined(_WIN64) -#define UNIV_CAN_USE_X86_ASSEMBLER -#endif +# if !defined(WIN64) && !defined(_WIN64) +# define UNIV_CAN_USE_X86_ASSEMBLER +# endif -#ifdef _NT_ -#define __NT__ -#endif +# ifdef _NT_ +# define __NT__ +# endif #else /* The defines used with MySQL */ @@ -30,23 +30,23 @@ Created 1/20/1994 Heikki Tuuri in compiling more Posix-compatible. These headers also define __WIN__ if we are compiling on Windows. */ -#include <my_global.h> -#include <my_pthread.h> +# include <my_global.h> +# include <my_pthread.h> /* Include <sys/stat.h> to get S_I... macros defined for os0file.c */ -#include <sys/stat.h> +# include <sys/stat.h> -#undef PACKAGE -#undef VERSION +# undef PACKAGE +# undef VERSION /* Include the header file generated by GNU autoconf */ #ifndef __WIN__ -#include "config.h" +# include "config.h" #endif -#ifdef HAVE_SCHED_H -#include <sched.h> -#endif +# ifdef HAVE_SCHED_H +# include <sched.h> +# endif /* When compiling for Itanium IA64, undefine the flag below to prevent use of the 32-bit x86 assembler in mutex operations. */ @@ -58,14 +58,14 @@ of the 32-bit x86 assembler in mutex operations. */ /* We only try to do explicit inlining of functions with gcc and Microsoft Visual C++ */ -#if !defined(__GNUC__) && !defined(__WIN__) -#undef UNIV_MUST_NOT_INLINE /* Remove compiler warning */ -#define UNIV_MUST_NOT_INLINE -#endif +# if !defined(__GNUC__) +# undef UNIV_MUST_NOT_INLINE /* Remove compiler warning */ +# define UNIV_MUST_NOT_INLINE +# endif -#ifdef HAVE_PREAD -#define HAVE_PWRITE -#endif +# ifdef HAVE_PREAD +# define HAVE_PWRITE +# endif #endif /* #if (defined(WIN32) || ... */ diff --git a/storage/innobase/include/ut0ut.h b/storage/innobase/include/ut0ut.h index 1eafa680d8d..b4e9fa91491 100644 --- a/storage/innobase/include/ut0ut.h +++ b/storage/innobase/include/ut0ut.h @@ -218,7 +218,10 @@ ut_print_filename( struct trx_struct; /************************************************************************** -Outputs a NUL-terminated string, quoted as an SQL identifier. */ +Outputs a fixed-length string, quoted as an SQL identifier. +If the string contains a slash '/', the string will be +output as two identifiers separated by a period (.), +as in SQL database_name.identifier. */ void ut_print_name( @@ -230,7 +233,10 @@ ut_print_name( const char* name); /* in: name to print */ /************************************************************************** -Outputs a fixed-length string, quoted as an SQL identifier. */ +Outputs a fixed-length string, quoted as an SQL identifier. +If the string contains a slash '/', the string will be +output as two identifiers separated by a period (.), +as in SQL database_name.identifier. */ void ut_print_namel( diff --git a/storage/innobase/mem/mem0dbg.c b/storage/innobase/mem/mem0dbg.c index 419f410cf1b..eb77dd01f6d 100644 --- a/storage/innobase/mem/mem0dbg.c +++ b/storage/innobase/mem/mem0dbg.c @@ -66,7 +66,6 @@ mem_hash_get_nth_cell(ulint i) return(&(mem_hash_table[i])); } -#endif /* UNIV_MEM_DEBUG */ /* Accessor functions for a memory field in the debug version */ @@ -106,6 +105,7 @@ mem_field_trailer_get_check(byte* field) return(mach_read_from_4(field + mem_field_header_get_len(field))); } +#endif /* UNIV_MEM_DEBUG */ /********************************************************************** Initializes the memory system. */ @@ -136,6 +136,7 @@ mem_init( mem_comm_pool = mem_pool_create(size); } +#ifdef UNIV_MEM_DEBUG /********************************************************************** Initializes an allocated memory field in the debug version. */ @@ -163,7 +164,6 @@ mem_field_init( mem_field_header_set_check(usr_buf, rnd); mem_field_trailer_set_check(usr_buf, rnd); -#ifdef UNIV_MEM_DEBUG /* Update the memory allocation information */ mutex_enter(&mem_hash_mutex); @@ -182,7 +182,6 @@ mem_field_init( combination of 0xBA and 0xBE */ mem_init_buf(usr_buf, n); -#endif /* UNIV_MEM_DEBUG */ } /********************************************************************** @@ -199,7 +198,6 @@ mem_field_erase( usr_buf = buf + MEM_FIELD_HEADER_SIZE; -#ifdef UNIV_MEM_DEBUG mutex_enter(&mem_hash_mutex); mem_current_allocated_memory -= n; mutex_exit(&mem_hash_mutex); @@ -211,10 +209,8 @@ mem_field_erase( combination of 0xDE and 0xAD */ mem_erase_buf(buf, MEM_SPACE_NEEDED(n)); -#endif /* UNIV_MEM_DEBUG */ } -#ifdef UNIV_MEM_DEBUG /******************************************************************* Initializes a buffer to a random combination of hex BA and BE. Used to initialize allocated memory. */ @@ -376,6 +372,7 @@ mem_hash_remove( } #endif /* UNIV_MEM_DEBUG */ +#if defined UNIV_MEM_DEBUG || defined UNIV_DEBUG /******************************************************************* Checks a memory heap for consistency and prints the contents if requested. Outputs the sum of sizes of buffers given to the user (only in @@ -549,10 +546,12 @@ completed: } *error = FALSE; } +#endif /* UNIV_MEM_DEBUG || UNIV_DEBUG */ +#ifdef UNIV_DEBUG /****************************************************************** Prints the contents of a memory heap. */ - +static void mem_heap_print( /*===========*/ @@ -615,6 +614,7 @@ mem_heap_validate( return(TRUE); } +#endif /* UNIV_DEBUG */ #ifdef UNIV_MEM_DEBUG /********************************************************************* diff --git a/storage/innobase/mem/mem0pool.c b/storage/innobase/mem/mem0pool.c index 6a419ff33ec..a7acd331e16 100644 --- a/storage/innobase/mem/mem0pool.c +++ b/storage/innobase/mem/mem0pool.c @@ -35,7 +35,7 @@ The main components of the memory consumption are: 8. session for each user, and 9. stack for each OS thread. -Items 1-3 are managed by an LRU algorithm. Items 5 and 6 can potentially +Items 1 and 2 are managed by an LRU algorithm. Items 5 and 6 can potentially consume very much memory. Items 7 and 8 should consume quite little memory, and the OS should take care of item 9, which too should consume little memory. @@ -54,16 +54,15 @@ common pool and the buffers in the buffer pool into a single LRU list and manage it uniformly, but this approach does not take into account the parsing and other costs unique to SQL statements. -So, let the SQL statements and the data dictionary entries form one single -LRU list, let us call it the dictionary LRU list. The locks for a transaction -can be seen as a part of the state of the transaction. Hence, they should be -stored in the common pool. We still have the problem of a very big update -transaction, for example, which will set very many x-locks on rows, and the -locks will consume a lot of memory, say, half of the buffer pool size. +The locks for a transaction can be seen as a part of the state of the +transaction. Hence, they should be stored in the common pool. We still +have the problem of a very big update transaction, for example, which +will set very many x-locks on rows, and the locks will consume a lot +of memory, say, half of the buffer pool size. Another problem is what to do if we are not able to malloc a requested -block of memory from the common pool. Then we can truncate the LRU list of -the dictionary cache. If it does not help, a system error results. +block of memory from the common pool. Then we can request memory from +the operating system. If it does not help, a system error results. Because 5 and 6 may potentially consume very much memory, we let them grow into the buffer pool. We may let the locks of a transaction take frames diff --git a/storage/innobase/mtr/mtr0mtr.c b/storage/innobase/mtr/mtr0mtr.c index 1a65da6e7f4..365fa15878a 100644 --- a/storage/innobase/mtr/mtr0mtr.c +++ b/storage/innobase/mtr/mtr0mtr.c @@ -318,6 +318,7 @@ mtr_read_dulint( return(mach_read_from_8(ptr)); } +#ifdef UNIV_DEBUG /************************************************************* Prints info of an mtr handle. */ @@ -332,3 +333,4 @@ mtr_print( (ulong) dyn_array_get_data_size(&(mtr->memo)), (ulong) dyn_array_get_data_size(&(mtr->log))); } +#endif /* UNIV_DEBUG */ diff --git a/storage/innobase/plug.in b/storage/innobase/plug.in index 028937882b2..9c21a491d9f 100644 --- a/storage/innobase/plug.in +++ b/storage/innobase/plug.in @@ -68,4 +68,5 @@ MYSQL_PLUGIN_ACTIONS(innobase, [ storage/innobase/handler/Makefile storage/innobase/usr/Makefile) ]) +MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS(innobase, [handler/ha_innodb.cc]) diff --git a/storage/innobase/row/row0purge.c b/storage/innobase/row/row0purge.c index 889a11a7a76..1fef47da13f 100644 --- a/storage/innobase/row/row0purge.c +++ b/storage/innobase/row/row0purge.c @@ -563,7 +563,7 @@ row_purge_parse_undo_rec( /* Read to the partial row the fields that occur in indexes */ - if (!cmpl_info & UPD_NODE_NO_ORD_CHANGE) { + if (!(cmpl_info & UPD_NODE_NO_ORD_CHANGE)) { ptr = trx_undo_rec_get_partial_row(ptr, clust_index, &(node->row), node->heap); } diff --git a/storage/innobase/sync/sync0rw.c b/storage/innobase/sync/sync0rw.c index 304801d0a3b..441933843d7 100644 --- a/storage/innobase/sync/sync0rw.c +++ b/storage/innobase/sync/sync0rw.c @@ -758,8 +758,9 @@ rw_lock_is_locked( Prints debug info of currently locked rw-locks. */ void -rw_lock_list_print_info(void) -/*=========================*/ +rw_lock_list_print_info( +/*====================*/ + FILE* file) /* in: file where to print */ { rw_lock_t* lock; ulint count = 0; @@ -769,7 +770,7 @@ rw_lock_list_print_info(void) fputs("-------------\n" "RW-LATCH INFO\n" - "-------------\n", stderr); + "-------------\n", file); lock = UT_LIST_GET_FIRST(rw_lock_list); @@ -783,12 +784,12 @@ rw_lock_list_print_info(void) || (rw_lock_get_reader_count(lock) != 0) || (rw_lock_get_waiters(lock) != 0)) { - fprintf(stderr, "RW-LOCK: %p ", (void*) lock); + fprintf(file, "RW-LOCK: %p ", (void*) lock); if (rw_lock_get_waiters(lock)) { - fputs(" Waiters for the lock exist\n", stderr); + fputs(" Waiters for the lock exist\n", file); } else { - putc('\n', stderr); + putc('\n', file); } info = UT_LIST_GET_FIRST(lock->debug_list); @@ -802,7 +803,7 @@ rw_lock_list_print_info(void) lock = UT_LIST_GET_NEXT(list, lock); } - fprintf(stderr, "Total number of rw-locks %ld\n", count); + fprintf(file, "Total number of rw-locks %ld\n", count); mutex_exit(&rw_lock_list_mutex); } diff --git a/storage/innobase/sync/sync0sync.c b/storage/innobase/sync/sync0sync.c index 91fd248502a..ff7056b0afe 100644 --- a/storage/innobase/sync/sync0sync.c +++ b/storage/innobase/sync/sync0sync.c @@ -628,10 +628,11 @@ mutex_own( /********************************************************************** Prints debug info of currently reserved mutexes. */ - +static void -mutex_list_print_info(void) -/*=======================*/ +mutex_list_print_info( +/*==================*/ + FILE* file) /* in: file where to print */ { mutex_t* mutex; const char* file_name; @@ -641,7 +642,7 @@ mutex_list_print_info(void) fputs("----------\n" "MUTEX INFO\n" - "----------\n", stderr); + "----------\n", file); mutex_enter(&mutex_list_mutex); @@ -653,7 +654,7 @@ mutex_list_print_info(void) if (mutex_get_lock_word(mutex) != 0) { mutex_get_debug_info(mutex, &file_name, &line, &thread_id); - fprintf(stderr, + fprintf(file, "Locked mutex: addr %p thread %ld" " file %s line %ld\n", (void*) mutex, os_thread_pf(thread_id), @@ -663,7 +664,7 @@ mutex_list_print_info(void) mutex = UT_LIST_GET_NEXT(list, mutex); } - fprintf(stderr, "Total number of mutexes %ld\n", count); + fprintf(file, "Total number of mutexes %ld\n", count); mutex_exit(&mutex_list_mutex); } @@ -1343,7 +1344,7 @@ sync_print_wait_info( FILE* file) /* in: file where to print */ { #ifdef UNIV_SYNC_DEBUG - fprintf(stderr, "Mutex exits %lu, rws exits %lu, rwx exits %lu\n", + fprintf(file, "Mutex exits %lu, rws exits %lu, rwx exits %lu\n", mutex_exit_count, rw_s_exit_count, rw_x_exit_count); #endif @@ -1369,9 +1370,9 @@ sync_print( FILE* file) /* in: file where to print */ { #ifdef UNIV_SYNC_DEBUG - mutex_list_print_info(); + mutex_list_print_info(file); - rw_lock_list_print_info(); + rw_lock_list_print_info(file); #endif /* UNIV_SYNC_DEBUG */ sync_array_print_info(file, sync_primary_wait_array); diff --git a/storage/innobase/ut/ut0ut.c b/storage/innobase/ut/ut0ut.c index 10641b88a17..d805cc3b4b2 100644 --- a/storage/innobase/ut/ut0ut.c +++ b/storage/innobase/ut/ut0ut.c @@ -394,7 +394,10 @@ done: } /************************************************************************** -Outputs a NUL-terminated string, quoted as an SQL identifier. */ +Outputs a fixed-length string, quoted as an SQL identifier. +If the string contains a slash '/', the string will be +output as two identifiers separated by a period (.), +as in SQL database_name.identifier. */ void ut_print_name( @@ -409,7 +412,10 @@ ut_print_name( } /************************************************************************** -Outputs a fixed-length string, quoted as an SQL identifier. */ +Outputs a fixed-length string, quoted as an SQL identifier. +If the string contains a slash '/', the string will be +output as two identifiers separated by a period (.), +as in SQL database_name.identifier. */ void ut_print_namel( @@ -424,7 +430,7 @@ ut_print_namel( #ifdef UNIV_HOTBACKUP fwrite(name, 1, namelen, f); #else - char* slash = strchr(name, '/'); + char* slash = memchr(name, '/', namelen); if (UNIV_LIKELY_NULL(slash)) { /* Print the database name and table name separately. */ diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 03065b43dd5..85968110a77 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -265,7 +265,7 @@ err: bool ha_myisam::check_if_locking_is_allowed(uint sql_command, ulong type, TABLE *table, uint count, - bool called_by_logger_thread) + bool called_by_privileged_thread) { /* To be able to open and lock for reading system tables like 'mysql.proc', @@ -283,10 +283,10 @@ bool ha_myisam::check_if_locking_is_allowed(uint sql_command, /* Deny locking of the log tables, which is incompatible with - concurrent insert. Unless called from a logger THD: - general_log_thd or slow_log_thd. + concurrent insert. Unless called from a logger THD (general_log_thd + or slow_log_thd) or by a privileged thread. */ - if (!called_by_logger_thread) + if (!called_by_privileged_thread) return check_if_log_table_locking_is_allowed(sql_command, type, table); return TRUE; @@ -1325,7 +1325,7 @@ void ha_myisam::position(const byte* record) my_store_ptr(ref, ref_length, position); } -void ha_myisam::info(uint flag) +int ha_myisam::info(uint flag) { MI_ISAMINFO info; char name_buff[FN_REFLEN]; @@ -1386,6 +1386,8 @@ void ha_myisam::info(uint flag) stats.update_time = info.update_time; if (flag & HA_STATUS_AUTO) stats.auto_increment_value= info.auto_increment; + + return 0; } diff --git a/storage/myisam/ha_myisam.h b/storage/myisam/ha_myisam.h index 85abcdca8b2..7ad938c06a7 100644 --- a/storage/myisam/ha_myisam.h +++ b/storage/myisam/ha_myisam.h @@ -99,7 +99,7 @@ class ha_myisam: public handler int rnd_pos(byte * buf, byte *pos); int restart_rnd_next(byte *buf, byte *pos); void position(const byte *record); - void info(uint); + int info(uint); int extra(enum ha_extra_function operation); int extra_opt(enum ha_extra_function operation, ulong cache_size); int reset(void); diff --git a/storage/myisam/plug.in b/storage/myisam/plug.in index 3160752182d..051ec2d54aa 100644 --- a/storage/myisam/plug.in +++ b/storage/myisam/plug.in @@ -3,4 +3,5 @@ MYSQL_STORAGE_ENGINE(myisam,no, [MyISAM Storage Engine], MYSQL_PLUGIN_DIRECTORY(myisam, [storage/myisam]) MYSQL_PLUGIN_STATIC(myisam, [libmyisam.a]) MYSQL_PLUGIN_MANDATORY(myisam) dnl Default +MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS(myisam, [ha_myisam.cc]) diff --git a/storage/myisam/sort.c b/storage/myisam/sort.c index bdbfa91ced4..a6bf3934959 100644 --- a/storage/myisam/sort.c +++ b/storage/myisam/sort.c @@ -322,160 +322,164 @@ pthread_handler_t thr_find_all_keys(void *arg) if (my_thread_init()) goto err; - DBUG_ENTER("thr_find_all_keys"); - DBUG_PRINT("enter", ("master: %d", sort_param->master)); - if (sort_param->sort_info->got_error) - goto err; - if (sort_param->keyinfo->flag && HA_VAR_LENGTH_KEY) - { - sort_param->write_keys= write_keys_varlen; - sort_param->read_to_buffer= read_to_buffer_varlen; - sort_param->write_key= write_merge_key_varlen; - } - else - { - sort_param->write_keys= write_keys; - sort_param->read_to_buffer= read_to_buffer; - sort_param->write_key= write_merge_key; - } + { /* Add extra block since DBUG_ENTER declare variables */ + DBUG_ENTER("thr_find_all_keys"); + DBUG_PRINT("enter", ("master: %d", sort_param->master)); + if (sort_param->sort_info->got_error) + goto err; - my_b_clear(&sort_param->tempfile); - my_b_clear(&sort_param->tempfile_for_exceptions); - bzero((char*) &sort_param->buffpek, sizeof(sort_param->buffpek)); - bzero((char*) &sort_param->unique, sizeof(sort_param->unique)); - sort_keys= (uchar **) NULL; + if (sort_param->keyinfo->flag & HA_VAR_LENGTH_KEY) + { + sort_param->write_keys= write_keys_varlen; + sort_param->read_to_buffer= read_to_buffer_varlen; + sort_param->write_key= write_merge_key_varlen; + } + else + { + sort_param->write_keys= write_keys; + sort_param->read_to_buffer= read_to_buffer; + sort_param->write_key= write_merge_key; + } - memavl= max(sort_param->sortbuff_size, MIN_SORT_MEMORY); - idx= sort_param->sort_info->max_records; - sort_length= sort_param->key_length; - maxbuffer= 1; + my_b_clear(&sort_param->tempfile); + my_b_clear(&sort_param->tempfile_for_exceptions); + bzero((char*) &sort_param->buffpek, sizeof(sort_param->buffpek)); + bzero((char*) &sort_param->unique, sizeof(sort_param->unique)); + sort_keys= (uchar **) NULL; - while (memavl >= MIN_SORT_MEMORY) - { - if ((my_off_t) (idx+1)*(sort_length+sizeof(char*)) <= - (my_off_t) memavl) - keys= idx+1; - else + memavl= max(sort_param->sortbuff_size, MIN_SORT_MEMORY); + idx= sort_param->sort_info->max_records; + sort_length= sort_param->key_length; + maxbuffer= 1; + + while (memavl >= MIN_SORT_MEMORY) { - uint skr; - do + if ((my_off_t) (idx+1)*(sort_length+sizeof(char*)) <= + (my_off_t) memavl) + keys= idx+1; + else { - skr=maxbuffer; - if (memavl < sizeof(BUFFPEK)*maxbuffer || - (keys=(memavl-sizeof(BUFFPEK)*maxbuffer)/ - (sort_length+sizeof(char*))) <= 1 || - keys < (uint) maxbuffer) + uint skr; + do { - mi_check_print_error(sort_param->sort_info->param, - "sort_buffer_size is to small"); - goto err; + skr= maxbuffer; + if (memavl < sizeof(BUFFPEK)*maxbuffer || + (keys=(memavl-sizeof(BUFFPEK)*maxbuffer)/ + (sort_length+sizeof(char*))) <= 1 || + keys < (uint) maxbuffer) + { + mi_check_print_error(sort_param->sort_info->param, + "sort_buffer_size is to small"); + goto err; + } } + while ((maxbuffer= (int) (idx/(keys-1)+1)) != skr); } - while ((maxbuffer= (int) (idx/(keys-1)+1)) != skr); - } - if ((sort_keys= (uchar**) - my_malloc(keys*(sort_length+sizeof(char*))+ - ((sort_param->keyinfo->flag & HA_FULLTEXT) ? - HA_FT_MAXBYTELEN : 0), MYF(0)))) - { - if (my_init_dynamic_array(&sort_param->buffpek, sizeof(BUFFPEK), - maxbuffer, maxbuffer/2)) + if ((sort_keys= (uchar**) + my_malloc(keys*(sort_length+sizeof(char*))+ + ((sort_param->keyinfo->flag & HA_FULLTEXT) ? + HA_FT_MAXBYTELEN : 0), MYF(0)))) { - my_free((gptr) sort_keys,MYF(0)); - sort_keys= (uchar **) NULL; /* for err: label */ + if (my_init_dynamic_array(&sort_param->buffpek, sizeof(BUFFPEK), + maxbuffer, maxbuffer/2)) + { + my_free((gptr) sort_keys,MYF(0)); + sort_keys= (uchar **) NULL; /* for err: label */ + } + else + break; } - else - break; + old_memavl= memavl; + if ((memavl= memavl/4*3) < MIN_SORT_MEMORY && + old_memavl > MIN_SORT_MEMORY) + memavl= MIN_SORT_MEMORY; + } + if (memavl < MIN_SORT_MEMORY) + { + mi_check_print_error(sort_param->sort_info->param, + "Sort buffer too small"); + goto err; /* purecov: tested */ } - old_memavl=memavl; - if ((memavl=memavl/4*3) < MIN_SORT_MEMORY && old_memavl > MIN_SORT_MEMORY) - memavl=MIN_SORT_MEMORY; - } - if (memavl < MIN_SORT_MEMORY) - { - mi_check_print_error(sort_param->sort_info->param, "Sort buffer too small"); - goto err; /* purecov: tested */ - } - if (sort_param->sort_info->param->testflag & T_VERBOSE) - printf("Key %d - Allocating buffer for %d keys\n", - sort_param->key + 1, keys); - sort_param->sort_keys= sort_keys; + if (sort_param->sort_info->param->testflag & T_VERBOSE) + printf("Key %d - Allocating buffer for %d keys\n", + sort_param->key + 1, keys); + sort_param->sort_keys= sort_keys; - idx=error=0; - sort_keys[0]=(uchar*) (sort_keys+keys); + idx= error= 0; + sort_keys[0]= (uchar*) (sort_keys+keys); - DBUG_PRINT("info", ("reading keys")); - while (!(error= sort_param->sort_info->got_error) && - !(error= (*sort_param->key_read)(sort_param, sort_keys[idx]))) - { - if (sort_param->real_key_length > sort_param->key_length) + DBUG_PRINT("info", ("reading keys")); + while (!(error= sort_param->sort_info->got_error) && + !(error= (*sort_param->key_read)(sort_param, sort_keys[idx]))) { - if (write_key(sort_param, sort_keys[idx], - &sort_param->tempfile_for_exceptions)) - goto err; - continue; - } + if (sort_param->real_key_length > sort_param->key_length) + { + if (write_key(sort_param, sort_keys[idx], + &sort_param->tempfile_for_exceptions)) + goto err; + continue; + } - if (++idx == keys) + if (++idx == keys) + { + if (sort_param->write_keys(sort_param, sort_keys, idx - 1, + (BUFFPEK*) alloc_dynamic(&sort_param->buffpek), + &sort_param->tempfile)) + goto err; + sort_keys[0]= (uchar*) (sort_keys+keys); + memcpy(sort_keys[0], sort_keys[idx - 1], (size_t) sort_param->key_length); + idx= 1; + } + sort_keys[idx]= sort_keys[idx - 1] + sort_param->key_length; + } + if (error > 0) + goto err; + if (sort_param->buffpek.elements) { - if (sort_param->write_keys(sort_param, sort_keys, idx - 1, + if (sort_param->write_keys(sort_param, sort_keys, idx, (BUFFPEK*) alloc_dynamic(&sort_param->buffpek), &sort_param->tempfile)) goto err; - sort_keys[0]=(uchar*) (sort_keys+keys); - memcpy(sort_keys[0], sort_keys[idx - 1], (size_t) sort_param->key_length); - idx=1; + sort_param->keys= (sort_param->buffpek.elements - 1) * (keys - 1) + idx; } - sort_keys[idx]= sort_keys[idx - 1] + sort_param->key_length; - } - if (error > 0) - goto err; - if (sort_param->buffpek.elements) - { - if (sort_param->write_keys(sort_param, sort_keys, idx, - (BUFFPEK*) alloc_dynamic(&sort_param->buffpek), - &sort_param->tempfile)) - goto err; - sort_param->keys= (sort_param->buffpek.elements - 1) * (keys - 1) + idx; - } - else - sort_param->keys= idx; + else + sort_param->keys= idx; - sort_param->sort_keys_length= keys; - goto ok; + sort_param->sort_keys_length= keys; + goto ok; err: - DBUG_PRINT("error", ("got some error")); - sort_param->sort_info->got_error= 1; /* no need to protect with a mutex */ - if (sort_keys) - my_free((gptr) sort_keys,MYF(0)); - sort_param->sort_keys= 0; - delete_dynamic(& sort_param->buffpek); - close_cached_file(&sort_param->tempfile); - close_cached_file(&sort_param->tempfile_for_exceptions); + DBUG_PRINT("error", ("got some error")); + sort_param->sort_info->got_error= 1; /* no need to protect with a mutex */ + if (sort_keys) + my_free((gptr) sort_keys,MYF(0)); + sort_param->sort_keys= 0; + delete_dynamic(& sort_param->buffpek); + close_cached_file(&sort_param->tempfile); + close_cached_file(&sort_param->tempfile_for_exceptions); ok: - free_root(&sort_param->wordroot, MYF(0)); - /* - Detach from the share if the writer is involved. Avoid others to - be blocked. This includes a flush of the write buffer. This will - also indicate EOF to the readers. - */ - if (sort_param->sort_info->info->rec_cache.share) - remove_io_thread(&sort_param->sort_info->info->rec_cache); - - /* Readers detach from the share if any. Avoid others to be blocked. */ - if (sort_param->read_cache.share) - remove_io_thread(&sort_param->read_cache); - - pthread_mutex_lock(&sort_param->sort_info->mutex); - if (!--sort_param->sort_info->threads_running) - pthread_cond_signal(&sort_param->sort_info->cond); - pthread_mutex_unlock(&sort_param->sort_info->mutex); - - DBUG_PRINT("exit", ("======== ending thread ========")); + free_root(&sort_param->wordroot, MYF(0)); + /* + Detach from the share if the writer is involved. Avoid others to + be blocked. This includes a flush of the write buffer. This will + also indicate EOF to the readers. + */ + if (sort_param->sort_info->info->rec_cache.share) + remove_io_thread(&sort_param->sort_info->info->rec_cache); + + /* Readers detach from the share if any. Avoid others to be blocked. */ + if (sort_param->read_cache.share) + remove_io_thread(&sort_param->read_cache); + + pthread_mutex_lock(&sort_param->sort_info->mutex); + if (!--sort_param->sort_info->threads_running) + pthread_cond_signal(&sort_param->sort_info->cond); + pthread_mutex_unlock(&sort_param->sort_info->mutex); + DBUG_PRINT("exit", ("======== ending thread ========")); + } my_thread_end(); return NULL; } @@ -543,7 +547,7 @@ int thr_write_keys(MI_SORT_PARAM *sort_param) { if (got_error) continue; - if (sinfo->keyinfo->flag && HA_VAR_LENGTH_KEY) + if (sinfo->keyinfo->flag & HA_VAR_LENGTH_KEY) { sinfo->write_keys=write_keys_varlen; sinfo->read_to_buffer=read_to_buffer_varlen; diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 5c8a05f0dde..57ef1dad6f7 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -262,7 +262,7 @@ ha_rows ha_myisammrg::records_in_range(uint inx, key_range *min_key, } -void ha_myisammrg::info(uint flag) +int ha_myisammrg::info(uint flag) { MYMERGE_INFO info; (void) myrg_status(file,&info,flag); @@ -329,6 +329,7 @@ void ha_myisammrg::info(uint flag) min(file->keys, table->s->key_parts)); } } + return 0; } diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index faa3ae73c59..ae3cb0aea42 100644 --- a/storage/myisammrg/ha_myisammrg.h +++ b/storage/myisammrg/ha_myisammrg.h @@ -72,7 +72,7 @@ class ha_myisammrg: public handler int rnd_pos(byte * buf, byte *pos); void position(const byte *record); ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); - void info(uint); + int info(uint); int reset(void); int extra(enum ha_extra_function operation); int extra_opt(enum ha_extra_function operation, ulong cache_size); diff --git a/storage/myisammrg/plug.in b/storage/myisammrg/plug.in index b4b2af8d984..1f94e07d881 100644 --- a/storage/myisammrg/plug.in +++ b/storage/myisammrg/plug.in @@ -3,3 +3,4 @@ MYSQL_STORAGE_ENGINE(myisammrg,no,[MyISAM MERGE Engine], MYSQL_PLUGIN_DIRECTORY(myisammrg,[storage/myisammrg]) MYSQL_PLUGIN_STATIC(myisammrg, [libmyisammrg.a]) MYSQL_PLUGIN_MANDATORY(myisammrg) +MYSQL_PLUGIN_DEPENDS_ON_MYSQL_INTERNALS(myisammrg, [ha_myisammrg.cc]) diff --git a/storage/ndb/include/kernel/ndb_limits.h b/storage/ndb/include/kernel/ndb_limits.h index 5985fbe5d9b..b6a55cc8331 100644 --- a/storage/ndb/include/kernel/ndb_limits.h +++ b/storage/ndb/include/kernel/ndb_limits.h @@ -66,7 +66,8 @@ #define MAX_FRAGMENT_DATA_BYTES (4+(2 * 8 * MAX_REPLICAS * MAX_NDB_NODES)) #define MAX_NDB_PARTITIONS 1024 #define MAX_RANGE_DATA (131072+MAX_NDB_PARTITIONS) //0.5 MByte of list data -#define MAX_WORDS_META_FILE 16382 + +#define MAX_WORDS_META_FILE 24576 #define MIN_ATTRBUF ((MAX_ATTRIBUTES_IN_TABLE/24) + 1) /* diff --git a/storage/ndb/include/mgmapi/ndbd_exit_codes.h b/storage/ndb/include/mgmapi/ndbd_exit_codes.h index 1b662c9d270..6f0e8fec0af 100644 --- a/storage/ndb/include/mgmapi/ndbd_exit_codes.h +++ b/storage/ndb/include/mgmapi/ndbd_exit_codes.h @@ -146,6 +146,8 @@ typedef ndbd_exit_classification_enum ndbd_exit_classification; #define NDBD_EXIT_AFS_NO_SUCH_FILE 2815 #define NDBD_EXIT_AFS_READ_UNDERFLOW 2816 +#define NDBD_EXIT_INVALID_LCP_FILE 2352 + const char * ndbd_exit_message(int faultId, ndbd_exit_classification *cl); const char * diff --git a/storage/ndb/include/ndb_types.h.in b/storage/ndb/include/ndb_types.h.in index c657ce4f075..2a5d576ffea 100644 --- a/storage/ndb/include/ndb_types.h.in +++ b/storage/ndb/include/ndb_types.h.in @@ -21,8 +21,6 @@ #ifndef NDB_TYPES_H #define NDB_TYPES_H -#include <my_config.h> - #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(_WIN64) #define NDB_SIZEOF_CHARP SIZEOF_CHARP #define NDB_SIZEOF_CHAR SIZEOF_CHAR @@ -33,12 +31,12 @@ typedef unsigned __int64 Uint64; typedef signed __int64 Int64; #else -#define NDB_SIZEOF_CHARP SIZEOF_CHARP -#define NDB_SIZEOF_CHAR SIZEOF_CHAR -#define NDB_SIZEOF_INT SIZEOF_INT -#define NDB_SIZEOF_SHORT SIZEOF_SHORT -#define NDB_SIZEOF_LONG SIZEOF_LONG -#define NDB_SIZEOF_LONG_LONG SIZEOF_LONG_LONG +#define NDB_SIZEOF_CHARP @NDB_SIZEOF_CHARP@ +#define NDB_SIZEOF_CHAR @NDB_SIZEOF_CHAR@ +#define NDB_SIZEOF_INT @NDB_SIZEOF_INT@ +#define NDB_SIZEOF_SHORT @NDB_SIZEOF_SHORT@ +#define NDB_SIZEOF_LONG @NDB_SIZEOF_LONG@ +#define NDB_SIZEOF_LONG_LONG @NDB_SIZEOF_LONG_LONG@ typedef unsigned long long Uint64; typedef signed long long Int64; #endif diff --git a/storage/ndb/include/ndb_version.h.in b/storage/ndb/include/ndb_version.h.in index 6a1b1f5292c..9eb609e3830 100644 --- a/storage/ndb/include/ndb_version.h.in +++ b/storage/ndb/include/ndb_version.h.in @@ -71,5 +71,6 @@ char ndb_version_string_buf[NDB_VERSION_STRING_BUF_SZ]; #define NDBD_UPDATE_FRAG_DIST_KEY_51 MAKE_VERSION(5,1,12) #define NDBD_QMGR_SINGLEUSER_VERSION_5 MAKE_VERSION(5,0,25) + #endif diff --git a/storage/ndb/include/util/UtilBuffer.hpp b/storage/ndb/include/util/UtilBuffer.hpp index f97f5175dce..d71674d91ff 100644 --- a/storage/ndb/include/util/UtilBuffer.hpp +++ b/storage/ndb/include/util/UtilBuffer.hpp @@ -73,11 +73,15 @@ public: } int assign(const void * d, size_t l) { - if (data) free(data); + /* Free the old data only after copying, in case d==data. */ + void *old_data= data; data = NULL; len = 0; alloc_size = 0; - return append(d, l); + int ret= append(d, l); + if (old_data) + free(old_data); + return ret; } void clear() { diff --git a/storage/ndb/src/common/debugger/EventLogger.cpp b/storage/ndb/src/common/debugger/EventLogger.cpp index db9b8417c0d..f1c6084754f 100644 --- a/storage/ndb/src/common/debugger/EventLogger.cpp +++ b/storage/ndb/src/common/debugger/EventLogger.cpp @@ -683,8 +683,8 @@ void getTextMemoryUsage(QQQQ) { const int used = theData[3]; const int total = theData[4]; const int block = theData[5]; - const int percent = (used*100)/total; - + const int percent = total ? (used*100)/total : 0; + BaseString::snprintf(m_text, m_text_len, "%s usage %s %d%s(%d %dK pages of total %d)", (block==DBACC ? "Index" : (block == DBTUP ?"Data":"<unknown>")), diff --git a/storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp b/storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp index 62f372025ff..cb6cf71d216 100644 --- a/storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp +++ b/storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp @@ -263,7 +263,7 @@ DictFilegroupInfo::Filegroup::init(){ void DictFilegroupInfo::File::init(){ - memset(FileName, sizeof(FileName), 0); + memset(FileName, 0, sizeof(FileName)); FileType = ~0; FileId = ~0; FileVersion = ~0; diff --git a/storage/ndb/src/common/util/SimpleProperties.cpp b/storage/ndb/src/common/util/SimpleProperties.cpp index c9251c6a854..a32762caad7 100644 --- a/storage/ndb/src/common/util/SimpleProperties.cpp +++ b/storage/ndb/src/common/util/SimpleProperties.cpp @@ -267,7 +267,7 @@ SimpleProperties::pack(Writer & it, const void * __src, const char * src_len = _src + _map[i].Length_Offset; Uint32 len = *((Uint32*)src_len); if(!ignoreMinMax){ - if(len == _map[i].maxValue) + if(len > _map[i].maxValue) return ValueTooHigh; } ok = it.add(_map[i].Key, src, len); @@ -276,7 +276,7 @@ SimpleProperties::pack(Writer & it, const void * __src, case SimpleProperties::StringValue: if(!ignoreMinMax){ size_t len = strlen(src); - if(len == _map[i].maxValue) + if(len > _map[i].maxValue) return ValueTooHigh; } ok = it.add(_map[i].Key, src); diff --git a/storage/ndb/src/kernel/blocks/ERROR_codes.txt b/storage/ndb/src/kernel/blocks/ERROR_codes.txt index 5b83ecffc6c..119f77fd0e2 100644 --- a/storage/ndb/src/kernel/blocks/ERROR_codes.txt +++ b/storage/ndb/src/kernel/blocks/ERROR_codes.txt @@ -5,10 +5,10 @@ Next DBACC 3002 Next DBTUP 4024 Next DBLQH 5045 Next DBDICT 6007 -Next DBDIH 7177 +Next DBDIH 7178 Next DBTC 8038 Next CMVMI 9000 -Next BACKUP 10022 +Next BACKUP 10036 Next DBUTIL 11002 Next DBTUX 12008 Next SUMA 13001 @@ -66,6 +66,8 @@ Delay GCP_SAVEREQ by 10 secs 7030: Delay in GCP_PREPARE until node has completed a node failure 7031: Delay in GCP_PREPARE and die 3s later +7177: Delay copying of sysfileData in execCOPY_GCIREQ + ERROR CODES FOR TESTING NODE FAILURE, LOCAL CHECKPOINT HANDLING: ----------------------------------------------------------------- @@ -409,6 +411,11 @@ Backup Stuff: 10028: Abort backup by error at reception of BACKUP_FRAGMENT_CONF at master (code 305) 10029: Abort backup by error at reception of FSAPPENDCONF in slave (FileOrScanError = 5) 10030: Simulate buffer full from trigger execution => abort backup +10031: Error 331 for dictCommitTableMutex_locked +10032: backup checkscan +10033: backup checkscan +10034: define backup reply error +10035: Fail to allocate buffers 11001: Send UTIL_SEQUENCE_REF (in master) diff --git a/storage/ndb/src/kernel/blocks/backup/Backup.cpp b/storage/ndb/src/kernel/blocks/backup/Backup.cpp index 23a2f908c20..d6b557424e7 100644 --- a/storage/ndb/src/kernel/blocks/backup/Backup.cpp +++ b/storage/ndb/src/kernel/blocks/backup/Backup.cpp @@ -2004,7 +2004,15 @@ Backup::sendDropTrig(Signal* signal, BackupRecordPtr ptr) if (ptr.p->slaveData.dropTrig.tableId == RNIL) { jam(); - ptr.p->tables.first(tabPtr); + if(ptr.p->tables.count()) + ptr.p->tables.first(tabPtr); + else + { + // Early abort, go to close files + jam(); + closeFiles(signal, ptr); + return; + } } else { jam(); ndbrequire(findTable(ptr, tabPtr, ptr.p->slaveData.dropTrig.tableId)); @@ -2105,8 +2113,11 @@ Backup::execDROP_TRIG_REF(Signal* signal) BackupRecordPtr ptr; c_backupPool.getPtr(ptr, ptrI); - ndbout << "ERROR DROPPING TRIGGER: " << ref->getConf()->getTriggerId(); - ndbout << " Err: " << (Uint32)ref->getErrorCode() << endl << endl; + if(ref->getConf()->getTriggerId() != -1) + { + ndbout << "ERROR DROPPING TRIGGER: " << ref->getConf()->getTriggerId(); + ndbout << " Err: " << (Uint32)ref->getErrorCode() << endl << endl; + } dropTrigReply(signal, ptr); } @@ -2487,8 +2498,8 @@ Backup::execDEFINE_BACKUP_REQ(Signal* signal) 0 // 3M }; const Uint32 maxInsert[] = { - 2048, // Temporarily to solve TR515 - 4096, // 4k + MAX_WORDS_META_FILE, + 4096, // 16k 16*3000, // Max 16 tuples }; Uint32 minWrite[] = { @@ -2538,8 +2549,9 @@ Backup::execDEFINE_BACKUP_REQ(Signal* signal) files[i].p->filePointer = RNIL; files[i].p->m_flags = 0; files[i].p->errorCode = 0; - - if(files[i].p->pages.seize(noOfPages[i]) == false) { + + if(ERROR_INSERTED(10035) || files[i].p->pages.seize(noOfPages[i]) == false) + { jam(); DEBUG_OUT("Failed to seize " << noOfPages[i] << " pages"); defineBackupRef(signal, ptr, DefineBackupRef::FailedToAllocateBuffers); @@ -4451,14 +4463,24 @@ Backup::closeFilesDone(Signal* signal, BackupRecordPtr ptr) } jam(); - BackupFilePtr filePtr; - ptr.p->files.getPtr(filePtr, ptr.p->logFilePtr); - + StopBackupConf* conf = (StopBackupConf*)signal->getDataPtrSend(); conf->backupId = ptr.p->backupId; conf->backupPtr = ptr.i; - conf->noOfLogBytes = filePtr.p->operation.noOfBytes; - conf->noOfLogRecords = filePtr.p->operation.noOfRecords; + + BackupFilePtr filePtr; + if(ptr.p->logFilePtr != RNIL) + { + ptr.p->files.getPtr(filePtr, ptr.p->logFilePtr); + conf->noOfLogBytes= filePtr.p->operation.noOfBytes; + conf->noOfLogRecords= filePtr.p->operation.noOfRecords; + } + else + { + conf->noOfLogBytes= 0; + conf->noOfLogRecords= 0; + } + sendSignal(ptr.p->masterRef, GSN_STOP_BACKUP_CONF, signal, StopBackupConf::SignalLength, JBB); diff --git a/storage/ndb/src/kernel/blocks/backup/Backup.hpp b/storage/ndb/src/kernel/blocks/backup/Backup.hpp index a5929efa5c8..509a9b4b9c1 100644 --- a/storage/ndb/src/kernel/blocks/backup/Backup.hpp +++ b/storage/ndb/src/kernel/blocks/backup/Backup.hpp @@ -427,6 +427,7 @@ public: : slaveState(b, validSlaveTransitions, validSlaveTransitionsCount,1) , tables(tp), triggers(trp), files(bp) , masterData(b), backup(b) + , ctlFilePtr(RNIL), logFilePtr(RNIL), dataFilePtr(RNIL) { } @@ -556,7 +557,9 @@ public: NDB_TICKS m_reset_disk_speed_time; static const int DISK_SPEED_CHECK_DELAY = 100; - STATIC_CONST(NO_OF_PAGES_META_FILE = MAX_WORDS_META_FILE/BACKUP_WORDS_PER_PAGE); + STATIC_CONST(NO_OF_PAGES_META_FILE = + (MAX_WORDS_META_FILE + BACKUP_WORDS_PER_PAGE - 1) / + BACKUP_WORDS_PER_PAGE); /** * Pools diff --git a/storage/ndb/src/kernel/blocks/dbacc/DbaccInit.cpp b/storage/ndb/src/kernel/blocks/dbacc/DbaccInit.cpp index 27355299a9c..cc8d0f38c4f 100644 --- a/storage/ndb/src/kernel/blocks/dbacc/DbaccInit.cpp +++ b/storage/ndb/src/kernel/blocks/dbacc/DbaccInit.cpp @@ -42,6 +42,7 @@ void Dbacc::initData() scanRec = 0; tabrec = 0; + cnoOfAllocatedPages = cpagesize = 0; // Records with constant sizes }//Dbacc::initData() diff --git a/storage/ndb/src/kernel/blocks/dbacc/DbaccMain.cpp b/storage/ndb/src/kernel/blocks/dbacc/DbaccMain.cpp index 30a36495579..d5578a5c0c0 100644 --- a/storage/ndb/src/kernel/blocks/dbacc/DbaccMain.cpp +++ b/storage/ndb/src/kernel/blocks/dbacc/DbaccMain.cpp @@ -113,7 +113,7 @@ void Dbacc::execCONTINUEB(Signal* signal) case ZREPORT_MEMORY_USAGE:{ jam(); static int c_currentMemUsed = 0; - int now = (cnoOfAllocatedPages * 100)/cpagesize; + int now = cpagesize ? (cnoOfAllocatedPages * 100)/cpagesize : 0; const int thresholds[] = { 99, 90, 80, 0}; Uint32 i = 0; diff --git a/storage/ndb/src/kernel/blocks/dbdih/Dbdih.hpp b/storage/ndb/src/kernel/blocks/dbdih/Dbdih.hpp index d0b97c0eb81..3edaf146cd4 100644 --- a/storage/ndb/src/kernel/blocks/dbdih/Dbdih.hpp +++ b/storage/ndb/src/kernel/blocks/dbdih/Dbdih.hpp @@ -1056,6 +1056,8 @@ private: void removeStoredReplica(FragmentstorePtr regFragptr, ReplicaRecordPtr replicaPtr); void searchStoredReplicas(FragmentstorePtr regFragptr); + bool setup_create_replica(FragmentstorePtr, CreateReplicaRecord*, + ConstPtr<ReplicaRecord>); void updateNodeInfo(FragmentstorePtr regFragptr); //------------------------------------ diff --git a/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp b/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp index 802230b8e02..0e9157c38aa 100644 --- a/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp +++ b/storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp @@ -636,23 +636,49 @@ void Dbdih::execCOPY_GCIREQ(Signal* signal) ndbrequire(c_copyGCISlave.m_copyReason == CopyGCIReq::IDLE); ndbrequire(c_copyGCISlave.m_expectedNextWord == tstart); ndbrequire(reason != CopyGCIReq::IDLE); - + bool isdone = (tstart + CopyGCIReq::DATA_SIZE) >= Sysfile::SYSFILE_SIZE32; + + if (ERROR_INSERTED(7177)) + { + jam(); + + if (signal->getLength() == 3) + { + jam(); + goto done; + } + } + arrGuard(tstart + CopyGCIReq::DATA_SIZE, sizeof(sysfileData)/4); for(Uint32 i = 0; i<CopyGCIReq::DATA_SIZE; i++) cdata[tstart+i] = copyGCI->data[i]; - if ((tstart + CopyGCIReq::DATA_SIZE) >= Sysfile::SYSFILE_SIZE32) { + if (ERROR_INSERTED(7177) && isMaster() && isdone) + { + sendSignalWithDelay(reference(), GSN_COPY_GCIREQ, signal, 1000, 3); + return; + } + +done: + if (isdone) + { jam(); c_copyGCISlave.m_expectedNextWord = 0; - } else { + } + else + { jam(); c_copyGCISlave.m_expectedNextWord += CopyGCIReq::DATA_SIZE; return; - }//if - - Uint32 tmp= SYSFILE->m_restart_seq; - memcpy(sysfileData, cdata, sizeof(sysfileData)); - SYSFILE->m_restart_seq = tmp; + } + + if (cmasterdihref != reference()) + { + jam(); + Uint32 tmp= SYSFILE->m_restart_seq; + memcpy(sysfileData, cdata, sizeof(sysfileData)); + SYSFILE->m_restart_seq = tmp; + } c_copyGCISlave.m_copyReason = reason; c_copyGCISlave.m_senderRef = signal->senderBlockRef(); @@ -8735,14 +8761,33 @@ Dbdih::resetReplicaSr(TabRecordPtr tabPtr){ resetReplicaLcp(replicaPtr.p, newestRestorableGCI); - /* ----------------------------------------------------------------- - * LINK THE REPLICA INTO THE STORED REPLICA LIST. WE WILL USE THIS - * NODE AS A STORED REPLICA. - * WE MUST FIRST LINK IT OUT OF THE LIST OF OLD STORED REPLICAS. - * --------------------------------------------------------------- */ - removeOldStoredReplica(fragPtr, replicaPtr); - linkStoredReplica(fragPtr, replicaPtr); - + /** + * Make sure we can also find REDO for restoring replica... + */ + { + CreateReplicaRecord createReplica; + ConstPtr<ReplicaRecord> constReplicaPtr; + constReplicaPtr.i = replicaPtr.i; + constReplicaPtr.p = replicaPtr.p; + if (tabPtr.p->tabStorage != TabRecord::ST_NORMAL || + setup_create_replica(fragPtr, + &createReplica, constReplicaPtr)) + { + jam(); + removeOldStoredReplica(fragPtr, replicaPtr); + linkStoredReplica(fragPtr, replicaPtr); + } + else + { + jam(); + infoEvent("Forcing take-over of node %d due to unsufficient REDO" + " for table %d fragment: %d", + nodePtr.i, tabPtr.i, i); + + setNodeActiveStatus(nodePtr.i, + Sysfile::NS_NotActive_NotTakenOver); + } + } } default: jam(); @@ -9864,6 +9909,7 @@ void Dbdih::calculateKeepGciLab(Signal* signal, Uint32 tableId, Uint32 fragId) FragmentstorePtr fragPtr; getFragstore(tabPtr.p, fragId, fragPtr); checkKeepGci(tabPtr, fragId, fragPtr.p, fragPtr.p->storedReplicas); + checkKeepGci(tabPtr, fragId, fragPtr.p, fragPtr.p->oldStoredReplicas); fragId++; if (fragId >= tabPtr.p->totalfragments) { jam(); @@ -12875,16 +12921,75 @@ void Dbdih::removeTooNewCrashedReplicas(ReplicaRecordPtr rtnReplicaPtr) /* CHECKPOINT WITHOUT NEEDING ANY EXTRA LOGGING FACILITIES.*/ /* A MAXIMUM OF FOUR NODES IS RETRIEVED. */ /*************************************************************************/ +bool +Dbdih::setup_create_replica(FragmentstorePtr fragPtr, + CreateReplicaRecord* createReplicaPtrP, + ConstPtr<ReplicaRecord> replicaPtr) +{ + createReplicaPtrP->dataNodeId = replicaPtr.p->procNode; + createReplicaPtrP->replicaRec = replicaPtr.i; + + /* ----------------------------------------------------------------- */ + /* WE NEED TO SEARCH FOR A PROPER LOCAL CHECKPOINT TO USE FOR THE */ + /* SYSTEM RESTART. */ + /* ----------------------------------------------------------------- */ + Uint32 startGci; + Uint32 startLcpNo; + Uint32 stopGci = SYSFILE->newestRestorableGCI; + bool result = findStartGci(replicaPtr, + stopGci, + startGci, + startLcpNo); + if (!result) + { + jam(); + /* --------------------------------------------------------------- */ + /* WE COULD NOT FIND ANY LOCAL CHECKPOINT. THE FRAGMENT THUS DO NOT*/ + /* CONTAIN ANY VALID LOCAL CHECKPOINT. IT DOES HOWEVER CONTAIN A */ + /* VALID FRAGMENT LOG. THUS BY FIRST CREATING THE FRAGMENT AND THEN*/ + /* EXECUTING THE FRAGMENT LOG WE CAN CREATE THE FRAGMENT AS */ + /* DESIRED. THIS SHOULD ONLY OCCUR AFTER CREATING A FRAGMENT. */ + /* */ + /* TO INDICATE THAT NO LOCAL CHECKPOINT IS TO BE USED WE SET THE */ + /* LOCAL CHECKPOINT TO ZNIL. */ + /* --------------------------------------------------------------- */ + createReplicaPtrP->lcpNo = ZNIL; + } + else + { + jam(); + /* --------------------------------------------------------------- */ + /* WE FOUND A PROPER LOCAL CHECKPOINT TO RESTART FROM. */ + /* SET LOCAL CHECKPOINT ID AND LOCAL CHECKPOINT NUMBER. */ + /* --------------------------------------------------------------- */ + createReplicaPtrP->lcpNo = startLcpNo; + arrGuard(startLcpNo, MAX_LCP_STORED); + createReplicaPtrP->createLcpId = replicaPtr.p->lcpId[startLcpNo]; + }//if + + + /* ----------------------------------------------------------------- */ + /* WE HAVE EITHER FOUND A LOCAL CHECKPOINT OR WE ARE PLANNING TO */ + /* EXECUTE THE LOG FROM THE INITIAL CREATION OF THE TABLE. IN BOTH */ + /* CASES WE NEED TO FIND A SET OF LOGS THAT CAN EXECUTE SUCH THAT */ + /* WE RECOVER TO THE SYSTEM RESTART GLOBAL CHECKPOINT. */ + /* -_--------------------------------------------------------------- */ + return findLogNodes(createReplicaPtrP, fragPtr, startGci, stopGci); +} + void Dbdih::searchStoredReplicas(FragmentstorePtr fragPtr) { Uint32 nextReplicaPtrI; - ConstPtr<ReplicaRecord> replicaPtr; + Ptr<ReplicaRecord> replicaPtr; replicaPtr.i = fragPtr.p->storedReplicas; while (replicaPtr.i != RNIL) { jam(); ptrCheckGuard(replicaPtr, creplicaFileSize, replicaRecord); nextReplicaPtrI = replicaPtr.p->nextReplica; + ConstPtr<ReplicaRecord> constReplicaPtr; + constReplicaPtr.i = replicaPtr.i; + constReplicaPtr.p = replicaPtr.p; NodeRecordPtr nodePtr; nodePtr.i = replicaPtr.p->procNode; ptrCheckGuard(nodePtr, MAX_NDB_NODES, nodeRecord); @@ -12904,69 +13009,13 @@ void Dbdih::searchStoredReplicas(FragmentstorePtr fragPtr) createReplicaPtr.i = cnoOfCreateReplicas; ptrCheckGuard(createReplicaPtr, 4, createReplicaRecord); cnoOfCreateReplicas++; - createReplicaPtr.p->dataNodeId = replicaPtr.p->procNode; - createReplicaPtr.p->replicaRec = replicaPtr.i; - /* ----------------------------------------------------------------- */ - /* WE NEED TO SEARCH FOR A PROPER LOCAL CHECKPOINT TO USE FOR THE */ - /* SYSTEM RESTART. */ - /* ----------------------------------------------------------------- */ - Uint32 startGci; - Uint32 startLcpNo; - Uint32 stopGci = SYSFILE->newestRestorableGCI; - bool result = findStartGci(replicaPtr, - stopGci, - startGci, - startLcpNo); - if (!result) { - jam(); - /* --------------------------------------------------------------- */ - /* WE COULD NOT FIND ANY LOCAL CHECKPOINT. THE FRAGMENT THUS DO NOT*/ - /* CONTAIN ANY VALID LOCAL CHECKPOINT. IT DOES HOWEVER CONTAIN A */ - /* VALID FRAGMENT LOG. THUS BY FIRST CREATING THE FRAGMENT AND THEN*/ - /* EXECUTING THE FRAGMENT LOG WE CAN CREATE THE FRAGMENT AS */ - /* DESIRED. THIS SHOULD ONLY OCCUR AFTER CREATING A FRAGMENT. */ - /* */ - /* TO INDICATE THAT NO LOCAL CHECKPOINT IS TO BE USED WE SET THE */ - /* LOCAL CHECKPOINT TO ZNIL. */ - /* --------------------------------------------------------------- */ - createReplicaPtr.p->lcpNo = ZNIL; - } else { - jam(); - /* --------------------------------------------------------------- */ - /* WE FOUND A PROPER LOCAL CHECKPOINT TO RESTART FROM. */ - /* SET LOCAL CHECKPOINT ID AND LOCAL CHECKPOINT NUMBER. */ - /* --------------------------------------------------------------- */ - createReplicaPtr.p->lcpNo = startLcpNo; - arrGuard(startLcpNo, MAX_LCP_STORED); - createReplicaPtr.p->createLcpId = replicaPtr.p->lcpId[startLcpNo]; - }//if - - if(ERROR_INSERTED(7073) || ERROR_INSERTED(7074)){ - jam(); - nodePtr.p->nodeStatus = NodeRecord::DEAD; - } - - /* ----------------------------------------------------------------- */ - /* WE HAVE EITHER FOUND A LOCAL CHECKPOINT OR WE ARE PLANNING TO */ - /* EXECUTE THE LOG FROM THE INITIAL CREATION OF THE TABLE. IN BOTH */ - /* CASES WE NEED TO FIND A SET OF LOGS THAT CAN EXECUTE SUCH THAT */ - /* WE RECOVER TO THE SYSTEM RESTART GLOBAL CHECKPOINT. */ - /* -_--------------------------------------------------------------- */ - if (!findLogNodes(createReplicaPtr.p, fragPtr, startGci, stopGci)) { - jam(); - /* --------------------------------------------------------------- */ - /* WE WERE NOT ABLE TO FIND ANY WAY OF RESTORING THIS REPLICA. */ - /* THIS IS A POTENTIAL SYSTEM ERROR. */ - /* --------------------------------------------------------------- */ - cnoOfCreateReplicas--; - return; - }//if - - if(ERROR_INSERTED(7073) || ERROR_INSERTED(7074)){ - jam(); - nodePtr.p->nodeStatus = NodeRecord::ALIVE; - } + /** + * Should have been checked in resetReplicaSr + */ + ndbrequire(setup_create_replica(fragPtr, + createReplicaPtr.p, + constReplicaPtr)); break; } default: diff --git a/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp b/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp index 04f44a2742d..3fdd587afa5 100644 --- a/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp +++ b/storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp @@ -1295,6 +1295,7 @@ void Dbtc::execTCRELEASEREQ(Signal* signal) apiConnectptr.p->firstTcConnect == RNIL)) { jam(); /* JUST REPLY OK */ + apiConnectptr.p->m_transaction_nodes.clear(); releaseApiCon(signal, apiConnectptr.i); signal->theData[0] = tuserpointer; sendSignal(tapiBlockref, diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupAbort.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupAbort.cpp index 16c51f7aa6e..76f4c215618 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupAbort.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupAbort.cpp @@ -352,7 +352,8 @@ void Dbtup::tupkeyErrorLab(Signal* signal) tabPtr.i= fragPtr.p->fragTableId; ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec); - if (regOperPtr->m_undo_buffer_space) + if (regOperPtr->m_undo_buffer_space && + (regOperPtr->is_first_operation() && regOperPtr->is_last_operation())) { c_lgman->free_log_space(fragPtr.p->m_logfile_group_id, regOperPtr->m_undo_buffer_space); diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp index 56f7fb1dd1e..a055b18888b 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp @@ -75,7 +75,7 @@ Dbtup::dump_disk_alloc(Dbtup::Disk_alloc_info & alloc) for(Uint32 i = 0; i<MAX_FREE_LIST; i++) { printf(" %d : ", i); - Ptr<Page> ptr; + PagePtr ptr; ArrayPool<Page> *pool= (ArrayPool<Page>*)&m_global_page_pool; LocalDLList<Page> list(*pool, alloc.m_dirty_pages[i]); for(list.first(ptr); !ptr.isNull(); list.next(ptr)) @@ -262,7 +262,7 @@ Dbtup::update_extent_pos(Disk_alloc_info& alloc, } void -Dbtup::restart_setup_page(Disk_alloc_info& alloc, Ptr<Page> pagePtr) +Dbtup::restart_setup_page(Disk_alloc_info& alloc, PagePtr pagePtr) { /** * Link to extent, clear uncommitted_used_space @@ -344,12 +344,15 @@ Dbtup::disk_page_prealloc(Signal* signal, if (!alloc.m_dirty_pages[i].isEmpty()) { ptrI= alloc.m_dirty_pages[i].firstItem; - Ptr<GlobalPage> page; - m_global_page_pool.getPtr(page, ptrI); + Ptr<GlobalPage> gpage; + m_global_page_pool.getPtr(gpage, ptrI); - disk_page_prealloc_dirty_page(alloc, *(PagePtr*)&page, i, sz); - key->m_page_no= ((Page*)page.p)->m_page_no; - key->m_file_no= ((Page*)page.p)->m_file_no; + PagePtr tmp; + tmp.i = gpage.i; + tmp.p = reinterpret_cast<Page*>(gpage.p); + disk_page_prealloc_dirty_page(alloc, tmp, i, sz); + key->m_page_no= tmp.p->m_page_no; + key->m_file_no= tmp.p->m_file_no; if (DBG_DISK) ndbout << " found dirty page " << *key << endl; return 0; // Page in memory @@ -547,7 +550,7 @@ Dbtup::disk_page_prealloc(Signal* signal, void Dbtup::disk_page_prealloc_dirty_page(Disk_alloc_info & alloc, - Ptr<Page> pagePtr, + PagePtr pagePtr, Uint32 old_idx, Uint32 sz) { ddassert(pagePtr.p->list_index == old_idx); @@ -638,7 +641,9 @@ Dbtup::disk_page_prealloc_callback(Signal* signal, fragPtr.i= req.p->m_frag_ptr_i; ptrCheckGuard(fragPtr, cnoOfFragrec, fragrecord); - Ptr<Page> pagePtr = *(Ptr<Page>*)&gpage; + PagePtr pagePtr; + pagePtr.i = gpage.i; + pagePtr.p = reinterpret_cast<Page*>(gpage.p); if (unlikely(pagePtr.p->m_restart_seq != globalData.m_restart_seq)) { @@ -666,7 +671,9 @@ Dbtup::disk_page_prealloc_initial_callback(Signal*signal, Ptr<GlobalPage> gpage; m_global_page_pool.getPtr(gpage, page_id); - Ptr<Page> pagePtr = *(Ptr<Page>*)&gpage; + PagePtr pagePtr; + pagePtr.i = gpage.i; + pagePtr.p = reinterpret_cast<Page*>(gpage.p); Ptr<Fragrecord> fragPtr; fragPtr.i= req.p->m_frag_ptr_i; @@ -705,7 +712,7 @@ void Dbtup::disk_page_prealloc_callback_common(Signal* signal, Ptr<Page_request> req, Ptr<Fragrecord> fragPtr, - Ptr<Page> pagePtr) + PagePtr pagePtr) { /** * 1) remove page request from Disk_alloc_info.m_page_requests @@ -736,7 +743,7 @@ Dbtup::disk_page_prealloc_callback_common(Signal* signal, */ ArrayPool<Page> *cheat_pool= (ArrayPool<Page>*)&m_global_page_pool; LocalDLList<Page> list(* cheat_pool, alloc.m_dirty_pages[new_idx]); - list.add(*(Ptr<Page>*)&pagePtr); + list.add(pagePtr); pagePtr.p->uncommitted_used_space = real_used; pagePtr.p->list_index = new_idx; @@ -765,7 +772,7 @@ Dbtup::disk_page_prealloc_callback_common(Signal* signal, } void -Dbtup::disk_page_set_dirty(Ptr<Page> pagePtr) +Dbtup::disk_page_set_dirty(PagePtr pagePtr) { Uint32 idx = pagePtr.p->list_index; if ((idx & 0x8000) == 0) @@ -833,7 +840,9 @@ Dbtup::disk_page_unmap_callback(Uint32 page_id, Uint32 dirty_count) { Ptr<GlobalPage> gpage; m_global_page_pool.getPtr(gpage, page_id); - PagePtr pagePtr= *(PagePtr*)&gpage; + PagePtr pagePtr; + pagePtr.i = gpage.i; + pagePtr.p = reinterpret_cast<Page*>(gpage.p); Uint32 type = pagePtr.p->m_page_header.m_page_type; if (unlikely((type != File_formats::PT_Tup_fixsize_page && @@ -1028,10 +1037,13 @@ Dbtup::disk_page_abort_prealloc(Signal *signal, Fragrecord* fragPtrP, case -1: break; default: - Ptr<GlobalPage> page; - m_global_page_pool.getPtr(page, (Uint32)res); - disk_page_abort_prealloc_callback_1(signal, fragPtrP, *(PagePtr*)&page, - sz); + Ptr<GlobalPage> gpage; + m_global_page_pool.getPtr(gpage, (Uint32)res); + PagePtr pagePtr; + pagePtr.i = gpage.i; + pagePtr.p = reinterpret_cast<Page*>(gpage.p); + + disk_page_abort_prealloc_callback_1(signal, fragPtrP, pagePtr, sz); } } @@ -1044,8 +1056,10 @@ Dbtup::disk_page_abort_prealloc_callback(Signal* signal, Ptr<GlobalPage> gpage; m_global_page_pool.getPtr(gpage, page_id); - PagePtr pagePtr= *(PagePtr*)&gpage; - + PagePtr pagePtr; + pagePtr.i = gpage.i; + pagePtr.p = reinterpret_cast<Page*>(gpage.p); + Ptr<Tablerec> tabPtr; tabPtr.i= pagePtr.p->m_table_id; ptrCheckGuard(tabPtr, cnoOfTablerec, tablerec); @@ -1308,7 +1322,9 @@ Dbtup::disk_restart_undo_callback(Signal* signal, jamEntry(); Ptr<GlobalPage> gpage; m_global_page_pool.getPtr(gpage, page_id); - Ptr<Page> pagePtr = *(Ptr<Page>*)&gpage; + PagePtr pagePtr; + pagePtr.i = gpage.i; + pagePtr.p = reinterpret_cast<Page*>(gpage.p); Apply_undo* undo = &f_undo; diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp index 3118164badd..d9710cc2549 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp @@ -1039,22 +1039,19 @@ int Dbtup::handleUpdateReq(Signal* signal, tup_version= (tup_version + 1) & ZTUP_VERSION_MASK; operPtrP->tupVersion= tup_version; - int retValue; if (!req_struct->interpreted_exec) { jam(); - retValue= updateAttributes(req_struct, - &cinBuffer[0], - req_struct->attrinfo_len); + int retValue = updateAttributes(req_struct, + &cinBuffer[0], + req_struct->attrinfo_len); + if (unlikely(retValue == -1)) + goto error; } else { jam(); if (unlikely(interpreterStartLab(signal, req_struct) == -1)) return -1; } - if (retValue == -1) { - goto error; - } - if (regTabPtr->need_shrink()) { shrink_tuple(req_struct, sizes+2, regTabPtr, disk); @@ -1073,7 +1070,7 @@ int Dbtup::handleUpdateReq(Signal* signal, jam(); setChecksum(req_struct->m_tuple_ptr, regTabPtr); } - return retValue; + return 0; error: tupkeyErrorLab(signal); diff --git a/storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp b/storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp index c59cf4015af..973d2f7a9ef 100644 --- a/storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp +++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp @@ -169,7 +169,8 @@ void Dbtup::execCONTINUEB(Signal* signal) case ZREPORT_MEMORY_USAGE:{ ljam(); static int c_currentMemUsed = 0; - int now = (cnoOfAllocatedPages * 100)/c_page_pool.getSize(); + Uint32 tmp = c_page_pool.getSize(); + int now = tmp ? (cnoOfAllocatedPages * 100)/tmp : 0; const int thresholds[] = { 100, 90, 80, 0 }; Uint32 i = 0; diff --git a/storage/ndb/src/kernel/blocks/dbtux/Dbtux.hpp b/storage/ndb/src/kernel/blocks/dbtux/Dbtux.hpp index 946504ec3a5..d943fabd5c9 100644 --- a/storage/ndb/src/kernel/blocks/dbtux/Dbtux.hpp +++ b/storage/ndb/src/kernel/blocks/dbtux/Dbtux.hpp @@ -23,6 +23,7 @@ #include <AttributeHeader.hpp> #include <ArrayPool.hpp> #include <DataBuffer.hpp> +#include <DLFifoList.hpp> #include <md5_hash.hpp> // big brother @@ -126,41 +127,17 @@ private: // forward declarations struct DescEnt; - /* - * Pointer to array of Uint32. - */ - struct Data { - private: - Uint32* m_data; - public: - Data(); - Data(Uint32* data); - Data& operator=(Uint32* data); - operator Uint32*() const; - Data& operator+=(size_t n); - AttributeHeader& ah() const; - }; - friend class Data; + // Pointer to array of Uint32 represents attribute data and bounds - /* - * Pointer to array of constant Uint32. - */ - struct ConstData; - friend struct ConstData; - struct ConstData { - private: - const Uint32* m_data; - public: - ConstData(); - ConstData(const Uint32* data); - ConstData& operator=(const Uint32* data); - operator const Uint32*() const; - ConstData& operator+=(size_t n); - const AttributeHeader& ah() const; - // non-const pointer can be cast to const pointer - ConstData(Data data); - ConstData& operator=(Data data); - }; + typedef Uint32 *Data; + inline AttributeHeader& ah(Data data) { + return *reinterpret_cast<AttributeHeader*>(data); + } + + typedef const Uint32* ConstData; + inline const AttributeHeader& ah(ConstData data) { + return *reinterpret_cast<const AttributeHeader*>(data); + } // AttributeHeader size is assumed to be 1 word STATIC_CONST( AttributeHeaderSize = 1 ); @@ -216,6 +193,7 @@ private: unsigned m_tupVersion : 15; // version TreeEnt(); // methods + bool eqtuple(const TreeEnt ent) const; bool eq(const TreeEnt ent) const; int cmp(const TreeEnt ent) const; }; @@ -294,8 +272,7 @@ private: struct TreePos { TupLoc m_loc; // physical node address Uint16 m_pos; // position 0 to m_occup - Uint8 m_match; // at an existing entry - Uint8 m_dir; // see scanNext() + Uint8 m_dir; // see scanNext TreePos(); }; @@ -362,6 +339,18 @@ private: typedef DataBuffer<ScanBoundSegmentSize>::ConstDataBufferIterator ScanBoundIterator; typedef DataBuffer<ScanBoundSegmentSize>::DataBufferPool ScanBoundPool; ScanBoundPool c_scanBoundPool; + + // ScanLock + struct ScanLock { + Uint32 m_accLockOp; + union { + Uint32 nextPool; + Uint32 nextList; + }; + Uint32 prevList; + }; + typedef Ptr<ScanLock> ScanLockPtr; + ArrayPool<ScanLock> c_scanLockPool; /* * Scan operation. @@ -386,12 +375,13 @@ private: enum { Undef = 0, First = 1, // before first entry - Current = 2, // at current before locking - Blocked = 3, // at current waiting for ACC lock - Locked = 4, // at current and locked or no lock needed - Next = 5, // looking for next extry - Last = 6, // after last entry - Aborting = 7, // lock wait at scan close + Current = 2, // at some entry + Found = 3, // return current as next scan result + Blocked = 4, // found and waiting for ACC lock + Locked = 5, // found and locked or no lock needed + Next = 6, // looking for next extry + Last = 7, // after last entry + Aborting = 8, // lock wait at scan close Invalid = 9 // cannot return REF to LQH currently }; Uint16 m_state; @@ -407,6 +397,8 @@ private: Uint32 m_savePointId; // lock waited for or obtained and not yet passed to LQH Uint32 m_accLockOp; + // locks obtained and passed to LQH but not yet returned by LQH + DLFifoList<ScanLock>::Head m_accLockOps; Uint8 m_readCommitted; // no locking Uint8 m_lockMode; Uint8 m_descending; @@ -422,13 +414,6 @@ private: Uint32 nextList; }; Uint32 prevList; - /* - * Locks obtained and passed to LQH but not yet returned by LQH. - * The max was increased from 16 to 992 (default 64). Record max - * ever used in this scan. TODO fix quadratic behaviour - */ - Uint32 m_maxAccLockOps; - Uint32 m_accLockOps[MaxAccLockOps]; ScanOp(ScanBoundPool& scanBoundPool); }; typedef Ptr<ScanOp> ScanOpPtr; @@ -568,6 +553,7 @@ private: void readKeyAttrs(const Frag& frag, TreeEnt ent, unsigned start, Data keyData); void readTablePk(const Frag& frag, TreeEnt ent, Data pkData, unsigned& pkSize); void copyAttrs(const Frag& frag, ConstData data1, Data data2, unsigned maxlen2 = MaxAttrDataSize); + void unpackBound(const ScanBound& bound, Data data); /* * DbtuxMeta.cpp @@ -642,18 +628,21 @@ private: void execACCKEYREF(Signal* signal); void execACC_ABORTCONF(Signal* signal); void scanFirst(ScanOpPtr scanPtr); + void scanFind(ScanOpPtr scanPtr); void scanNext(ScanOpPtr scanPtr, bool fromMaintReq); + bool scanCheck(ScanOpPtr scanPtr, TreeEnt ent); bool scanVisible(ScanOpPtr scanPtr, TreeEnt ent); void scanClose(Signal* signal, ScanOpPtr scanPtr); - void addAccLockOp(ScanOp& scan, Uint32 accLockOp); - void removeAccLockOp(ScanOp& scan, Uint32 accLockOp); + void abortAccLockOps(Signal* signal, ScanOpPtr scanPtr); + void addAccLockOp(ScanOpPtr scanPtr, Uint32 accLockOp); + void removeAccLockOp(ScanOpPtr scanPtr, Uint32 accLockOp); void releaseScanOp(ScanOpPtr& scanPtr); /* * DbtuxSearch.cpp */ - void searchToAdd(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& treePos); - void searchToRemove(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& treePos); + bool searchToAdd(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& treePos); + bool searchToRemove(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& treePos); void searchToScan(Frag& frag, ConstData boundInfo, unsigned boundCount, bool descending, TreePos& treePos); void searchToScanAscending(Frag& frag, ConstData boundInfo, unsigned boundCount, TreePos& treePos); void searchToScanDescending(Frag& frag, ConstData boundInfo, unsigned boundCount, TreePos& treePos); @@ -707,7 +696,8 @@ private: DebugMeta = 1, // log create and drop index DebugMaint = 2, // log maintenance ops DebugTree = 4, // log and check tree after each op - DebugScan = 8 // log scans + DebugScan = 8, // log scans + DebugLock = 16 // log ACC locks }; STATIC_CONST( DataFillByte = 0xa2 ); STATIC_CONST( NodeFillByte = 0xa4 ); @@ -750,99 +740,6 @@ private: static unsigned max(unsigned x, unsigned y); }; -// Dbtux::Data - -inline -Dbtux::Data::Data() : - m_data(0) -{ -} - -inline -Dbtux::Data::Data(Uint32* data) : - m_data(data) -{ -} - -inline Dbtux::Data& -Dbtux::Data::operator=(Uint32* data) -{ - m_data = data; - return *this; -} - -inline -Dbtux::Data::operator Uint32*() const -{ - return m_data; -} - -inline Dbtux::Data& -Dbtux::Data::operator+=(size_t n) -{ - m_data += n; - return *this; -} - -inline AttributeHeader& -Dbtux::Data::ah() const -{ - return *reinterpret_cast<AttributeHeader*>(m_data); -} - -// Dbtux::ConstData - -inline -Dbtux::ConstData::ConstData() : - m_data(0) -{ -} - -inline -Dbtux::ConstData::ConstData(const Uint32* data) : - m_data(data) -{ -} - -inline Dbtux::ConstData& -Dbtux::ConstData::operator=(const Uint32* data) -{ - m_data = data; - return *this; -} - -inline -Dbtux::ConstData::operator const Uint32*() const -{ - return m_data; -} - -inline Dbtux::ConstData& -Dbtux::ConstData::operator+=(size_t n) -{ - m_data += n; - return *this; -} - -inline const AttributeHeader& -Dbtux::ConstData::ah() const -{ - return *reinterpret_cast<const AttributeHeader*>(m_data); -} - -inline -Dbtux::ConstData::ConstData(Data data) : - m_data(static_cast<Uint32*>(data)) -{ -} - -inline Dbtux::ConstData& -Dbtux::ConstData::operator=(Data data) -{ - m_data = static_cast<Uint32*>(data); - return *this; -} - // Dbtux::TupLoc inline @@ -911,6 +808,13 @@ Dbtux::TreeEnt::TreeEnt() : } inline bool +Dbtux::TreeEnt::eqtuple(const TreeEnt ent) const +{ + return + m_tupLoc == ent.m_tupLoc; +} + +inline bool Dbtux::TreeEnt::eq(const TreeEnt ent) const { return @@ -929,10 +833,25 @@ Dbtux::TreeEnt::cmp(const TreeEnt ent) const return -1; if (m_tupLoc.getPageOffset() > ent.m_tupLoc.getPageOffset()) return +1; - if (m_tupVersion < ent.m_tupVersion) - return -1; - if (m_tupVersion > ent.m_tupVersion) - return +1; + /* + * Guess if one tuple version has wrapped around. This is well + * defined ordering on existing versions since versions are assigned + * consecutively and different versions exists only on uncommitted + * tuple. Assuming max 2**14 uncommitted ops on same tuple. + */ + const unsigned version_wrap_limit = (1 << (ZTUP_VERSION_BITS - 1)); + if (m_tupVersion < ent.m_tupVersion) { + if (ent.m_tupVersion - m_tupVersion < version_wrap_limit) + return -1; + else + return +1; + } + if (m_tupVersion > ent.m_tupVersion) { + if (m_tupVersion - ent.m_tupVersion < version_wrap_limit) + return +1; + else + return -1; + } return 0; } @@ -1000,7 +919,6 @@ inline Dbtux::TreePos::TreePos() : m_loc(), m_pos(ZNIL), - m_match(false), m_dir(255) { } @@ -1036,6 +954,7 @@ Dbtux::ScanOp::ScanOp(ScanBoundPool& scanBoundPool) : m_transId2(0), m_savePointId(0), m_accLockOp(RNIL), + m_accLockOps(), m_readCommitted(0), m_lockMode(0), m_descending(0), @@ -1043,18 +962,12 @@ Dbtux::ScanOp::ScanOp(ScanBoundPool& scanBoundPool) : m_boundMax(scanBoundPool), m_scanPos(), m_scanEnt(), - m_nodeScan(RNIL), - m_maxAccLockOps(0) + m_nodeScan(RNIL) { m_bound[0] = &m_boundMin; m_bound[1] = &m_boundMax; m_boundCnt[0] = 0; m_boundCnt[1] = 0; -#ifdef VM_TRACE - for (unsigned i = 0; i < MaxAccLockOps; i++) { - m_accLockOps[i] = 0x1f1f1f1f; - } -#endif } // Dbtux::Index diff --git a/storage/ndb/src/kernel/blocks/dbtux/DbtuxCmp.cpp b/storage/ndb/src/kernel/blocks/dbtux/DbtuxCmp.cpp index cf815b14c1a..058409c99b0 100644 --- a/storage/ndb/src/kernel/blocks/dbtux/DbtuxCmp.cpp +++ b/storage/ndb/src/kernel/blocks/dbtux/DbtuxCmp.cpp @@ -34,7 +34,7 @@ Dbtux::cmpSearchKey(const Frag& frag, unsigned& start, ConstData searchKey, Cons // skip to right position in search key only for (unsigned i = 0; i < start; i++) { jam(); - searchKey += AttributeHeaderSize + searchKey.ah().getDataSize(); + searchKey += AttributeHeaderSize + ah(searchKey).getDataSize(); } // number of words of entry data left unsigned len2 = maxlen; @@ -46,16 +46,16 @@ Dbtux::cmpSearchKey(const Frag& frag, unsigned& start, ConstData searchKey, Cons break; } len2 -= AttributeHeaderSize; - if (! searchKey.ah().isNULL()) { - if (! entryData.ah().isNULL()) { + if (! ah(searchKey).isNULL()) { + if (! ah(entryData).isNULL()) { jam(); // verify attribute id const DescAttr& descAttr = descEnt.m_descAttr[start]; - ndbrequire(searchKey.ah().getAttributeId() == descAttr.m_primaryAttrId); - ndbrequire(entryData.ah().getAttributeId() == descAttr.m_primaryAttrId); + ndbrequire(ah(searchKey).getAttributeId() == descAttr.m_primaryAttrId); + ndbrequire(ah(entryData).getAttributeId() == descAttr.m_primaryAttrId); // sizes - const unsigned size1 = searchKey.ah().getDataSize(); - const unsigned size2 = min(entryData.ah().getDataSize(), len2); + const unsigned size1 = ah(searchKey).getDataSize(); + const unsigned size2 = min(ah(entryData).getDataSize(), len2); len2 -= size2; // compare NdbSqlUtil::Cmp* const cmp = c_sqlCmp[start]; @@ -74,15 +74,15 @@ Dbtux::cmpSearchKey(const Frag& frag, unsigned& start, ConstData searchKey, Cons break; } } else { - if (! entryData.ah().isNULL()) { + if (! ah(entryData).isNULL()) { jam(); // NULL < not NULL ret = -1; break; } } - searchKey += AttributeHeaderSize + searchKey.ah().getDataSize(); - entryData += AttributeHeaderSize + entryData.ah().getDataSize(); + searchKey += AttributeHeaderSize + ah(searchKey).getDataSize(); + entryData += AttributeHeaderSize + ah(entryData).getDataSize(); start++; } return ret; @@ -130,17 +130,17 @@ Dbtux::cmpScanBound(const Frag& frag, unsigned idir, ConstData boundInfo, unsign // get and skip bound type (it is used after the loop) type = boundInfo[0]; boundInfo += 1; - if (! boundInfo.ah().isNULL()) { - if (! entryData.ah().isNULL()) { + if (! ah(boundInfo).isNULL()) { + if (! ah(entryData).isNULL()) { jam(); // verify attribute id - const Uint32 index = boundInfo.ah().getAttributeId(); + const Uint32 index = ah(boundInfo).getAttributeId(); ndbrequire(index < frag.m_numAttrs); const DescAttr& descAttr = descEnt.m_descAttr[index]; - ndbrequire(entryData.ah().getAttributeId() == descAttr.m_primaryAttrId); + ndbrequire(ah(entryData).getAttributeId() == descAttr.m_primaryAttrId); // sizes - const unsigned size1 = boundInfo.ah().getDataSize(); - const unsigned size2 = min(entryData.ah().getDataSize(), len2); + const unsigned size1 = ah(boundInfo).getDataSize(); + const unsigned size2 = min(ah(entryData).getDataSize(), len2); len2 -= size2; // compare NdbSqlUtil::Cmp* const cmp = c_sqlCmp[index]; @@ -159,14 +159,14 @@ Dbtux::cmpScanBound(const Frag& frag, unsigned idir, ConstData boundInfo, unsign } } else { jam(); - if (! entryData.ah().isNULL()) { + if (! ah(entryData).isNULL()) { jam(); // NULL < not NULL return -1; } } - boundInfo += AttributeHeaderSize + boundInfo.ah().getDataSize(); - entryData += AttributeHeaderSize + entryData.ah().getDataSize(); + boundInfo += AttributeHeaderSize + ah(boundInfo).getDataSize(); + entryData += AttributeHeaderSize + ah(entryData).getDataSize(); boundCount -= 1; } // all attributes were equal diff --git a/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp b/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp index a9eae510ce6..61aae83ca27 100644 --- a/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp +++ b/storage/ndb/src/kernel/blocks/dbtux/DbtuxDebug.cpp @@ -280,7 +280,6 @@ operator<<(NdbOut& out, const Dbtux::TreePos& pos) out << "[TreePos " << hex << &pos; out << " [loc " << pos.m_loc << "]"; out << " [pos " << dec << pos.m_pos << "]"; - out << " [match " << dec << pos.m_match << "]"; out << " [dir " << dec << pos.m_dir << "]"; out << "]"; return out; @@ -300,6 +299,7 @@ operator<<(NdbOut& out, const Dbtux::DescAttr& descAttr) NdbOut& operator<<(NdbOut& out, const Dbtux::ScanOp& scan) { + Dbtux* tux = (Dbtux*)globalData.getBlock(DBTUX); out << "[ScanOp " << hex << &scan; out << " [state " << dec << scan.m_state << "]"; out << " [lockwait " << dec << scan.m_lockwait << "]"; @@ -309,9 +309,15 @@ operator<<(NdbOut& out, const Dbtux::ScanOp& scan) out << " [savePointId " << dec << scan.m_savePointId << "]"; out << " [accLockOp " << hex << scan.m_accLockOp << "]"; out << " [accLockOps"; - for (unsigned i = 0; i < scan.m_maxAccLockOps; i++) { - if (scan.m_accLockOps[i] != RNIL) - out << " " << hex << scan.m_accLockOps[i]; + { + DLFifoList<Dbtux::ScanLock>::Head head = scan.m_accLockOps; + LocalDLFifoList<Dbtux::ScanLock> list(tux->c_scanLockPool, head); + Dbtux::ScanLockPtr lockPtr; + list.first(lockPtr); + while (lockPtr.i != RNIL) { + out << " " << hex << lockPtr.p->m_accLockOp; + list.next(lockPtr); + } } out << "]"; out << " [readCommitted " << dec << scan.m_readCommitted << "]"; @@ -337,13 +343,12 @@ operator<<(NdbOut& out, const Dbtux::ScanOp& scan) NdbOut& operator<<(NdbOut& out, const Dbtux::Index& index) { + Dbtux* tux = (Dbtux*)globalData.getBlock(DBTUX); out << "[Index " << hex << &index; out << " [tableId " << dec << index.m_tableId << "]"; out << " [numFrags " << dec << index.m_numFrags << "]"; for (unsigned i = 0; i < index.m_numFrags; i++) { out << " [frag " << dec << i << " "; - // dangerous and wrong - Dbtux* tux = (Dbtux*)globalData.getBlock(DBTUX); const Dbtux::Frag& frag = *tux->c_fragPool.getPtr(index.m_fragPtrI[i]); out << frag; out << "]"; diff --git a/storage/ndb/src/kernel/blocks/dbtux/DbtuxGen.cpp b/storage/ndb/src/kernel/blocks/dbtux/DbtuxGen.cpp index a2e285078c0..beed787f45f 100644 --- a/storage/ndb/src/kernel/blocks/dbtux/DbtuxGen.cpp +++ b/storage/ndb/src/kernel/blocks/dbtux/DbtuxGen.cpp @@ -163,6 +163,7 @@ Dbtux::execREAD_CONFIG_REQ(Signal* signal) Uint32 nFragment; Uint32 nAttribute; Uint32 nScanOp; + Uint32 nScanBatch; const ndb_mgm_configuration_iterator * p = m_ctx.m_config.getOwnConfigIterator(); @@ -172,9 +173,11 @@ Dbtux::execREAD_CONFIG_REQ(Signal* signal) ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUX_FRAGMENT, &nFragment)); ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUX_ATTRIBUTE, &nAttribute)); ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_TUX_SCAN_OP, &nScanOp)); + ndbrequire(!ndb_mgm_get_int_parameter(p, CFG_DB_BATCH_SIZE, &nScanBatch)); const Uint32 nDescPage = (nIndex * DescHeadSize + nAttribute * DescAttrSize + DescPageSize - 1) / DescPageSize; const Uint32 nScanBoundWords = nScanOp * ScanBoundSegmentSize * 4; + const Uint32 nScanLock = nScanOp * nScanBatch; c_indexPool.setSize(nIndex); c_fragPool.setSize(nFragment); @@ -182,6 +185,7 @@ Dbtux::execREAD_CONFIG_REQ(Signal* signal) c_fragOpPool.setSize(MaxIndexFragments); c_scanOpPool.setSize(nScanOp); c_scanBoundPool.setSize(nScanBoundWords); + c_scanLockPool.setSize(nScanLock); /* * Index id is physical array index. We seize and initialize all * index records now. @@ -225,7 +229,7 @@ Dbtux::setKeyAttrs(const Frag& frag) const DescAttr& descAttr = descEnt.m_descAttr[i]; Uint32 size = AttributeDescriptor::getSizeInWords(descAttr.m_attrDesc); // set attr id and fixed size - keyAttrs.ah() = AttributeHeader(descAttr.m_primaryAttrId, size); + ah(keyAttrs) = AttributeHeader(descAttr.m_primaryAttrId, size); keyAttrs += 1; // set comparison method pointer const NdbSqlUtil::Type& sqlType = NdbSqlUtil::getTypeBinary(descAttr.m_typeId); @@ -255,8 +259,8 @@ Dbtux::readKeyAttrs(const Frag& frag, TreeEnt ent, unsigned start, Data keyData) ConstData data = keyData; Uint32 totalSize = 0; for (Uint32 i = start; i < frag.m_numAttrs; i++) { - Uint32 attrId = data.ah().getAttributeId(); - Uint32 dataSize = data.ah().getDataSize(); + Uint32 attrId = ah(data).getAttributeId(); + Uint32 dataSize = ah(data).getDataSize(); debugOut << i << " attrId=" << attrId << " size=" << dataSize; data += 1; for (Uint32 j = 0; j < dataSize; j++) { @@ -294,7 +298,7 @@ Dbtux::copyAttrs(const Frag& frag, ConstData data1, Data data2, unsigned maxlen2 unsigned len2 = maxlen2; while (n != 0) { jam(); - const unsigned dataSize = data1.ah().getDataSize(); + const unsigned dataSize = ah(data1).getDataSize(); // copy header if (len2 == 0) return; @@ -318,4 +322,17 @@ Dbtux::copyAttrs(const Frag& frag, ConstData data1, Data data2, unsigned maxlen2 #endif } +void +Dbtux::unpackBound(const ScanBound& bound, Data dest) +{ + ScanBoundIterator iter; + bound.first(iter); + const unsigned n = bound.getSize(); + unsigned j; + for (j = 0; j < n; j++) { + dest[j] = *iter.data; + bound.next(iter); + } +} + BLOCK_FUNCTIONS(Dbtux) diff --git a/storage/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp b/storage/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp index b329d694f0b..4fc2c2dd968 100644 --- a/storage/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp +++ b/storage/ndb/src/kernel/blocks/dbtux/DbtuxMaint.cpp @@ -111,16 +111,17 @@ Dbtux::execTUX_MAINT_REQ(Signal* signal) // do the operation req->errorCode = 0; TreePos treePos; + bool ok; switch (opCode) { case TuxMaintReq::OpAdd: jam(); - searchToAdd(frag, c_searchKey, ent, treePos); + ok = searchToAdd(frag, c_searchKey, ent, treePos); #ifdef VM_TRACE if (debugFlags & DebugMaint) { - debugOut << treePos << (treePos.m_match ? " - error" : "") << endl; + debugOut << treePos << (! ok ? " - error" : "") << endl; } #endif - if (treePos.m_match) { + if (! ok) { jam(); // there is no "Building" state so this will have to do if (indexPtr.p->m_state == Index::Online) { @@ -150,13 +151,13 @@ Dbtux::execTUX_MAINT_REQ(Signal* signal) break; case TuxMaintReq::OpRemove: jam(); - searchToRemove(frag, c_searchKey, ent, treePos); + ok = searchToRemove(frag, c_searchKey, ent, treePos); #ifdef VM_TRACE if (debugFlags & DebugMaint) { - debugOut << treePos << (! treePos.m_match ? " - error" : "") << endl; + debugOut << treePos << (! ok ? " - error" : "") << endl; } #endif - if (! treePos.m_match) { + if (! ok) { jam(); // there is no "Building" state so this will have to do if (indexPtr.p->m_state == Index::Online) { diff --git a/storage/ndb/src/kernel/blocks/dbtux/DbtuxScan.cpp b/storage/ndb/src/kernel/blocks/dbtux/DbtuxScan.cpp index 55315806635..fab2de5022d 100644 --- a/storage/ndb/src/kernel/blocks/dbtux/DbtuxScan.cpp +++ b/storage/ndb/src/kernel/blocks/dbtux/DbtuxScan.cpp @@ -313,7 +313,7 @@ Dbtux::execNEXT_SCANREQ(Signal* signal) EXECUTE_DIRECT(DBACC, GSN_ACC_LOCKREQ, signal, AccLockReq::UndoSignalLength); jamEntry(); ndbrequire(lockReq->returnCode == AccLockReq::Success); - removeAccLockOp(scan, req->accOperationPtr); + removeAccLockOp(scanPtr, req->accOperationPtr); } if (req->scanFlag == NextScanReq::ZSCAN_COMMIT) { jam(); @@ -424,21 +424,17 @@ Dbtux::execACC_CHECK_SCAN(Signal* signal) jam(); // search is done only once in single range scan scanFirst(scanPtr); -#ifdef VM_TRACE - if (debugFlags & DebugScan) { - debugOut << "First scan " << scanPtr.i << " " << scan << endl; - } -#endif } - if (scan.m_state == ScanOp::Next) { + if (scan.m_state == ScanOp::Current || + scan.m_state == ScanOp::Next) { jam(); // look for next - scanNext(scanPtr, false); + scanFind(scanPtr); } - // for reading tuple key in Current or Locked state + // for reading tuple key in Found or Locked state Data pkData = c_dataBuffer; unsigned pkSize = 0; // indicates not yet done - if (scan.m_state == ScanOp::Current) { + if (scan.m_state == ScanOp::Found) { // found an entry to return jam(); ndbrequire(scan.m_accLockOp == RNIL); @@ -473,7 +469,7 @@ Dbtux::execACC_CHECK_SCAN(Signal* signal) scan.m_state = ScanOp::Locked; scan.m_accLockOp = lockReq->accOpPtr; #ifdef VM_TRACE - if (debugFlags & DebugScan) { + if (debugFlags & (DebugScan | DebugLock)) { debugOut << "Lock immediate scan " << scanPtr.i << " " << scan << endl; } #endif @@ -485,7 +481,7 @@ Dbtux::execACC_CHECK_SCAN(Signal* signal) scan.m_lockwait = true; scan.m_accLockOp = lockReq->accOpPtr; #ifdef VM_TRACE - if (debugFlags & DebugScan) { + if (debugFlags & (DebugScan | DebugLock)) { debugOut << "Lock wait scan " << scanPtr.i << " " << scan << endl; } #endif @@ -512,8 +508,8 @@ Dbtux::execACC_CHECK_SCAN(Signal* signal) jam(); // max ops should depend on max scans (assert only) ndbassert(false); - // stay in Current state - scan.m_state = ScanOp::Current; + // stay in Found state + scan.m_state = ScanOp::Found; signal->theData[0] = scan.m_userPtr; signal->theData[1] = true; EXECUTE_DIRECT(DBLQH, GSN_CHECK_LCP_STOP, signal, 2); @@ -541,7 +537,7 @@ Dbtux::execACC_CHECK_SCAN(Signal* signal) if (accLockOp != RNIL) { scan.m_accLockOp = RNIL; // remember it until LQH unlocks it - addAccLockOp(scan, accLockOp); + addAccLockOp(scanPtr, accLockOp); } else { ndbrequire(scan.m_readCommitted); // operation RNIL in LQH would signal no tuple returned @@ -596,7 +592,7 @@ Dbtux::execACCKEYCONF(Signal* signal) c_scanOpPool.getPtr(scanPtr); ScanOp& scan = *scanPtr.p; #ifdef VM_TRACE - if (debugFlags & DebugScan) { + if (debugFlags & (DebugScan | DebugLock)) { debugOut << "Lock obtained scan " << scanPtr.i << " " << scan << endl; } #endif @@ -641,7 +637,7 @@ Dbtux::execACCKEYREF(Signal* signal) c_scanOpPool.getPtr(scanPtr); ScanOp& scan = *scanPtr.p; #ifdef VM_TRACE - if (debugFlags & DebugScan) { + if (debugFlags & (DebugScan | DebugLock)) { debugOut << "Lock refused scan " << scanPtr.i << " " << scan << endl; } #endif @@ -685,7 +681,7 @@ Dbtux::execACC_ABORTCONF(Signal* signal) c_scanOpPool.getPtr(scanPtr); ScanOp& scan = *scanPtr.p; #ifdef VM_TRACE - if (debugFlags & DebugScan) { + if (debugFlags & (DebugScan | DebugLock)) { debugOut << "ACC_ABORTCONF scan " << scanPtr.i << " " << scan << endl; } #endif @@ -700,44 +696,95 @@ Dbtux::execACC_ABORTCONF(Signal* signal) } /* - * Find start position for single range scan. If it exists, sets state - * to Next and links the scan to the node. The first entry is returned - * by scanNext. + * Find start position for single range scan. */ void Dbtux::scanFirst(ScanOpPtr scanPtr) { ScanOp& scan = *scanPtr.p; Frag& frag = *c_fragPool.getPtr(scan.m_fragPtrI); +#ifdef VM_TRACE + if (debugFlags & DebugScan) { + debugOut << "Enter first scan " << scanPtr.i << " " << scan << endl; + } +#endif TreeHead& tree = frag.m_tree; // set up index keys for this operation setKeyAttrs(frag); // scan direction 0, 1 const unsigned idir = scan.m_descending; - // unpack start key into c_dataBuffer - const ScanBound& bound = *scan.m_bound[idir]; - ScanBoundIterator iter; - bound.first(iter); - for (unsigned j = 0; j < bound.getSize(); j++) { - jam(); - c_dataBuffer[j] = *iter.data; - bound.next(iter); - } + unpackBound(*scan.m_bound[idir], c_dataBuffer); TreePos treePos; searchToScan(frag, c_dataBuffer, scan.m_boundCnt[idir], scan.m_descending, treePos); - if (treePos.m_loc == NullTupLoc) { - // empty result set + if (treePos.m_loc != NullTupLoc) { + scan.m_scanPos = treePos; + // link the scan to node found + NodeHandle node(frag); + selectNode(node, treePos.m_loc); + linkScan(node, scanPtr); + if (treePos.m_dir == 3) { + jam(); + // check upper bound + TreeEnt ent = node.getEnt(treePos.m_pos); + if (scanCheck(scanPtr, ent)) + scan.m_state = ScanOp::Current; + else + scan.m_state = ScanOp::Last; + } else { + scan.m_state = ScanOp::Next; + } + } else { jam(); scan.m_state = ScanOp::Last; - return; } - // set position and state - scan.m_scanPos = treePos; - scan.m_state = ScanOp::Next; - // link the scan to node found - NodeHandle node(frag); - selectNode(node, treePos.m_loc); - linkScan(node, scanPtr); +#ifdef VM_TRACE + if (debugFlags & DebugScan) { + debugOut << "Leave first scan " << scanPtr.i << " " << scan << endl; + } +#endif +} + +/* + * Look for entry to return as scan result. + */ +void +Dbtux::scanFind(ScanOpPtr scanPtr) +{ + ScanOp& scan = *scanPtr.p; + Frag& frag = *c_fragPool.getPtr(scan.m_fragPtrI); +#ifdef VM_TRACE + if (debugFlags & DebugScan) { + debugOut << "Enter find scan " << scanPtr.i << " " << scan << endl; + } +#endif + ndbrequire(scan.m_state == ScanOp::Current || scan.m_state == ScanOp::Next); + while (1) { + jam(); + if (scan.m_state == ScanOp::Next) + scanNext(scanPtr, false); + if (scan.m_state == ScanOp::Current) { + jam(); + const TreePos pos = scan.m_scanPos; + NodeHandle node(frag); + selectNode(node, pos.m_loc); + const TreeEnt ent = node.getEnt(pos.m_pos); + if (scanVisible(scanPtr, ent)) { + jam(); + scan.m_state = ScanOp::Found; + scan.m_scanEnt = ent; + break; + } + } else { + jam(); + break; + } + scan.m_state = ScanOp::Next; + } +#ifdef VM_TRACE + if (debugFlags & DebugScan) { + debugOut << "Leave find scan " << scanPtr.i << " " << scan << endl; + } +#endif } /* @@ -755,6 +802,11 @@ Dbtux::scanFirst(ScanOpPtr scanPtr) * * If an entry was found, scan direction is 3. Therefore tree * re-organizations need not worry about scan direction. + * + * This method is also used to move a scan when its entry is removed + * (see moveScanList). If the scan is Blocked, we check if it remains + * Blocked on a different version of the tuple. Otherwise the tuple is + * lost and state becomes Current. */ void Dbtux::scanNext(ScanOpPtr scanPtr, bool fromMaintReq) @@ -762,8 +814,8 @@ Dbtux::scanNext(ScanOpPtr scanPtr, bool fromMaintReq) ScanOp& scan = *scanPtr.p; Frag& frag = *c_fragPool.getPtr(scan.m_fragPtrI); #ifdef VM_TRACE - if (debugFlags & DebugScan) { - debugOut << "Next in scan " << scanPtr.i << " " << scan << endl; + if (debugFlags & (DebugMaint | DebugScan)) { + debugOut << "Enter next scan " << scanPtr.i << " " << scan << endl; } #endif // cannot be moved away from tuple we have locked @@ -773,15 +825,6 @@ Dbtux::scanNext(ScanOpPtr scanPtr, bool fromMaintReq) // scan direction const unsigned idir = scan.m_descending; // 0, 1 const int jdir = 1 - 2 * (int)idir; // 1, -1 - // unpack end key into c_dataBuffer - const ScanBound& bound = *scan.m_bound[1 - idir]; - ScanBoundIterator iter; - bound.first(iter); - for (unsigned j = 0; j < bound.getSize(); j++) { - jam(); - c_dataBuffer[j] = *iter.data; - bound.next(iter); - } // use copy of position TreePos pos = scan.m_scanPos; // get and remember original node @@ -795,15 +838,14 @@ Dbtux::scanNext(ScanOpPtr scanPtr, bool fromMaintReq) while (true) { jam(); #ifdef VM_TRACE - if (debugFlags & DebugScan) { - debugOut << "Scan next pos " << pos << " " << node << endl; + if (debugFlags & (DebugMaint | DebugScan)) { + debugOut << "Current scan " << scanPtr.i << " pos " << pos << " node " << node << endl; } #endif if (pos.m_dir == 2) { // coming up from root ends the scan jam(); pos.m_loc = NullTupLoc; - scan.m_state = ScanOp::Last; break; } if (node.m_loc != pos.m_loc) { @@ -835,41 +877,22 @@ Dbtux::scanNext(ScanOpPtr scanPtr, bool fromMaintReq) if (pos.m_dir == idir) { // coming up from left child scan current node jam(); - pos.m_pos = idir == 0 ? 0 : occup - 1; - pos.m_match = false; + pos.m_pos = idir == 0 ? (Uint16)-1 : occup; pos.m_dir = 3; } if (pos.m_dir == 3) { - // within node + // before or within node jam(); - // advance position - if (! pos.m_match) - pos.m_match = true; - else - // becomes ZNIL (which is > occup) if 0 and scan descending - pos.m_pos += jdir; + // advance position - becomes ZNIL (> occup) if 0 and descending + pos.m_pos += jdir; if (pos.m_pos < occup) { jam(); - ent = node.getEnt(pos.m_pos); pos.m_dir = 3; // unchanged - // read and compare all attributes - readKeyAttrs(frag, ent, 0, c_entryKey); - int ret = cmpScanBound(frag, 1 - idir, c_dataBuffer, scan.m_boundCnt[1 - idir], c_entryKey); - ndbrequire(ret != NdbSqlUtil::CmpUnknown); - if (jdir * ret < 0) { + ent = node.getEnt(pos.m_pos); + if (! scanCheck(scanPtr, ent)) { jam(); - // hit upper bound of single range scan pos.m_loc = NullTupLoc; - scan.m_state = ScanOp::Last; - break; - } - // can we see it - if (! scanVisible(scanPtr, ent)) { - jam(); - continue; } - // found entry - scan.m_state = ScanOp::Current; break; } // after node proceed to right child @@ -895,31 +918,64 @@ Dbtux::scanNext(ScanOpPtr scanPtr, bool fromMaintReq) // copy back position scan.m_scanPos = pos; // relink - if (scan.m_state == ScanOp::Current) { - ndbrequire(pos.m_match == true && pos.m_dir == 3); + if (pos.m_loc != NullTupLoc) { + ndbrequire(pos.m_dir == 3); ndbrequire(pos.m_loc == node.m_loc); if (origNode.m_loc != node.m_loc) { jam(); unlinkScan(origNode, scanPtr); linkScan(node, scanPtr); } - // copy found entry - scan.m_scanEnt = ent; - } else if (scan.m_state == ScanOp::Last) { + if (scan.m_state != ScanOp::Blocked) { + scan.m_state = ScanOp::Current; + } else { + jam(); + ndbrequire(fromMaintReq); + TreeEnt& scanEnt = scan.m_scanEnt; + ndbrequire(scanEnt.m_tupLoc != NullTupLoc); + if (scanEnt.eqtuple(ent)) { + // remains blocked on another version + scanEnt = ent; + } else { + jam(); + scanEnt.m_tupLoc = NullTupLoc; + scan.m_state = ScanOp::Current; + } + } + } else { jam(); - ndbrequire(pos.m_loc == NullTupLoc); unlinkScan(origNode, scanPtr); - } else { - ndbrequire(false); + scan.m_state = ScanOp::Last; } #ifdef VM_TRACE - if (debugFlags & DebugScan) { - debugOut << "Next out scan " << scanPtr.i << " " << scan << endl; + if (debugFlags & (DebugMaint | DebugScan)) { + debugOut << "Leave next scan " << scanPtr.i << " " << scan << endl; } #endif } /* + * Check end key. Return true if scan is still within range. + */ +bool +Dbtux::scanCheck(ScanOpPtr scanPtr, TreeEnt ent) +{ + ScanOp& scan = *scanPtr.p; + Frag& frag = *c_fragPool.getPtr(scan.m_fragPtrI); + const unsigned idir = scan.m_descending; + const int jdir = 1 - 2 * (int)idir; + unpackBound(*scan.m_bound[1 - idir], c_dataBuffer); + unsigned boundCnt = scan.m_boundCnt[1 - idir]; + readKeyAttrs(frag, ent, 0, c_entryKey); + int ret = cmpScanBound(frag, 1 - idir, c_dataBuffer, boundCnt, c_entryKey); + ndbrequire(ret != NdbSqlUtil::CmpUnknown); + if (jdir * ret > 0) + return true; + // hit upper bound of single range scan + return false; +} + +/* * Check if an entry is visible to the scan. * * There is a special check to never accept same tuple twice in a row. @@ -959,18 +1015,9 @@ Dbtux::scanClose(Signal* signal, ScanOpPtr scanPtr) ScanOp& scan = *scanPtr.p; ndbrequire(! scan.m_lockwait && scan.m_accLockOp == RNIL); // unlock all not unlocked by LQH - for (unsigned i = 0; i < scan.m_maxAccLockOps; i++) { - if (scan.m_accLockOps[i] != RNIL) { - jam(); - AccLockReq* const lockReq = (AccLockReq*)signal->getDataPtrSend(); - lockReq->returnCode = RNIL; - lockReq->requestInfo = AccLockReq::Abort; - lockReq->accOpPtr = scan.m_accLockOps[i]; - EXECUTE_DIRECT(DBACC, GSN_ACC_LOCKREQ, signal, AccLockReq::UndoSignalLength); - jamEntry(); - ndbrequire(lockReq->returnCode == AccLockReq::Success); - scan.m_accLockOps[i] = RNIL; - } + if (! scan.m_accLockOps.isEmpty()) { + jam(); + abortAccLockOps(signal, scanPtr); } // send conf NextScanConf* const conf = (NextScanConf*)signal->getDataPtrSend(); @@ -984,44 +1031,76 @@ Dbtux::scanClose(Signal* signal, ScanOpPtr scanPtr) } void -Dbtux::addAccLockOp(ScanOp& scan, Uint32 accLockOp) +Dbtux::abortAccLockOps(Signal* signal, ScanOpPtr scanPtr) { - ndbrequire(accLockOp != RNIL); - Uint32* list = scan.m_accLockOps; - bool ok = false; - for (unsigned i = 0; i < scan.m_maxAccLockOps; i++) { - ndbrequire(list[i] != accLockOp); - if (! ok && list[i] == RNIL) { - list[i] = accLockOp; - ok = true; - // continue check for duplicates - } + ScanOp& scan = *scanPtr.p; +#ifdef VM_TRACE + if (debugFlags & (DebugScan | DebugLock)) { + debugOut << "Abort locks in scan " << scanPtr.i << " " << scan << endl; } - if (! ok) { - unsigned i = scan.m_maxAccLockOps; - if (i < MaxAccLockOps) { - list[i] = accLockOp; - ok = true; - scan.m_maxAccLockOps = i + 1; - } +#endif + LocalDLFifoList<ScanLock> list(c_scanLockPool, scan.m_accLockOps); + ScanLockPtr lockPtr; + while (list.first(lockPtr)) { + jam(); + AccLockReq* const lockReq = (AccLockReq*)signal->getDataPtrSend(); + lockReq->returnCode = RNIL; + lockReq->requestInfo = AccLockReq::Abort; + lockReq->accOpPtr = lockPtr.p->m_accLockOp; + EXECUTE_DIRECT(DBACC, GSN_ACC_LOCKREQ, signal, AccLockReq::UndoSignalLength); + jamEntry(); + ndbrequire(lockReq->returnCode == AccLockReq::Success); + list.release(lockPtr); } - ndbrequire(ok); } void -Dbtux::removeAccLockOp(ScanOp& scan, Uint32 accLockOp) +Dbtux::addAccLockOp(ScanOpPtr scanPtr, Uint32 accLockOp) { + ScanOp& scan = *scanPtr.p; +#ifdef VM_TRACE + if (debugFlags & (DebugScan | DebugLock)) { + debugOut << "Add lock " << hex << accLockOp << dec + << " to scan " << scanPtr.i << " " << scan << endl; + } +#endif + LocalDLFifoList<ScanLock> list(c_scanLockPool, scan.m_accLockOps); + ScanLockPtr lockPtr; +#ifdef VM_TRACE + list.first(lockPtr); + while (lockPtr.i != RNIL) { + ndbrequire(lockPtr.p->m_accLockOp != accLockOp); + list.next(lockPtr); + } +#endif + bool ok = list.seize(lockPtr); + ndbrequire(ok); ndbrequire(accLockOp != RNIL); - Uint32* list = scan.m_accLockOps; - bool ok = false; - for (unsigned i = 0; i < scan.m_maxAccLockOps; i++) { - if (list[i] == accLockOp) { - list[i] = RNIL; - ok = true; + lockPtr.p->m_accLockOp = accLockOp; +} + +void +Dbtux::removeAccLockOp(ScanOpPtr scanPtr, Uint32 accLockOp) +{ + ScanOp& scan = *scanPtr.p; +#ifdef VM_TRACE + if (debugFlags & (DebugScan | DebugLock)) { + debugOut << "Remove lock " << hex << accLockOp << dec + << " from scan " << scanPtr.i << " " << scan << endl; + } +#endif + LocalDLFifoList<ScanLock> list(c_scanLockPool, scan.m_accLockOps); + ScanLockPtr lockPtr; + list.first(lockPtr); + while (lockPtr.i != RNIL) { + if (lockPtr.p->m_accLockOp == accLockOp) { + jam(); break; } + list.next(lockPtr); } - ndbrequire(ok); + ndbrequire(lockPtr.i != RNIL); + list.release(lockPtr); } /* diff --git a/storage/ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp b/storage/ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp index b0e2a664bfd..4b5c0b791f9 100644 --- a/storage/ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp +++ b/storage/ndb/src/kernel/blocks/dbtux/DbtuxSearch.cpp @@ -21,22 +21,18 @@ * Search for entry to add. * * Similar to searchToRemove (see below). - * - * TODO optimize for initial equal attrs in node min/max */ -void +bool Dbtux::searchToAdd(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& treePos) { const TreeHead& tree = frag.m_tree; const unsigned numAttrs = frag.m_numAttrs; NodeHandle currNode(frag); currNode.m_loc = tree.m_root; - // assume success - treePos.m_match = false; if (currNode.m_loc == NullTupLoc) { // empty tree jam(); - return; + return true; } NodeHandle glbNode(frag); // potential g.l.b of final node /* @@ -94,9 +90,8 @@ Dbtux::searchToAdd(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& jam(); treePos.m_loc = currNode.m_loc; treePos.m_pos = 0; - // failed - treePos.m_match = true; - return; + // entry found - error + return false; } break; } @@ -104,7 +99,7 @@ Dbtux::searchToAdd(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& treePos.m_loc = currNode.m_loc; // binary search int lo = -1; - unsigned hi = currNode.getOccup(); + int hi = currNode.getOccup(); int ret; while (1) { jam(); @@ -126,9 +121,8 @@ Dbtux::searchToAdd(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& lo = j; else { treePos.m_pos = j; - // failed - treePos.m_match = true; - return; + // entry found - error + return false; } if (hi - lo == 1) break; @@ -136,22 +130,23 @@ Dbtux::searchToAdd(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& if (ret < 0) { jam(); treePos.m_pos = hi; - return; + return true; } if (hi < currNode.getOccup()) { jam(); treePos.m_pos = hi; - return; + return true; } if (bottomNode.isNull()) { jam(); treePos.m_pos = hi; - return; + return true; } jam(); // backwards compatible for now treePos.m_loc = bottomNode.m_loc; treePos.m_pos = 0; + return true; } /* @@ -163,21 +158,17 @@ Dbtux::searchToAdd(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& * then the saved node is the g.l.b of the final node and we move back * to it. */ -void +bool Dbtux::searchToRemove(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePos& treePos) { const TreeHead& tree = frag.m_tree; const unsigned numAttrs = frag.m_numAttrs; NodeHandle currNode(frag); currNode.m_loc = tree.m_root; - // assume success - treePos.m_match = true; if (currNode.m_loc == NullTupLoc) { - // empty tree + // empty tree - failed jam(); - // failed - treePos.m_match = false; - return; + return false; } NodeHandle glbNode(frag); // potential g.l.b of final node while (true) { @@ -229,7 +220,7 @@ Dbtux::searchToRemove(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePo jam(); treePos.m_loc = currNode.m_loc; treePos.m_pos = 0; - return; + return true; } break; } @@ -242,12 +233,12 @@ Dbtux::searchToRemove(Frag& frag, ConstData searchKey, TreeEnt searchEnt, TreePo if (searchEnt.eq(currNode.getEnt(j))) { jam(); treePos.m_pos = j; - return; + return true; } } treePos.m_pos = currNode.getOccup(); - // failed - treePos.m_match = false; + // not found - failed + return false; } /* @@ -278,8 +269,6 @@ Dbtux::searchToScanAscending(Frag& frag, ConstData boundInfo, unsigned boundCoun currNode.m_loc = tree.m_root; NodeHandle glbNode(frag); // potential g.l.b of final node NodeHandle bottomNode(frag); - // always before entry - treePos.m_match = false; while (true) { jam(); selectNode(currNode, currNode.m_loc); @@ -315,7 +304,7 @@ Dbtux::searchToScanAscending(Frag& frag, ConstData boundInfo, unsigned boundCoun treePos.m_dir = 3; return; } - } else if (ret > 0) { + } else { // bound is at or right of this node jam(); const TupLoc loc = currNode.getLink(1); @@ -327,8 +316,6 @@ Dbtux::searchToScanAscending(Frag& frag, ConstData boundInfo, unsigned boundCoun currNode.m_loc = loc; continue; } - } else { - ndbrequire(false); } break; } @@ -369,8 +356,6 @@ Dbtux::searchToScanDescending(Frag& frag, ConstData boundInfo, unsigned boundCou currNode.m_loc = tree.m_root; NodeHandle glbNode(frag); // potential g.l.b of final node NodeHandle bottomNode(frag); - // always before entry - treePos.m_match = false; while (true) { jam(); selectNode(currNode, currNode.m_loc); @@ -403,7 +388,7 @@ Dbtux::searchToScanDescending(Frag& frag, ConstData boundInfo, unsigned boundCou // empty result set return; } - } else if (ret > 0) { + } else { // bound is at or right of this node jam(); const TupLoc loc = currNode.getLink(1); @@ -415,8 +400,6 @@ Dbtux::searchToScanDescending(Frag& frag, ConstData boundInfo, unsigned boundCou currNode.m_loc = loc; continue; } - } else { - ndbrequire(false); } break; } diff --git a/storage/ndb/src/kernel/blocks/restore.cpp b/storage/ndb/src/kernel/blocks/restore.cpp index d6e95537699..b80bc88ec5b 100644 --- a/storage/ndb/src/kernel/blocks/restore.cpp +++ b/storage/ndb/src/kernel/blocks/restore.cpp @@ -173,7 +173,12 @@ Restore::execREAD_CONFIG_REQ(Signal* signal) } #endif m_file_pool.setSize(1); - m_databuffer_pool.setSize((1*128+PAGES+List::getSegmentSize()-1)/List::getSegmentSize()); + Uint32 cnt = 2*MAX_ATTRIBUTES_IN_TABLE; + cnt += PAGES; + cnt += List::getSegmentSize()-1; + cnt /= List::getSegmentSize(); + cnt += 2; + m_databuffer_pool.setSize(cnt); ReadConfigConf * conf = (ReadConfigConf*)signal->getDataPtrSend(); conf->senderRef = reference(); @@ -242,7 +247,7 @@ Restore::execRESTORE_LCP_REQ(Signal* signal){ break; } - open_file(signal, file_ptr, req->lcpNo); + open_file(signal, file_ptr); return; } while(0); @@ -265,6 +270,7 @@ Restore::init_file(const RestoreLcpReq* req, FilePtr file_ptr) file_ptr.p->m_file_type = BackupFormat::LCP_FILE; file_ptr.p->m_status = File::FIRST_READ; + file_ptr.p->m_lcp_no = req->lcpNo; file_ptr.p->m_table_id = req->tableId; file_ptr.p->m_fragment_id = req->fragmentId; file_ptr.p->m_table_version = RNIL; @@ -352,7 +358,7 @@ Restore::release_file(FilePtr file_ptr) } void -Restore::open_file(Signal* signal, FilePtr file_ptr, Uint32 lcpNo) +Restore::open_file(Signal* signal, FilePtr file_ptr) { FsOpenReq * req = (FsOpenReq *)signal->getDataPtrSend(); req->userReference = reference(); @@ -361,7 +367,7 @@ Restore::open_file(Signal* signal, FilePtr file_ptr, Uint32 lcpNo) FsOpenReq::setVersion(req->fileNumber, 5); FsOpenReq::setSuffix(req->fileNumber, FsOpenReq::S_DATA); - FsOpenReq::v5_setLcpNo(req->fileNumber, lcpNo); + FsOpenReq::v5_setLcpNo(req->fileNumber, file_ptr.p->m_lcp_no); FsOpenReq::v5_setTableId(req->fileNumber, file_ptr.p->m_table_id); FsOpenReq::v5_setFragmentId(req->fileNumber, file_ptr.p->m_fragment_id); sendSignal(NDBFS_REF, GSN_FSOPENREQ, signal, FsOpenReq::SignalLength, JBA); @@ -1216,6 +1222,17 @@ void Restore::parse_error(Signal* signal, FilePtr file_ptr, Uint32 line, Uint32 extra) { + char buf[255], name[100]; + BaseString::snprintf(name, sizeof(name), "%u/T%dF%d", + file_ptr.p->m_lcp_no, + file_ptr.p->m_table_id, + file_ptr.p->m_fragment_id); + + BaseString::snprintf(buf, sizeof(buf), + "Parse error in file: %s, extra: %d", + name, extra); + + progError(line, NDBD_EXIT_INVALID_LCP_FILE, buf); ndbrequire(false); } diff --git a/storage/ndb/src/kernel/blocks/restore.hpp b/storage/ndb/src/kernel/blocks/restore.hpp index 609040e0280..d2d1bcfb775 100644 --- a/storage/ndb/src/kernel/blocks/restore.hpp +++ b/storage/ndb/src/kernel/blocks/restore.hpp @@ -116,6 +116,7 @@ private: Uint32 nextList; Uint32 prevList; Uint32 nextPool; + Uint32 m_lcp_no; bool is_lcp() const { return m_file_type == BackupFormat::LCP_FILE;} }; @@ -124,7 +125,7 @@ private: Uint32 init_file(const struct RestoreLcpReq*, FilePtr); void release_file(FilePtr); - void open_file(Signal*, FilePtr, Uint32 lcpNo); + void open_file(Signal*, FilePtr); void read_file(Signal*, FilePtr); void restore_next(Signal*, FilePtr); void parse_file_header(Signal*, FilePtr, const Uint32*, Uint32 len); diff --git a/storage/ndb/src/kernel/error/ndbd_exit_codes.c b/storage/ndb/src/kernel/error/ndbd_exit_codes.c index bf1d143e436..8ed3b3a5cbb 100644 --- a/storage/ndb/src/kernel/error/ndbd_exit_codes.c +++ b/storage/ndb/src/kernel/error/ndbd_exit_codes.c @@ -158,7 +158,9 @@ static const ErrStruct errArray[] = "System reports no more file system resources"}, {NDBD_EXIT_AFS_NO_SUCH_FILE , XFI, "File not found"}, {NDBD_EXIT_AFS_READ_UNDERFLOW , XFI, "Read underflow"}, - + + {NDBD_EXIT_INVALID_LCP_FILE, XFI, "Invalid LCP" }, + /* Sentinel */ {0, XUE, "No message slogan found (please report a bug if you get this error code)"} diff --git a/storage/ndb/src/kernel/vm/Pool.hpp b/storage/ndb/src/kernel/vm/Pool.hpp index 70fcdf8b56a..fe3a50e127b 100644 --- a/storage/ndb/src/kernel/vm/Pool.hpp +++ b/storage/ndb/src/kernel/vm/Pool.hpp @@ -305,7 +305,11 @@ inline bool RecordPool<T, P>::seize(Ptr<T> & ptr) { - return m_pool.seize(*(Ptr<void>*)&ptr); + Ptr<void> tmp; + bool ret = m_pool.seize(tmp); + ptr.i = tmp.i; + ptr.p = static_cast<T*>(tmp.p); + return ret; } template <typename T, typename P> diff --git a/storage/ndb/src/mgmsrv/Services.cpp b/storage/ndb/src/mgmsrv/Services.cpp index 4a84095aa9f..80dd040eb1b 100644 --- a/storage/ndb/src/mgmsrv/Services.cpp +++ b/storage/ndb/src/mgmsrv/Services.cpp @@ -1368,14 +1368,8 @@ Ndb_mgmd_event_service::log(int eventType, const Uint32* theData, NodeId nodeId) if (ndb_logevent_body[i].index_fn) val= (*(ndb_logevent_body[i].index_fn))(val); str.appfmt("%s=%d\n",ndb_logevent_body[i].token, val); - if(strcmp(ndb_logevent_body[i].token,"error") == 0) - { - int m_text_len= strlen(m_text); - snprintf(m_text+m_text_len, 4 , " - "); - ndb_error_string(theData[3], m_text+(m_text_len+3), sizeof(m_text)-m_text_len-3); - } } - + Vector<NDB_SOCKET_TYPE> copy; m_clients.lock(); for(i = m_clients.size() - 1; i >= 0; i--) diff --git a/storage/ndb/src/ndbapi/NdbScanOperation.cpp b/storage/ndb/src/ndbapi/NdbScanOperation.cpp index 4c39d4ee342..2d47f79ee09 100644 --- a/storage/ndb/src/ndbapi/NdbScanOperation.cpp +++ b/storage/ndb/src/ndbapi/NdbScanOperation.cpp @@ -701,7 +701,7 @@ void NdbScanOperation::close(bool forceSend, bool releaseOp) theNdbCon = NULL; m_transConnection = NULL; - if (tTransCon) + if (tTransCon && releaseOp) { NdbIndexScanOperation* tOp = (NdbIndexScanOperation*)this; @@ -716,7 +716,7 @@ void NdbScanOperation::close(bool forceSend, bool releaseOp) &tTransCon->m_theLastScanOperation, tOp); } - else if (releaseOp) + else { ret = tTransCon->releaseScanOperation(&tTransCon->m_firstExecutedScanOp, 0, tOp); diff --git a/storage/ndb/src/ndbapi/NdbTransaction.cpp b/storage/ndb/src/ndbapi/NdbTransaction.cpp index dad866ff453..0cbd67a38f6 100644 --- a/storage/ndb/src/ndbapi/NdbTransaction.cpp +++ b/storage/ndb/src/ndbapi/NdbTransaction.cpp @@ -360,8 +360,37 @@ NdbTransaction::execute(ExecType aTypeOfExec, ret = -1; if(savedError.code==0) savedError= theError; + + /** + * If AO_IgnoreError, error codes arent always set on individual + * operations, making postExecute impossible + */ + if (abortOption == AO_IgnoreError) + { + if (theCompletedFirstOp != NULL) + { + if (tCompletedFirstOp != NULL) + { + tCompletedLastOp->next(theCompletedFirstOp); + theCompletedFirstOp = tCompletedFirstOp; + } + } + else + { + theCompletedFirstOp = tCompletedFirstOp; + theCompletedLastOp = tCompletedLastOp; + } + if (tPrepOp != NULL && tRestOp != NULL) { + if (theFirstOpInList == NULL) + theFirstOpInList = tRestOp; + else + theLastOpInList->next(tRestOp); + theLastOpInList = tLastOp; + } + DBUG_RETURN(-1); + } } - + #ifdef ndb_api_crash_on_complex_blob_abort assert(theFirstOpInList == NULL && theLastOpInList == NULL); #else @@ -1761,8 +1790,10 @@ from other transactions. if (tCommitFlag == 1) { theCommitStatus = Committed; theGlobalCheckpointId = tGCI; - assert(tGCI); - *p_latest_trans_gci = tGCI; + if (tGCI) // Read(dirty) only transaction doesnt get GCI + { + *p_latest_trans_gci = tGCI; + } } else if ((tNoComp >= tNoSent) && (theLastExecOpInList->theCommitIndicator == 1)){ diff --git a/storage/ndb/test/include/NDBT_Test.hpp b/storage/ndb/test/include/NDBT_Test.hpp index a22aa6e53bf..8c3c22192fc 100644 --- a/storage/ndb/test/include/NDBT_Test.hpp +++ b/storage/ndb/test/include/NDBT_Test.hpp @@ -364,6 +364,9 @@ public: // Table create tweaks int createHook(Ndb*, NdbDictionary::Table&, int when); Vector<BaseString> m_tables_in_test; + + void setTemporaryTables(bool val); + bool getTemporaryTables() const; private: int executeOne(Ndb_cluster_connection&, const char* _tabname, const char* testname = NULL); @@ -390,6 +393,7 @@ private: bool runonce; const char* tsname; bool createAllTables; + bool temporaryTables; }; diff --git a/storage/ndb/test/ndbapi/Makefile.am b/storage/ndb/test/ndbapi/Makefile.am index 9eea2639147..0f37cfa95d1 100644 --- a/storage/ndb/test/ndbapi/Makefile.am +++ b/storage/ndb/test/ndbapi/Makefile.am @@ -36,7 +36,8 @@ testPartitioning \ testBitfield \ DbCreate DbAsyncGenerator \ testSRBank \ -test_event_merge +test_event_merge \ +testIndexStat EXTRA_PROGRAMS = \ test_event \ @@ -87,6 +88,7 @@ DbAsyncGenerator_SOURCES = bench/mainAsyncGenerator.cpp bench/asyncGenerator.cpp testSRBank_SOURCES = testSRBank.cpp test_event_merge_SOURCES = test_event_merge.cpp test_event_multi_table_SOURCES = test_event_multi_table.cpp +testIndexStat_SOURCES = testIndexStat.cpp INCLUDES_LOC = -I$(top_srcdir)/storage/ndb/include/kernel @@ -168,3 +170,4 @@ testScan.dsp: Makefile \ @$(top_srcdir)/storage/ndb/config/win-sources $@ $(testScan_SOURCES) @$(top_srcdir)/storage/ndb/config/win-libraries $@ LINK $(LDADD) + diff --git a/storage/ndb/test/ndbapi/testIndexStat.cpp b/storage/ndb/test/ndbapi/testIndexStat.cpp new file mode 100644 index 00000000000..18524d0ac10 --- /dev/null +++ b/storage/ndb/test/ndbapi/testIndexStat.cpp @@ -0,0 +1,1406 @@ +/* Copyright (C) 2005 MySQL AB + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include <ndb_global.h> +#include <ndb_opts.h> +#include <NdbApi.hpp> +#include <NdbIndexStat.hpp> +#include <NdbTest.hpp> +#include <my_sys.h> +#include <ndb_version.h> +#include <math.h> + +/* + * Sample results: + * + * 0. err pct: count: 1000 min: -99.99 max: 99.92 avg: 6.88 stddev: 27.61 + * + * 0. baseline with same options as handler + */ + +#undef min +#undef max +#define min(a, b) ((a) <= (b) ? (a) : (b)) +#define max(a, b) ((a) >= (b) ? (a) : (b)) + +inline NdbOut& +NdbOut::operator<<(double x) +{ + char buf[100]; + sprintf(buf, "%.2f", x); + *this << buf; + return *this; +} + +struct Opts { + int loglevel; + uint seed; + uint loop; + uint rows; + uint ops; + uint nullkeys; + uint dupkeys; + uint scanpct; + uint eqscans; + uint dupscans; + my_bool keeptable; + my_bool loaddata; + my_bool nochecks; + my_bool abort; + // internal + uint tryhard; + Opts() : + loglevel(0), + seed(-1), + loop(1), + rows(100000), + ops(1000), + nullkeys(10), + dupkeys(1000), + scanpct(5), + eqscans(50), + dupscans(10), + keeptable(false), + loaddata(true), + nochecks(false), + abort(false), + // internal + tryhard(20) + {} +}; + +static Opts g_opts; +const char* g_progname = "testIndexStat"; +static uint g_loop = 0; + +static const char* g_tabname = "ts0"; +static const char* g_indname = "ts0x1"; +static const char g_numattrs = 3; +static const uint g_charlen = 10; +static const char* g_csname = "latin1_swedish_ci"; +static CHARSET_INFO* g_cs; + +// value and bound ranges +static uint g_val_b_max = 10; +static uint g_bnd_b_max = 20; +static const char* g_val_c_char = "bcd"; +static const char* g_bnd_c_char = "abcde"; +static uint g_val_d_max = 100; +static uint g_bnd_d_max = 200; + +static Ndb_cluster_connection* g_ncc = 0; +static Ndb* g_ndb = 0; +static NdbDictionary::Dictionary* g_dic = 0; +static const NdbDictionary::Table* g_tab = 0; +static const NdbDictionary::Index* g_ind = 0; + +static NdbIndexStat* g_stat = 0; + +static NdbTransaction* g_con = 0; +static NdbOperation* g_op = 0; +static NdbScanOperation* g_scan_op = 0; +static NdbIndexScanOperation* g_rangescan_op = 0; + +static uint +urandom() +{ + uint r = (uint)random(); + return r; +} + +static uint +urandom(uint m) +{ + if (m == 0) + return 0; + uint r = urandom(); + r = r % m; + return r; +} + +static int& g_loglevel = g_opts.loglevel; // default log level + +#define chkdb(x) \ + do { if (likely(x)) break; ndbout << "line " << __LINE__ << " FAIL " << #x << endl; errdb(); if (g_opts.abort) abort(); return -1; } while (0) + +#define chkrc(x) \ + do { if (likely(x)) break; ndbout << "line " << __LINE__ << " FAIL " << #x << endl; if (g_opts.abort) abort(); return -1; } while (0) + +#define reqrc(x) \ + do { if (likely(x)) break; ndbout << "line " << __LINE__ << " ASSERT " << #x << endl; abort(); } while (0) + +#define llx(n, x) \ + do { if (likely(g_loglevel < n)) break; ndbout << x << endl; } while (0) + +#define ll0(x) llx(0, x) +#define ll1(x) llx(1, x) +#define ll2(x) llx(2, x) +#define ll3(x) llx(3, x) + +static void +errdb() +{ + uint any = 0; + // g_ncc return no error... + if (g_ndb != 0) { + const NdbError& e = g_ndb->getNdbError(); + if (e.code != 0) + ll0(++any << " ndb: error " << e); + } + if (g_dic != 0) { + const NdbError& e = g_dic->getNdbError(); + if (e.code != 0) + ll0(++any << " dic: error " << e); + } + if (g_con != 0) { + const NdbError& e = g_con->getNdbError(); + if (e.code != 0) + ll0(++any << " con: error " << e); + } + if (g_op != 0) { + const NdbError& e = g_op->getNdbError(); + if (e.code != 0) + ll0(++any << " op: error " << e); + } + if (g_scan_op != 0) { + const NdbError& e = g_scan_op->getNdbError(); + if (e.code != 0) + ll0(++any << " scan_op: error " << e); + } + if (g_rangescan_op != 0) { + const NdbError& e = g_rangescan_op->getNdbError(); + if (e.code != 0) + ll0(++any << " rangescan_op: error " << e); + } + if (g_stat != 0) { + const NdbError& e = g_stat->getNdbError(); + if (e.code != 0) + ll0(++any << " stat: error " << e); + } + if (! any) + ll0("unknown db error"); +} + +// create table ts0 ( +// a int unsigned, b smallint not null, c varchar(10), d int unsigned, +// primary key using hash (a), index (b, c, d) ) + +static int +createtable() +{ + NdbDictionary::Table tab(g_tabname); + tab.setLogging(false); + { + NdbDictionary::Column col("a"); + col.setType(NdbDictionary::Column::Unsigned); + col.setPrimaryKey(true); + tab.addColumn(col); + } + { + NdbDictionary::Column col("b"); + col.setType(NdbDictionary::Column::Smallint); + col.setNullable(false); + tab.addColumn(col); + } + { + NdbDictionary::Column col("c"); + col.setType(NdbDictionary::Column::Varchar); + col.setLength(g_charlen); + col.setCharset(g_cs); + col.setNullable(true); + tab.addColumn(col); + } + { + NdbDictionary::Column col("d"); + col.setType(NdbDictionary::Column::Unsigned); + col.setNullable(true); + tab.addColumn(col); + } + NdbDictionary::Index ind(g_indname); + ind.setTable(g_tabname); + ind.setType(NdbDictionary::Index::OrderedIndex); + ind.setLogging(false); + ind.addColumnName("b"); + ind.addColumnName("c"); + ind.addColumnName("d"); + g_dic = g_ndb->getDictionary(); + if (! g_opts.keeptable) { + if (g_dic->getTable(g_tabname) != 0) + chkdb(g_dic->dropTable(g_tabname) == 0); + chkdb(g_dic->createTable(tab) == 0); + chkdb(g_dic->createIndex(ind) == 0); + } else { + if (g_dic->getTable(g_tabname) == 0) { + chkdb(g_dic->createTable(tab) == 0); + chkdb(g_dic->createIndex(ind) == 0); + } else + g_opts.loaddata = false; + } + chkdb((g_tab = g_dic->getTable(g_tabname)) != 0); + chkdb((g_ind = g_dic->getIndex(g_indname, g_tabname)) != 0); + g_dic = 0; + return 0; +} + +static int +droptable() +{ + g_dic = g_ndb->getDictionary(); + if (! g_opts.keeptable) + chkdb(g_dic->dropTable(g_tabname) == 0); + g_dic = 0; + return 0; +} + +struct Val { + Int16 b; + bool c_null; + uchar c[1 + g_charlen]; + bool d_null; + Uint32 d; + // partial values for use in Bnd + uint numattrs; + void make(uint n = g_numattrs, bool is_val = true); + int cmp(const Val& val, uint n = g_numattrs) const; +}; + +static NdbOut& +operator<<(NdbOut& out, const Val& val) +{ + out << "["; + if (val.numattrs >= 1) { + out << val.b; + } + if (val.numattrs >= 2) { + out << " "; + if (val.c_null) + out << "NULL"; + else { + char buf[1 + g_charlen]; + sprintf(buf, "%.*s", val.c[0], &val.c[1]); + out << "'" << buf << "'"; + } + } + if (val.numattrs >= 3) { + out << " "; + if (val.d_null) + out <<" NULL"; + else + out << val.d; + } + out << "]"; + return out; +} + +void +Val::make(uint n, bool is_val) +{ + if (n >= 1) { + uint b_max = is_val ? g_val_b_max : g_bnd_b_max; + b = (int)urandom(2 * b_max) - (int)b_max; + } + if (n >= 2) { + if (urandom(100) < g_opts.nullkeys) + c_null = 1; + else { + const char* c_char = is_val ? g_val_c_char : g_bnd_c_char; + // prefer shorter + uint len = urandom(urandom(g_charlen + 2)); + c[0] = len; + uint j; + for (j = 0; j < len; j++) { + uint k = urandom(strlen(c_char)); + c[1 + j] = c_char[k]; + } + c_null = 0; + } + } + if (n >= 3) { + if (urandom(100) < g_opts.nullkeys) + d_null = 1; + else { + uint d_max = is_val ? g_val_d_max : g_bnd_d_max; + d = urandom(d_max); + d_null = 0; + } + } + numattrs = n; +} + +int +Val::cmp(const Val& val, uint n) const +{ + int k = 0; + if (k == 0 && n >= 1) { + if (b < val.b) + k = -1; + else if (b > val.b) + k = +1; + } + if (k == 0 && n >= 2) { + if (! c_null && ! val.c_null) { + const uchar* s1 = &c[1]; + const uchar* s2 = &val.c[1]; + const uint l1 = (uint)c[0]; + const uint l2 = (uint)val.c[0]; + assert(l1 <= g_charlen && l2 <= g_charlen); + k = g_cs->coll->strnncollsp(g_cs, s1, l1, s2, l2, 0); + } else if (! c_null) { + k = +1; + } else if (! val.c_null) { + k = -1; + } + } + if (k == 0 && n >= 3) { + if (! d_null && ! val.d_null) { + if (d < val.d) + k = -1; + else if (d > val.d) + k = +1; + } else if (! d_null) { + k = +1; + } else if (! val.d_null) { + k = -1; + } + } + return k; +} + +struct Key { + Val val; + union { + bool flag; + uint count; + uint rpk; + }; +}; + +static NdbOut& +operator<<(NdbOut& out, const Key& key) +{ + out << key.val << " info:" << key.count; + return out; +} + +static Key* g_keys = 0; +static Key* g_sortkeys = 0; +static uint g_sortcount = 0; +static Key* g_minkey = 0; +static Key* g_maxkey = 0; + +static void +freekeys() +{ + if (g_keys != 0) + my_free((char*)g_keys, MYF(0)); + if (g_sortkeys != 0) + my_free((char*)g_sortkeys, MYF(0)); + g_keys = 0; + g_sortkeys = 0; +} + +static int +allockeys() +{ + freekeys(); + size_t sz = sizeof(Key) * g_opts.rows; + g_keys = (Key*)my_malloc(sz, MYF(0)); + g_sortkeys = (Key*)my_malloc(sz, MYF(0)); + chkrc(g_keys != 0 && g_sortkeys != 0); + memset(g_keys, 0x1f, sz); + memset(g_sortkeys, 0x1f, sz); + return 0; +} + +static void +makekeys() +{ + uint i; + for (i = 0; i < g_opts.rows; i++) { + Key& key = g_keys[i]; + key.val.make(); + key.flag = false; // mark for dup generation done + } + for (i = 0; i < g_opts.rows; i++) { + Key& key = g_keys[i]; + if (key.flag) + continue; + key.flag = true; + uint fudge = 9; + uint n = (urandom(fudge * (g_opts.dupkeys - 100)) + 99) / 100; + uint k; + for (k = 1; k < n; k++) { + uint j = urandom(g_opts.rows); + do { + Key& dst = g_keys[j]; + if (! dst.flag) { + dst.val = key.val; + dst.flag = true; + break; + } + } while (urandom(g_opts.tryhard) != 0); + } + } +} + +static int +insertdata() +{ + const uint batch = 512; + chkdb((g_con = g_ndb->startTransaction()) != 0); + uint i = 0; + while (i < g_opts.rows) { + chkdb((g_op = g_con->getNdbOperation(g_tab)) != 0); + chkdb(g_op->insertTuple() == 0); + Uint32 a = i; + const Val& val = g_keys[i].val; + const char* a_addr = (const char*)&a; + const char* b_addr = (const char*)&val.b; + const char* c_addr = ! val.c_null ? (const char*)val.c : 0; + const char* d_addr = ! val.d_null ? (const char*)&val.d : 0; + Uint32 no = 0; + chkdb(g_op->equal(no++, a_addr) == 0); + chkdb(g_op->setValue(no++, b_addr) == 0); + chkdb(g_op->setValue(no++, c_addr) == 0); + chkdb(g_op->setValue(no++, d_addr) == 0); + if (i++ % batch == 0) { + chkdb(g_con->execute(NdbTransaction::Commit) == 0); + g_ndb->closeTransaction(g_con); + g_con = 0; + g_op = 0; + chkdb((g_con = g_ndb->startTransaction()) != 0); + } + } + chkdb(g_con->execute(NdbTransaction::Commit) == 0); + g_ndb->closeTransaction(g_con); + g_con = 0; + g_op = 0; + ll0(g_tabname << ": inserted " << g_opts.rows << " rows"); + return 0; +} + +static int +countrows() +{ + Uint64 rows = 0; + Uint64 r; + char* r_addr = (char*)&r; + chkdb((g_con = g_ndb->startTransaction()) != 0); + chkdb((g_scan_op = g_con->getNdbScanOperation(g_tab)) != 0); + chkdb(g_scan_op->readTuples() == 0); + chkdb(g_scan_op->interpret_exit_last_row() == 0); + chkdb(g_scan_op->getValue(NdbDictionary::Column::ROW_COUNT, r_addr) != 0); + chkdb(g_con->execute(NdbTransaction::NoCommit) == 0); + while (1) { + int ret; + r = ~(Uint64)0; + chkdb((ret = g_scan_op->nextResult()) == 0 || ret == 1); + if (ret == 1) + break; + rows += r; + } + g_ndb->closeTransaction(g_con); + g_con = 0; + g_scan_op = 0; + g_opts.rows = rows; + return 0; +} + +static int +scandata() +{ + chkdb((g_con = g_ndb->startTransaction()) != 0); + chkdb((g_scan_op = g_con->getNdbScanOperation(g_tab)) != 0); + chkdb(g_scan_op->readTuples() == 0); + Uint32 a; + Val val; + char* a_addr = (char*)&a; + char* b_addr = (char*)&val.b; + char* c_addr = (char*)val.c; + char* d_addr = (char*)&val.d; + Uint32 no = 0; + NdbRecAttr* b_ra; + NdbRecAttr* c_ra; + NdbRecAttr* d_ra; + chkdb(g_scan_op->getValue(no++, a_addr) != 0); + chkdb((b_ra = g_scan_op->getValue(no++, b_addr)) != 0); + chkdb((c_ra = g_scan_op->getValue(no++, c_addr)) != 0); + chkdb((d_ra = g_scan_op->getValue(no++, d_addr)) != 0); + chkdb(g_con->execute(NdbTransaction::NoCommit) == 0); + uint count = 0; + uint i; + for (i = 0; i < g_opts.rows; i++) + g_keys[i].count = 0; + while (1) { + int ret; + a = ~(Uint32)0; + chkdb((ret = g_scan_op->nextResult()) == 0 || ret == 1); + if (ret == 1) + break; + assert(b_ra->isNULL() == 0 && c_ra->isNULL() != -1 && d_ra->isNULL() != -1); + val.c_null = c_ra->isNULL(); + val.d_null = d_ra->isNULL(); + i = (uint)a; + chkrc(i < g_opts.rows); + Key& key = g_keys[i]; + if (g_opts.loaddata) + chkrc(key.val.cmp(val) == 0); + else + key.val = val; + key.count++; + count++; + } + g_ndb->closeTransaction(g_con); + g_con = 0; + g_scan_op = 0; + for (i = 0; i < g_opts.rows; i++) + chkrc(g_keys[i].count == 1); + assert(count == g_opts.rows); + int level = g_opts.loaddata ? 1 : 0; + llx(level, g_tabname << ": scanned " << g_opts.rows << " rows"); + return 0; +} + +static int +loaddata() +{ + if (g_opts.loaddata) { + chkrc(allockeys() == 0); + makekeys(); + chkrc(insertdata() == 0); + } else { + chkrc(countrows() == 0); + chkrc(g_opts.rows != 0); + ll0(g_tabname << ": using old table of " << g_opts.rows << " rows"); + chkrc(allockeys() == 0); + } + chkrc(scandata() == 0); + uint i; + for (i = 0; i < g_opts.rows; i++) + ll3(i << ": " << g_keys[i]); + return 0; +} + +// true = match, index = match or next higher +static bool +sortval(const Val& val, int& index) +{ + if (unlikely(g_sortcount == 0)) { + index = 0; + return false; + } + int lo = -1; + int hi = (int)g_sortcount; + int ret; + int j; + do { + j = (hi + lo) / 2; + ret = val.cmp(g_sortkeys[j].val); + if (ret < 0) + hi = j; + else if (ret > 0) + lo = j; + else + break; + } while (hi - lo > 1); + if (ret == 0) { + index = j; + return true; + } + index = hi; + return false; +} + +static void +sortkeys() +{ + // insert sort with binary search + g_sortcount = 0; + uint i; + for (i = 0; i < g_opts.rows; i++) { + const Val& val = g_keys[i].val; + int index; + bool match = sortval(val, index); + Key& dst = g_sortkeys[index]; + if (match) { + dst.rpk++; + } else { + uint bytes = ((int)g_sortcount - index) * sizeof(Key); + memmove(&dst + 1, &dst, bytes); + dst.val = val; + dst.rpk = 1; + g_sortcount++; + } + } + g_minkey = &g_sortkeys[0]; + g_maxkey = &g_sortkeys[g_sortcount - 1]; + ll1("counted " << g_sortcount << " distinct keys"); +} + +struct Bnd { + Val val; + /* + * A bound is a partial key value (0 to g_numattrs attributes). + * It is not equal to any key value. Instead, it has a "side". + * + * side = 0 if the bound is empty + * side = -1 if the bound is "just before" its value + * side = +1 if the bound is "just after" its value + * + * This is another way of looking at strictness of non-empty + * start and end keys in a range. + * + * start key is strict if side = +1 + * end key is strict if side = -1 + * + * NDB API specifies strictness in the bound type of the last + * index attribute which is part of the start/end key. + * + * LE (0) - strict: n - side: -1 + * LT (1) - strict: y - side: +1 + * GE (2) - strict: n - side: +1 + * GT (3) - strict: y - side: -1 + * + * A non-empty bound divides keys into 2 disjoint subsets: + * keys before (cmp() == -1) and keys after (cmp() == +1). + */ + int side; + Bnd& make(uint minattrs); + Bnd& make(uint minattrs, const Val& theval); + int cmp(const Val& val) const; + int type(uint lohi, uint colno) const; // for setBound +}; + +static NdbOut& +operator<<(NdbOut& out, const Bnd& bnd) +{ + out << bnd.val; + out << " side: " << bnd.side; + return out; +} + +Bnd& +Bnd::make(uint minattrs) +{ + uint numattrs = minattrs + urandom(g_numattrs - minattrs); + val.make(numattrs, false); + side = val.numattrs == 0 ? 0 : urandom(2) == 0 ? -1 : +1; + return *this; +} + +Bnd& +Bnd::make(uint minattrs, const Val& theval) +{ + uint numattrs = minattrs + urandom(g_numattrs - minattrs); + val = theval; + val.numattrs = numattrs; + side = val.numattrs == 0 ? 0 : urandom(2) == 0 ? -1 : +1; + return *this; +} + +int +Bnd::cmp(const Val& theval) const +{ + int place; // debug + int ret; + do { + assert(theval.numattrs == g_numattrs); + int k = theval.cmp(val, val.numattrs); + if (k != 0) { + place = 1; + ret = k; + break; + } + if (side != 0) { + place = 2; + ret = -side; + break; + } + place = 3; + ret = 0; + assert(val.numattrs == 0); + } while (0); + ll3("cmp: val: " << theval << " bnd: " << *this << + " return: " << ret << " at " << place); + return ret; +} + +int +Bnd::type(uint lohi, uint colno) const +{ + int t; + assert(lohi <= 1 && colno < val.numattrs && (side == -1 || side == +1)); + if (lohi == 0) { + if (colno + 1 < val.numattrs) + t = 0; // LE + else if (side == -1) + t = 0; // LE + else + t = 1; // LT + } else { + if (colno + 1 < val.numattrs) + t = 2; // GE + else if (side == +1) + t = 2; // GE + else + t = 3; // GT + } + return t; +} + +struct Range { + Bnd bnd[2]; + uint minattrs() const; + uint maxattrs() const; + int cmp(const Val& val) const; // -1,0,+1 = key is before,in,after range + uint rowcount() const; + bool iseq() const; + // stats + bool flag; + uint statrows; + uint scanrows; + double errpct; +}; + +static NdbOut& +operator<<(NdbOut& out, const Range& range) +{ + out << "bnd0: " << range.bnd[0] << " bnd1: " << range.bnd[1]; + return out; +} + +uint +Range::minattrs() const +{ + return min(bnd[0].val.numattrs, bnd[1].val.numattrs); +} + +uint +Range::maxattrs() const +{ + return max(bnd[0].val.numattrs, bnd[1].val.numattrs); +} + +int +Range::cmp(const Val& theval) const +{ + int place; // debug + int ret; + do { + int k; + k = bnd[0].cmp(theval); + if (k < 0) { + place = 1; + ret = -1; + break; + } + k = bnd[1].cmp(theval); + if (k > 0) { + place = 2; + ret = +1; + break; + } + place = 3; + ret = 0; + } while (0); + ll3("cmp: val: " << theval << " range: " << *this << + " return: " << ret << " at " << place); + return ret; +} + +uint +Range::rowcount() const +{ + ll2("rowcount: " << *this); + int i; + // binary search for first and last in range + int lim[2]; + for (i = 0; i <= 1; i++) { + ll3("search i=" << i); + int lo = -1; + int hi = (int)g_sortcount; + int ret; + int j; + do { + j = (hi + lo) / 2; + ret = cmp(g_sortkeys[j].val); + if (i == 0) { + if (ret < 0) + lo = j; + else + hi = j; + } else { + if (ret > 0) + hi = j; + else + lo = j; + } + } while (hi - lo > 1); + if (ret == 0) + lim[i] = j; + else if (i == 0) + lim[i] = hi; + else + lim[i] = lo; + } + // the range + const int lo = max(lim[0], 0); + const int hi = min(lim[1], (int)g_sortcount - 1); + if (! g_opts.nochecks) { + int curr = -1; + for (i = 0; i < (int)g_sortcount; i++) { + int k = cmp(g_sortkeys[i].val); + if (k < 0) + assert(i < lo); + else if (k == 0) + assert(lo <= i && i <= hi); + else + assert(i > hi); + assert(curr <= k); + if (curr < k) + curr = k; + } + } + // sum them up + uint count = 0; + for (i = lo; i <= hi; i++) + count += g_sortkeys[i].count; + ll2("count: " << count << " index lim: " << lim[0] << " " << lim[1]); + return count; +} + +bool +Range::iseq() const +{ + return + minattrs() == maxattrs() && + bnd[0].val.cmp(bnd[1].val, minattrs()) == 0 && + bnd[0].side < bnd[1].side; +} + +static Range* g_ranges = 0; + +static void +freeranges() +{ + if (g_ranges != 0) + my_free((char*)g_ranges, MYF(0)); + g_ranges = 0; +} + +static int +allocranges() +{ + freeranges(); + size_t sz = sizeof(Range) * g_opts.ops; + g_ranges = (Range*)my_malloc(sz, MYF(0)); + chkrc(g_ranges != 0); + memset(g_ranges, 0x1f, sz); + return 0; +} + +static void +makeranges() +{ + uint i; + for (i = 0; i < g_opts.ops; i++) { + Range& range = g_ranges[i]; + range.flag = false; // mark for dup generation done + bool fulleq = (urandom(100) < g_opts.eqscans); + bool eq = fulleq || (urandom(100) < g_opts.eqscans); + bool matcheq = eq && (urandom(10) != 0); + if (! eq) { + // random but prefer non-empty and no more than scanpct + do { + range.bnd[0].make(0); + range.bnd[1].make(0); + uint count = range.rowcount(); + if (count != 0 && 100 * count <= g_opts.scanpct * g_opts.rows) + break; + } while (urandom(g_opts.tryhard) != 0); + } else { + uint minattrs = fulleq ? g_numattrs : 1; + if (! matcheq) { + range.bnd[0].make(minattrs); + } else { + uint m = urandom(g_sortcount); + const Val& val = g_sortkeys[m].val; + range.bnd[0].make(minattrs, val); + } + range.bnd[1] = range.bnd[0]; + range.bnd[0].side = -1; + range.bnd[1].side = +1; + // fix types + range.bnd[0]; + range.bnd[1]; + assert(range.iseq()); + } + } + for (i = 0; i < g_opts.ops; i++) { + Range& range = g_ranges[i]; + if (range.flag) + continue; + range.flag = true; + if (urandom(100) < g_opts.dupscans) { + uint j = urandom(g_opts.ops); + do { + Range& dst = g_ranges[j]; + if (! dst.flag) { + dst.bnd[0] = range.bnd[0]; + dst.bnd[1] = range.bnd[1]; + dst.flag = true; + break; + } + } while (urandom(g_opts.tryhard) != 0); + } + } +} + +static int +setbounds(const Range& range) +{ + // currently must do each attr in order + ll2("setbounds: " << range); + uint i; + const Bnd (&bnd)[2] = range.bnd; + for (i = 0; i < g_numattrs; i++) { + const Uint32 no = i; // index attribute number + uint j; + int type[2] = { -1, -1 }; + for (j = 0; j <= 1; j++) { + if (no < bnd[j].val.numattrs) + type[j] = bnd[j].type(j, no); + } + for (j = 0; j <= 1; j++) { + int t = type[j]; + if (t == -1) + continue; + if (no + 1 < bnd[j].val.numattrs) + t &= ~(uint)1; // strict bit is set on last bound only + const Val& val = bnd[j].val; + const void* addr = 0; + if (no == 0) + addr = (const void*)&val.b; + else if (no == 1) + addr = ! val.c_null ? (const void*)val.c : 0; + else if (no == 2) + addr = ! val.d_null ? (const void*)&val.d : 0; + else + assert(false); + ll2("setBound attr:" << no << " type:" << t << " val: " << val); + chkdb(g_rangescan_op->setBound(no, t, addr) == 0); + } + } + return 0; +} + +static int +allocstat() +{ + g_stat = new NdbIndexStat(g_ind); + chkdb(g_stat->alloc_cache(32) == 0); + return 0; +} + +static int +runstat(Range& range, int flags) +{ + ll2("runstat: " << range << " flags=" << flags); + chkdb((g_con = g_ndb->startTransaction()) != 0); + chkdb((g_rangescan_op = g_con->getNdbIndexScanOperation(g_ind, g_tab)) != 0); + chkdb(g_rangescan_op->readTuples(NdbOperation::LM_CommittedRead) == 0); + chkrc(setbounds(range) == 0); + Uint64 count = ~(Uint64)0; + chkdb(g_stat->records_in_range(g_ind, g_rangescan_op, g_opts.rows, &count, flags) == 0); + g_ndb->closeTransaction(g_con); + g_con = 0; + g_rangescan_op = 0; + range.statrows = (uint)count; + chkrc((Uint64)range.statrows == count); + ll2("stat: " << range.statrows); + return 0; +} + +static int +runscan(Range& range) +{ + ll2("runscan: " << range); + chkdb((g_con = g_ndb->startTransaction()) != 0); + chkdb((g_rangescan_op = g_con->getNdbIndexScanOperation(g_ind, g_tab)) != 0); + chkdb(g_rangescan_op->readTuples() == 0); + chkrc(setbounds(range) == 0); + Uint32 a; + char* a_addr = (char*)&a; + Uint32 no = 0; + chkdb(g_rangescan_op->getValue(no++, a_addr) != 0); + chkdb(g_con->execute(NdbTransaction::NoCommit) == 0); + uint count = 0; + uint i; + for (i = 0; i < g_opts.rows; i++) + g_keys[i].count = 0; + while (1) { + int ret; + a = ~(Uint32)0; + chkdb((ret = g_rangescan_op->nextResult()) == 0 || ret == 1); + if (ret == 1) + break; + i = (uint)a; + chkrc(i < g_opts.rows); + Key& key = g_keys[i]; + ll3("scan: " << key); + int k = range.cmp(key.val); + chkrc(k == 0); + chkrc(key.count == 0); + key.count++; + count++; + } + g_ndb->closeTransaction(g_con); + g_con = 0; + g_rangescan_op = 0; + if (! g_opts.nochecks) { + for (i = 0; i < g_opts.rows; i++) { + const Key& key = g_keys[i]; + int k = range.cmp(key.val); + assert((k != 0 && key.count == 0) || (k == 0 && key.count == 1)); + } + assert(range.rowcount() == count); + } + range.scanrows = count; + ll2("scan: " << range.scanrows); + return 0; +} + +static int +runscans() +{ + uint i; + for (i = 0; i < g_opts.ops; i++) { + Range& range = g_ranges[i]; + ll1("range " << i << ": " << range); + // simulate old handler code + int flags = 0; + if (i < 32 || i % 20 == 0) + flags |= NdbIndexStat::RR_UseDb; + chkrc(runstat(range, flags) == 0); + chkrc(runscan(range) == 0); + // if stat is 0 then it is exact scan count + chkrc(range.statrows != 0 || range.scanrows == 0); + // measure error as fraction of total rows + double x = (double)range.statrows; + double y = (double)range.scanrows; + double z = (double)g_opts.rows; + double err = (x - y) / z; + // report in pct + range.errpct = 100.0 * err; + ll1("range " << i << ":" << + " stat: " << range.statrows << " scan: " << range.scanrows << + " errpct: " << range.errpct); + } + return 0; +} + +struct Stat { + const char* name; + uint count; + double sum; + double minval; + double maxval; + double avg; + double varsum; + double var; + double stddev; + void init(); + void add(const Stat& stat); +}; + +void +Stat::init() +{ + name = "stat"; + count = 0; + sum = minval = maxval = avg = varsum = var = stddev = 0.0; +} + +void +Stat::add(const Stat& stat) +{ + if (count == 0) { + *this = stat; + return; + } + Stat tmp = *this; + tmp.count = count + stat.count; + tmp.sum = sum + stat.sum; + tmp.minval = minval <= stat.minval ? minval : stat.minval; + tmp.maxval = maxval >= stat.maxval ? maxval : stat.maxval; + tmp.avg = tmp.sum / double(tmp.count); + tmp.varsum = varsum + stat.varsum; + tmp.var = tmp.varsum / double(tmp.count); + tmp.stddev = sqrt(tmp.var); + *this = tmp; +} + +static NdbOut& +operator<<(NdbOut& out, const Stat& stat) +{ + out << stat.name << ": " << "count: " << stat.count + << " min: " << stat.minval << " max: " << stat.maxval + << " avg: " << stat.avg << " stddev: " << stat.stddev; + return out; +} + +template <class T, class V> +static void +computestat(Stat& stat) +{ + stat.init(); + stat.name = V::name(); + const T* array = V::array(); + stat.count = V::count(); + assert(stat.count != 0); + uint i; + for (i = 0; i < stat.count; i++) { + const T& item = array[i]; + double data = V::data(item); + stat.sum += data; + if (i == 0) + stat.minval = stat.maxval = data; + else { + if (stat.minval > data) + stat.minval = data; + if (stat.maxval < data) + stat.maxval = data; + } + } + stat.avg = stat.sum / double(stat.count); + stat.varsum = 0.0; + for (i = 0; i < stat.count; i++) { + const T& item = array[i]; + double data = V::data(item); + double x = data - stat.avg; + stat.varsum += x * x; + } + stat.var = stat.varsum / double(stat.count); + stat.stddev = sqrt(stat.var); +} + +struct V_rpk { + static const char* name() { return "rec per key"; } + static const Key* array() { return g_sortkeys; } + static uint count() { return g_sortcount; } + static double data(const Key& key) { return (double)key.rpk; } +}; + +struct V_rir { + static const char* name() { return "rir err pct"; } + static const Range* array() { return g_ranges; } + static uint count() { return g_opts.ops; } + static double data(const Range& range) { return (double)range.errpct; } +}; + +template static void computestat<Key, V_rpk>(Stat& stat); +template static void computestat<Range, V_rir>(Stat& stat); + +static Stat g_stat_rpk; // summaries over loops +static Stat g_stat_rir; + +static void +loopstats() +{ + Stat stat_rpk; // records per key + Stat stat_rir; // record in range + if (g_loop == 0) { + g_stat_rpk.init(); + g_stat_rir.init(); + } + computestat<Key, V_rpk>(stat_rpk); + computestat<Range, V_rir>(stat_rir); + if (g_opts.loop != 1) { + ll0("=== loop " << g_loop << " summary ==="); + ll0(stat_rpk); + ll0(stat_rir); + } + // accumulate + g_stat_rpk.add(stat_rpk); + g_stat_rir.add(stat_rir); +} + +static void +finalstats() +{ + ll0("=== summary ==="); + ll0(g_stat_rpk); + ll0(g_stat_rir); +} + +static void +setseed(int n) +{ + uint seed; + if (n == -1) { + if (g_opts.seed == 0) + return; + if (g_opts.seed != -1) + seed = (uint)g_opts.seed; + else + seed = 1 + (ushort)getpid(); + } else { + if (g_opts.seed != 0) + return; + seed = n; + } + ll0("seed=" << seed); + srandom(seed); +} + +static int +runtest() +{ + setseed(-1); + g_cs = get_charset_by_name(g_csname, MYF(0)); + if (g_cs == 0) + g_cs = get_charset_by_csname(g_csname, MY_CS_PRIMARY, MYF(0)); + chkrc(g_cs != 0); + for (g_loop = 0; g_opts.loop == 0 || g_loop < g_opts.loop; g_loop++) { + ll0("=== loop " << g_loop << " ==="); + setseed(g_loop); + chkrc(createtable() == 0); + chkrc(loaddata() == 0); + sortkeys(); + chkrc(allocranges() == 0); + makeranges(); + chkrc(allocstat() == 0); + chkrc(runscans() == 0); + chkrc(droptable() == 0); + loopstats(); + } + finalstats(); + return 0; +} + +NDB_STD_OPTS_VARS; + +static struct my_option +my_long_options[] = +{ + NDB_STD_OPTS("testIndexStat"), + { "loglevel", 1001, "Logging level in this program 0-3 (default 0)", + (gptr*)&g_opts.loglevel, (gptr*)&g_opts.loglevel, 0, + GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, + { "seed", 1002, "Random seed (0=loop number, default -1=random)", + (gptr*)&g_opts.seed, (gptr*)&g_opts.seed, 0, + GET_INT, REQUIRED_ARG, -1, 0, 0, 0, 0, 0 }, + { "loop", 1003, "Number of test loops (default 1, 0=forever)", + (gptr*)&g_opts.loop, (gptr*)&g_opts.loop, 0, + GET_INT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0 }, + { "rows", 1004, "Number of rows (default 100000)", + (gptr*)&g_opts.rows, (gptr*)&g_opts.rows, 0, + GET_UINT, REQUIRED_ARG, 100000, 0, 0, 0, 0, 0 }, + { "ops", 1005, "Number of index scans per loop (default 1000)", + (gptr*)&g_opts.ops, (gptr*)&g_opts.ops, 0, + GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0 }, + { "dupkeys", 1006, "Pct records per key (min 100, default 1000)", + (gptr*)&g_opts.dupkeys, (gptr*)&g_opts.dupkeys, 0, + GET_UINT, REQUIRED_ARG, 1000, 0, 0, 0, 0, 0 }, + { "scanpct", 1007, "Preferred max pct of total rows per scan (default 5)", + (gptr*)&g_opts.scanpct, (gptr*)&g_opts.scanpct, 0, + GET_UINT, REQUIRED_ARG, 5, 0, 0, 0, 0, 0 }, + { "nullkeys", 1008, "Pct nulls in each key attribute (default 10)", + (gptr*)&g_opts.nullkeys, (gptr*)&g_opts.nullkeys, 0, + GET_UINT, REQUIRED_ARG, 10, 0, 0, 0, 0, 0 }, + { "eqscans", 1009, "Pct scans for partial/full equality (default 50)", + (gptr*)&g_opts.eqscans, (gptr*)&g_opts.eqscans, 0, + GET_UINT, REQUIRED_ARG, 50, 0, 0, 0, 0, 0 }, + { "dupscans", 1010, "Pct scans using same bounds (default 10)", + (gptr*)&g_opts.dupscans, (gptr*)&g_opts.dupscans, 0, + GET_UINT, REQUIRED_ARG, 10, 0, 0, 0, 0, 0 }, + { "keeptable", 1011, "Use existing table and data if any and do not drop", + (gptr*)&g_opts.keeptable, (gptr*)&g_opts.keeptable, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "no-extra-checks", 1012, "Omit expensive consistency checks", + (gptr*)&g_opts.nochecks, (gptr*)&g_opts.nochecks, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { "abort-on-error", 1013, "Dump core on any error", + (gptr*)&g_opts.abort, (gptr*)&g_opts.abort, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, + { 0, 0, 0, + 0, 0, 0, + GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0 } +}; + +static void +usage() +{ + ndbout + << g_progname + << ": measure records_in_range error as percentage of total rows" << endl; + my_print_help(my_long_options); +} + +static int +checkoptions() +{ + chkrc(g_opts.rows != 0); + chkrc(g_opts.nullkeys <= 100); + chkrc(g_opts.dupkeys >= 100); + chkrc(g_opts.scanpct <= 100); + chkrc(g_opts.eqscans <= 100); + chkrc(g_opts.dupscans <= 100); + return 0; +} + +static int +doconnect() +{ + g_ncc = new Ndb_cluster_connection(); + chkdb(g_ncc->connect(30) == 0); + g_ndb = new Ndb(g_ncc, "TEST_DB"); + chkdb(g_ndb->init() == 0 && g_ndb->waitUntilReady(30) == 0); + return 0; +} + +static void +freeall() +{ + delete g_stat; + freekeys(); + freeranges(); + delete g_ndb; + delete g_ncc; +} + +int +main(int argc, char** argv) +{ + ndb_init(); + const char* g_progname = + strchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0]; + uint i; + ndbout << g_progname; + for (i = 1; i < argc; i++) + ndbout << " " << argv[i]; + ndbout << endl; + int ret; + ret = handle_options(&argc, &argv, my_long_options, ndb_std_get_one_option); + if (ret != 0 || argc != 0) + return NDBT_ProgramExit(NDBT_WRONGARGS); + if (checkoptions() == 0 && doconnect() == 0 && runtest() == 0) { + freeall(); + return NDBT_ProgramExit(NDBT_OK); + } + freeall(); + return NDBT_ProgramExit(NDBT_FAILED); +} diff --git a/storage/ndb/test/ndbapi/testOIBasic.cpp b/storage/ndb/test/ndbapi/testOIBasic.cpp index a752b9995f0..271f19a5477 100644 --- a/storage/ndb/test/ndbapi/testOIBasic.cpp +++ b/storage/ndb/test/ndbapi/testOIBasic.cpp @@ -47,7 +47,6 @@ struct Opt { int m_die; bool m_dups; NdbDictionary::Object::FragmentType m_fragtype; - unsigned m_subsubloop; const char* m_index; unsigned m_loop; bool m_msglock; @@ -56,6 +55,7 @@ struct Opt { unsigned m_pctnull; unsigned m_rows; unsigned m_samples; + unsigned m_scanbatch; unsigned m_scanpar; unsigned m_scanstop; int m_seed; @@ -74,7 +74,6 @@ struct Opt { m_die(0), m_dups(false), m_fragtype(NdbDictionary::Object::FragUndefined), - m_subsubloop(4), m_index(0), m_loop(1), m_msglock(true), @@ -83,6 +82,7 @@ struct Opt { m_pctnull(10), m_rows(1000), m_samples(0), + m_scanbatch(0), m_scanpar(0), m_scanstop(0), m_seed(-1), @@ -120,9 +120,10 @@ printhelp() << " -pctnull N pct NULL values in nullable column [" << d.m_pctnull << "]" << endl << " -rows N rows per thread [" << d.m_rows << "]" << endl << " -samples N samples for some timings (0=all) [" << d.m_samples << "]" << endl - << " -scanpar N scan parallelism [" << d.m_scanpar << "]" << endl + << " -scanbatch N scan batch 0=default [" << d.m_scanbatch << "]" << endl + << " -scanpar N scan parallel 0=default [" << d.m_scanpar << "]" << endl << " -seed N srandom seed 0=loop number -1=random [" << d.m_seed << "]" << endl - << " -subloop N subtest loop count [" << d.m_subloop << "]" << endl + << " -subloop N subtest (and subsubtest) loop count [" << d.m_subloop << "]" << endl << " -table xyz only given table numbers (digits 0-9)" << endl << " -threads N number of threads [" << d.m_threads << "]" << endl << " -vN verbosity [" << d.m_v << "]" << endl @@ -294,6 +295,7 @@ struct Par : public Opt { Set& set() const { assert(m_set != 0); return *m_set; } Tmr* m_tmr; Tmr& tmr() const { assert(m_tmr != 0); return *m_tmr; } + char m_currcase[2]; unsigned m_lno; unsigned m_slno; unsigned m_totrows; @@ -302,6 +304,7 @@ struct Par : public Opt { unsigned m_pctrange; unsigned m_pctbrange; int m_bdir; + bool m_noindexkeyupdate; // choice of key bool m_randomkey; // do verify after read @@ -330,6 +333,7 @@ struct Par : public Opt { m_pctrange(40), m_pctbrange(80), m_bdir(0), + m_noindexkeyupdate(false), m_randomkey(false), m_verify(false), m_deadlock(false), @@ -337,7 +341,9 @@ struct Par : public Opt { m_lockmode(NdbOperation::LM_Read), m_tupscan(false), m_ordered(false), - m_descending(false) { + m_descending(false) + { + m_currcase[0] = 0; } }; @@ -892,6 +898,8 @@ struct Tab { const Col** m_col; unsigned m_itabs; const ITab** m_itab; + unsigned m_orderedindexes; + unsigned m_hashindexes; // pk must contain an Unsigned column unsigned m_keycol; void coladd(unsigned k, Col* colptr); @@ -906,6 +914,8 @@ Tab::Tab(const char* name, unsigned cols, unsigned itabs, unsigned keycol) : m_col(new const Col* [cols + 1]), m_itabs(itabs), m_itab(new const ITab* [itabs + 1]), + m_orderedindexes(0), + m_hashindexes(0), m_keycol(keycol) { for (unsigned k = 0; k <= cols; k++) @@ -935,8 +945,12 @@ Tab::coladd(unsigned k, Col* colptr) void Tab::itabadd(unsigned j, ITab* itabptr) { - assert(j < m_itabs && m_itab[j] == 0); + assert(j < m_itabs && m_itab[j] == 0 && itabptr != 0); m_itab[j] = itabptr; + if (itabptr->m_type == ITab::OrderedIndex) + m_orderedindexes++; + else + m_hashindexes++; } static NdbOut& @@ -1434,7 +1448,7 @@ Con::readTuples(Par par) int scan_flags = 0; if (par.m_tupscan) scan_flags |= NdbScanOperation::SF_TupScan; - CHKCON(m_scanop->readTuples(par.m_lockmode, scan_flags, par.m_scanpar) == 0, *this); + CHKCON(m_scanop->readTuples(par.m_lockmode, scan_flags, par.m_scanpar, par.m_scanbatch) == 0, *this); return 0; } @@ -1442,7 +1456,12 @@ int Con::readIndexTuples(Par par) { assert(m_tx != 0 && m_indexscanop != 0); - CHKCON(m_indexscanop->readTuples(par.m_lockmode, 0, par.m_scanpar, par.m_ordered, par.m_descending) == 0, *this); + int scan_flags = 0; + if (par.m_ordered) + scan_flags |= NdbScanOperation::SF_OrderBy; + if (par.m_descending) + scan_flags |= NdbScanOperation::SF_Descending; + CHKCON(m_indexscanop->readTuples(par.m_lockmode, scan_flags, par.m_scanpar, par.m_scanbatch) == 0, *this); return 0; } @@ -2193,7 +2212,7 @@ struct Row { void copy(const Row& row2); void calc(Par par, unsigned i, unsigned mask = 0); const Row& dbrow() const; - int verify(Par par, const Row& row2) const; + int verify(Par par, const Row& row2, bool pkonly) const; int insrow(Par par); int updrow(Par par); int updrow(Par par, const ITab& itab); @@ -2275,15 +2294,18 @@ Row::dbrow() const } int -Row::verify(Par par, const Row& row2) const +Row::verify(Par par, const Row& row2, bool pkonly) const { const Tab& tab = m_tab; const Row& row1 = *this; assert(&row1.m_tab == &row2.m_tab && row1.m_exist && row2.m_exist); for (unsigned k = 0; k < tab.m_cols; k++) { - const Val& val1 = *row1.m_val[k]; - const Val& val2 = *row2.m_val[k]; - CHK(val1.verify(par, val2) == 0); + const Col& col = row1.m_val[k]->m_col; + if (! pkonly || col.m_pk) { + const Val& val1 = *row1.m_val[k]; + const Val& val2 = *row2.m_val[k]; + CHK(val1.verify(par, val2) == 0); + } } return 0; } @@ -2585,8 +2607,11 @@ struct Set { int getval(Par par); int getkey(Par par, unsigned* i); int putval(unsigned i, bool force, unsigned n = ~0); + // sort rows in-place according to ordered index + void sort(Par par, const ITab& itab); + void sort(Par par, const ITab& itab, unsigned lo, unsigned hi); // verify - int verify(Par par, const Set& set2) const; + int verify(Par par, const Set& set2, bool pkonly) const; int verifyorder(Par par, const ITab& itab, bool descending) const; // protect structure NdbMutex* m_mutex; @@ -2890,6 +2915,7 @@ Set::getkey(Par par, unsigned* i) assert(m_rec[k] != 0); const char* aRef = m_rec[k]->aRef(); Uint32 key = *(const Uint32*)aRef; + LL5("getkey: " << key); CHK(key < m_rows); *i = key; return 0; @@ -2922,8 +2948,43 @@ Set::putval(unsigned i, bool force, unsigned n) return 0; } +void +Set::sort(Par par, const ITab& itab) +{ + if (m_rows != 0) + sort(par, itab, 0, m_rows - 1); +} + +void +Set::sort(Par par, const ITab& itab, unsigned lo, unsigned hi) +{ + assert(lo < m_rows && hi < m_rows && lo <= hi); + Row* const p = m_row[lo]; + unsigned i = lo; + unsigned j = hi; + while (i < j) { + while (i < j && m_row[j]->cmp(par, *p, itab) >= 0) + j--; + if (i < j) { + m_row[i] = m_row[j]; + i++; + } + while (i < j && m_row[i]->cmp(par, *p, itab) <= 0) + i++; + if (i < j) { + m_row[j] = m_row[i]; + j--; + } + } + m_row[i] = p; + if (lo < i) + sort(par, itab, lo, i - 1); + if (hi > i) + sort(par, itab, i + 1, hi); +} + int -Set::verify(Par par, const Set& set2) const +Set::verify(Par par, const Set& set2, bool pkonly) const { assert(&m_tab == &set2.m_tab && m_rows == set2.m_rows); LL4("verify set1 count=" << count() << " vs set2 count=" << set2.count()); @@ -2932,7 +2993,7 @@ Set::verify(Par par, const Set& set2) const if (exist(i) != set2.exist(i)) { ok = false; } else if (exist(i)) { - if (dbrow(i).verify(par, set2.dbrow(i)) != 0) + if (dbrow(i).verify(par, set2.dbrow(i), pkonly) != 0) ok = false; } if (! ok) { @@ -3490,7 +3551,7 @@ pkread(Par par) con.closeTransaction(); } if (par.m_verify) - CHK(set1.verify(par, set2) == 0); + CHK(set1.verify(par, set2, false) == 0); return 0; } @@ -3657,7 +3718,7 @@ hashindexread(Par par, const ITab& itab) con.closeTransaction(); } if (par.m_verify) - CHK(set1.verify(par, set2) == 0); + CHK(set1.verify(par, set2, false) == 0); return 0; } @@ -3698,7 +3759,7 @@ scanreadtable(Par par) } con.closeTransaction(); if (par.m_verify) - CHK(set1.verify(par, set2) == 0); + CHK(set1.verify(par, set2, false) == 0); LL3("scanread " << tab.m_name << " done rows=" << n); return 0; } @@ -3730,6 +3791,23 @@ scanreadtablefast(Par par, unsigned countcheck) return 0; } +// try to get interesting bounds +static void +calcscanbounds(Par par, const ITab& itab, BSet& bset, const Set& set, Set& set1) +{ + while (true) { + bset.calc(par); + bset.filter(par, set, set1); + unsigned n = set1.count(); + // prefer proper subset + if (0 < n && n < set.m_rows) + break; + if (urandom(5) == 0) + break; + set1.reset(); + } +} + static int scanreadindex(Par par, const ITab& itab, BSet& bset, bool calc) { @@ -3738,21 +3816,11 @@ scanreadindex(Par par, const ITab& itab, BSet& bset, bool calc) const Set& set = par.set(); Set set1(tab, set.m_rows); if (calc) { - while (true) { - bset.calc(par); - bset.filter(par, set, set1); - unsigned n = set1.count(); - // prefer proper subset - if (0 < n && n < set.m_rows) - break; - if (urandom(3) == 0) - break; - set1.reset(); - } + calcscanbounds(par, itab, bset, set, set1); } else { bset.filter(par, set, set1); } - LL3("scanread " << itab.m_name << " " << bset << " lockmode=" << par.m_lockmode << " expect=" << set1.count() << " verify=" << par.m_verify << " ordered=" << par.m_ordered << " descending=" << par.m_descending); + LL3("scanread " << itab.m_name << " " << bset << " lockmode=" << par.m_lockmode << " expect=" << set1.count() << " ordered=" << par.m_ordered << " descending=" << par.m_descending << " verify=" << par.m_verify); Set set2(tab, set.m_rows); CHK(con.startTransaction() == 0); CHK(con.getNdbIndexScanOperation(itab, tab) == 0); @@ -3780,7 +3848,7 @@ scanreadindex(Par par, const ITab& itab, BSet& bset, bool calc) } con.closeTransaction(); if (par.m_verify) { - CHK(set1.verify(par, set2) == 0); + CHK(set1.verify(par, set2, false) == 0); if (par.m_ordered) CHK(set2.verifyorder(par, itab, par.m_descending) == 0); } @@ -3825,17 +3893,7 @@ scanreadfilter(Par par, const ITab& itab, BSet& bset, bool calc) const Set& set = par.set(); Set set1(tab, set.m_rows); if (calc) { - while (true) { - bset.calc(par); - bset.filter(par, set, set1); - unsigned n = set1.count(); - // prefer proper subset - if (0 < n && n < set.m_rows) - break; - if (urandom(3) == 0) - break; - set1.reset(); - } + calcscanbounds(par, itab, bset, set, set1); } else { bset.filter(par, set, set1); } @@ -3867,7 +3925,7 @@ scanreadfilter(Par par, const ITab& itab, BSet& bset, bool calc) } con.closeTransaction(); if (par.m_verify) { - CHK(set1.verify(par, set2) == 0); + CHK(set1.verify(par, set2, false) == 0); } LL3("scanfilter " << itab.m_name << " done rows=" << n); return 0; @@ -3877,7 +3935,7 @@ static int scanreadindex(Par par, const ITab& itab) { const Tab& tab = par.tab(); - for (unsigned i = 0; i < par.m_subsubloop; i++) { + for (unsigned i = 0; i < par.m_subloop; i++) { if (itab.m_type == ITab::OrderedIndex) { BSet bset(tab, itab, par.m_rows); CHK(scanreadfilter(par, itab, bset, true) == 0); @@ -4068,12 +4126,19 @@ out: } static int -scanupdateindex(Par par, const ITab& itab, const BSet& bset) +scanupdateindex(Par par, const ITab& itab, BSet& bset, bool calc) { Con& con = par.con(); const Tab& tab = par.tab(); Set& set = par.set(); - LL3("scan update " << itab.m_name); + // expected + Set set1(tab, set.m_rows); + if (calc) { + calcscanbounds(par, itab, bset, set, set1); + } else { + bset.filter(par, set, set1); + } + LL3("scan update " << itab.m_name << " " << bset << " expect=" << set1.count() << " ordered=" << par.m_ordered << " descending=" << par.m_descending << " verify=" << par.m_verify); Set set2(tab, set.m_rows); par.m_lockmode = NdbOperation::LM_Exclusive; CHK(con.startTransaction() == 0); @@ -4117,7 +4182,7 @@ scanupdateindex(Par par, const ITab& itab, const BSet& bset) Par par2 = par; par2.m_con = &con2; set.dbsave(i); - set.calc(par, i); + set.calc(par, i, ! par.m_noindexkeyupdate ? 0 : itab.m_colmask); CHKTRY(set.setrow(par2, i) == 0, set.unlock()); LL4("scan update " << itab.m_name << ": " << row); lst.push(i); @@ -4131,6 +4196,7 @@ scanupdateindex(Par par, const ITab& itab, const BSet& bset) goto out; } con2.closeTransaction(); + LL4("scanupdateindex: committed batch [at 1]"); set.lock(); set.notpending(lst); set.dbdiscard(lst); @@ -4148,6 +4214,7 @@ scanupdateindex(Par par, const ITab& itab, const BSet& bset) goto out; } con2.closeTransaction(); + LL4("scanupdateindex: committed batch [at 2]"); set.lock(); set.notpending(lst); set.dbdiscard(lst); @@ -4160,6 +4227,11 @@ scanupdateindex(Par par, const ITab& itab, const BSet& bset) } out: con2.closeTransaction(); + if (par.m_verify) { + CHK(set1.verify(par, set2, true) == 0); + if (par.m_ordered) + CHK(set2.verifyorder(par, itab, par.m_descending) == 0); + } LL3("scan update " << itab.m_name << " rows updated=" << count); con.closeTransaction(); return 0; @@ -4169,11 +4241,10 @@ static int scanupdateindex(Par par, const ITab& itab) { const Tab& tab = par.tab(); - for (unsigned i = 0; i < par.m_subsubloop; i++) { + for (unsigned i = 0; i < par.m_subloop; i++) { if (itab.m_type == ITab::OrderedIndex) { BSet bset(tab, itab, par.m_rows); - bset.calc(par); - CHK(scanupdateindex(par, itab, bset) == 0); + CHK(scanupdateindex(par, itab, bset, true) == 0); } else { CHK(hashindexupdate(par, itab) == 0); } @@ -4205,22 +4276,6 @@ scanupdateall(Par par) // medium level routines static int -readverify(Par par) -{ - if (par.m_noverify) - return 0; - par.m_verify = true; - if (par.m_abortpct != 0) { - LL2("skip verify in this version"); // implement in 5.0 version - par.m_verify = false; - } - par.m_lockmode = NdbOperation::LM_CommittedRead; - CHK(pkread(par) == 0); - CHK(scanreadall(par) == 0); - return 0; -} - -static int readverifyfull(Par par) { if (par.m_noverify) @@ -4277,7 +4332,7 @@ pkops(Par par) { const Tab& tab = par.tab(); par.m_randomkey = true; - for (unsigned i = 0; i < par.m_subsubloop; i++) { + for (unsigned i = 0; i < par.m_subloop; i++) { unsigned j = 0; while (j < tab.m_itabs) { if (tab.m_itab[j] != 0) { @@ -4377,6 +4432,33 @@ mixedoperations(Par par) } static int +parallelorderedupdate(Par par) +{ + const Tab& tab = par.tab(); + unsigned k = 0; + for (unsigned i = 0; i < tab.m_itabs; i++) { + if (tab.m_itab[i] == 0) + continue; + const ITab& itab = *tab.m_itab[i]; + if (itab.m_type != ITab::OrderedIndex) + continue; + // cannot sync threads yet except via subloop + if (k++ == par.m_slno % tab.m_orderedindexes) { + LL3("parallelorderedupdate: " << itab.m_name); + par.m_noindexkeyupdate = true; + par.m_ordered = true; + par.m_descending = (par.m_slno != 0); + par.m_verify = true; + BSet bset(tab, itab, par.m_rows); // empty bounds + // prefer empty bounds + unsigned sel = urandom(10); + CHK(scanupdateindex(par, itab, bset, sel < 2) == 0); + } + } + return 0; +} + +static int pkupdateindexbuild(Par par) { if (par.m_no == 0) { @@ -4578,7 +4660,7 @@ getthrno() static int runstep(Par par, const char* fname, TFunc func, unsigned mode) { - LL2(fname); + LL2("step: " << fname); const int threads = (mode & ST ? 1 : par.m_threads); int n; for (n = 0; n < threads; n++) { @@ -4604,7 +4686,12 @@ runstep(Par par, const char* fname, TFunc func, unsigned mode) return 0; } -#define RUNSTEP(par, func, mode) CHK(runstep(par, #func, func, mode) == 0) +#define RUNSTEP(par, func, mode) \ + CHK(runstep(par, #func, func, mode) == 0) + +#define SUBLOOP(par) \ + "subloop: " << par.m_lno << "/" << par.m_currcase << "/" << \ + par.m_tab->m_name << "/" << par.m_slno static int tbuild(Par par) @@ -4613,6 +4700,7 @@ tbuild(Par par) RUNSTEP(par, createtable, ST); RUNSTEP(par, invalidatetable, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); if (par.m_slno % 3 == 0) { RUNSTEP(par, createindex, ST); RUNSTEP(par, invalidateindex, MT); @@ -4630,7 +4718,7 @@ tbuild(Par par) RUNSTEP(par, invalidateindex, MT); } RUNSTEP(par, readverifyfull, MT); - // leave last one alone e.g. to continue manually + // leave last one if (par.m_slno + 1 < par.m_subloop) { RUNSTEP(par, pkdelete, MT); RUNSTEP(par, readverifyfull, MT); @@ -4651,7 +4739,7 @@ tindexscan(Par par) RUNSTEP(par, pkinsert, MT); RUNSTEP(par, readverifyfull, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { - LL4("subloop " << par.m_slno); + LL1(SUBLOOP(par)); RUNSTEP(par, readverifyindex, MT); } return 0; @@ -4667,6 +4755,7 @@ tpkops(Par par) RUNSTEP(par, createindex, ST); RUNSTEP(par, invalidateindex, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, pkops, MT); LL2("rows=" << par.set().count()); RUNSTEP(par, readverifyfull, MT); @@ -4683,13 +4772,14 @@ tpkopsread(Par par) RUNSTEP(par, pkinsert, MT); RUNSTEP(par, createindex, ST); RUNSTEP(par, invalidateindex, MT); - RUNSTEP(par, readverify, ST); + RUNSTEP(par, readverifyfull, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, pkupdatescanread, MT); - RUNSTEP(par, readverify, ST); + RUNSTEP(par, readverifyfull, MT); } RUNSTEP(par, pkdelete, MT); - RUNSTEP(par, readverify, ST); + RUNSTEP(par, readverifyfull, MT); return 0; } @@ -4702,10 +4792,11 @@ tmixedops(Par par) RUNSTEP(par, pkinsert, MT); RUNSTEP(par, createindex, ST); RUNSTEP(par, invalidateindex, MT); - RUNSTEP(par, readverify, ST); + RUNSTEP(par, readverifyfull, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, mixedoperations, MT); - RUNSTEP(par, readverify, ST); + RUNSTEP(par, readverifyfull, MT); } return 0; } @@ -4718,9 +4809,10 @@ tbusybuild(Par par) RUNSTEP(par, invalidatetable, MT); RUNSTEP(par, pkinsert, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, pkupdateindexbuild, MT); RUNSTEP(par, invalidateindex, MT); - RUNSTEP(par, readverify, ST); + RUNSTEP(par, readverifyfull, MT); RUNSTEP(par, dropindex, ST); } return 0; @@ -4736,10 +4828,29 @@ trollback(Par par) RUNSTEP(par, pkinsert, MT); RUNSTEP(par, createindex, ST); RUNSTEP(par, invalidateindex, MT); - RUNSTEP(par, readverify, ST); + RUNSTEP(par, readverifyfull, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, mixedoperations, MT); - RUNSTEP(par, readverify, ST); + RUNSTEP(par, readverifyfull, MT); + } + return 0; +} + +static int +tparupdate(Par par) +{ + RUNSTEP(par, droptable, ST); + RUNSTEP(par, createtable, ST); + RUNSTEP(par, invalidatetable, MT); + RUNSTEP(par, pkinsert, MT); + RUNSTEP(par, createindex, ST); + RUNSTEP(par, invalidateindex, MT); + RUNSTEP(par, readverifyfull, MT); + for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); + RUNSTEP(par, parallelorderedupdate, MT); + RUNSTEP(par, readverifyfull, MT); } return 0; } @@ -4752,6 +4863,7 @@ ttimebuild(Par par) RUNSTEP(par, createtable, ST); RUNSTEP(par, invalidatetable, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, pkinsert, MT); t1.on(); RUNSTEP(par, createindex, ST); @@ -4771,6 +4883,7 @@ ttimemaint(Par par) RUNSTEP(par, createtable, ST); RUNSTEP(par, invalidatetable, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, pkinsert, MT); t1.on(); RUNSTEP(par, pkupdate, MT); @@ -4800,6 +4913,7 @@ ttimescan(Par par) RUNSTEP(par, createtable, ST); RUNSTEP(par, invalidatetable, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, pkinsert, MT); RUNSTEP(par, createindex, ST); par.m_tmr = &t1; @@ -4826,6 +4940,7 @@ ttimepkread(Par par) RUNSTEP(par, createtable, ST); RUNSTEP(par, invalidatetable, MT); for (par.m_slno = 0; par.m_slno < par.m_subloop; par.m_slno++) { + LL1(SUBLOOP(par)); RUNSTEP(par, pkinsert, MT); RUNSTEP(par, createindex, ST); par.m_tmr = &t1; @@ -4867,6 +4982,7 @@ tcaselist[] = { TCase("e", tmixedops, "pk operations and scan operations"), TCase("f", tbusybuild, "pk operations and index build"), TCase("g", trollback, "operations with random rollbacks"), + TCase("h", tparupdate, "parallel ordered update (bug20446)"), TCase("t", ttimebuild, "time index build"), TCase("u", ttimemaint, "time index maintenance"), TCase("v", ttimescan, "time full scan table vs index on pk"), @@ -4924,17 +5040,16 @@ printtables() static int runtest(Par par) { - LL1("start"); if (par.m_seed == -1) { // good enough for daily run - unsigned short seed = (getpid() ^ time(0)); - LL1("random seed: " << seed); + unsigned short seed = (unsigned short)getpid(); + LL0("random seed: " << seed); srandom((unsigned)seed); } else if (par.m_seed != 0) { - LL1("random seed: " << par.m_seed); + LL0("random seed: " << par.m_seed); srandom(par.m_seed); } else { - LL1("random seed: loop number"); + LL0("random seed: loop number"); } // cs assert(par.m_csname != 0); @@ -4959,22 +5074,25 @@ runtest(Par par) assert(thr.m_thread != 0); } for (par.m_lno = 0; par.m_loop == 0 || par.m_lno < par.m_loop; par.m_lno++) { - LL1("loop " << par.m_lno); - if (par.m_seed == 0) + LL1("loop: " << par.m_lno); + if (par.m_seed == 0) { + LL1("random seed: " << par.m_lno); srandom(par.m_lno); + } for (unsigned i = 0; i < tcasecount; i++) { const TCase& tcase = tcaselist[i]; if (par.m_case != 0 && strchr(par.m_case, tcase.m_name[0]) == 0) continue; + sprintf(par.m_currcase, "%c", tcase.m_name[0]); makebuiltintables(par); - LL1("case " << tcase.m_name << " - " << tcase.m_desc); + LL1("case: " << par.m_lno << "/" << tcase.m_name << " - " << tcase.m_desc); for (unsigned j = 0; j < tabcount; j++) { if (tablist[j] == 0) continue; const Tab& tab = *tablist[j]; par.m_tab = &tab; par.m_set = new Set(tab, par.m_totrows); - LL1("table " << tab.m_name); + LL1("table: " << par.m_lno << "/" << tcase.m_name << "/" << tab.m_name); CHK(tcase.m_func(par) == 0); delete par.m_set; par.m_set = 0; @@ -4993,15 +5111,21 @@ runtest(Par par) delete [] g_thrlist; g_thrlist = 0; con.disconnect(); - LL1("done"); return 0; } -NDB_COMMAND(testOIBasic, "testOIBasic", "testOIBasic", "testOIBasic", 65535) +static const char* g_progname = "testOIBasic"; + +int +main(int argc, char** argv) { ndb_init(); - if (ndbout_mutex == NULL) - ndbout_mutex = NdbMutex_Create(); + unsigned i; + ndbout << g_progname; + for (i = 1; i < argc; i++) + ndbout << " " << argv[i]; + ndbout << endl; + ndbout_mutex = NdbMutex_Create(); while (++argv, --argc > 0) { const char* arg = argv[0]; if (*arg != '-') { @@ -5111,6 +5235,12 @@ NDB_COMMAND(testOIBasic, "testOIBasic", "testOIBasic", "testOIBasic", 65535) continue; } } + if (strcmp(arg, "-scanbatch") == 0) { + if (++argv, --argc > 0) { + g_opt.m_scanbatch = atoi(argv[0]); + continue; + } + } if (strcmp(arg, "-scanpar") == 0) { if (++argv, --argc > 0) { g_opt.m_scanpar = atoi(argv[0]); diff --git a/storage/ndb/test/ndbapi/testOperations.cpp b/storage/ndb/test/ndbapi/testOperations.cpp index e116545f7e3..5e629f8c0c9 100644 --- a/storage/ndb/test/ndbapi/testOperations.cpp +++ b/storage/ndb/test/ndbapi/testOperations.cpp @@ -660,9 +660,11 @@ main(int argc, const char** argv){ Vector<int> tmp; generate(tmp, 5); - + NDBT_TestSuite ts("testOperations"); - + + ts.setTemporaryTables(true); + for(Uint32 i = 0; i < 12; i++) { if(false && (i == 6 || i == 8 || i == 10)) diff --git a/storage/ndb/test/ndbapi/testTransactions.cpp b/storage/ndb/test/ndbapi/testTransactions.cpp index 3de088a5818..8552d1df6fb 100644 --- a/storage/ndb/test/ndbapi/testTransactions.cpp +++ b/storage/ndb/test/ndbapi/testTransactions.cpp @@ -372,6 +372,8 @@ main(int argc, const char** argv){ ndb_init(); NDBT_TestSuite ts("testOperations"); + ts.setTemporaryTables(true); + for(Uint32 i = 0; i<sizeof(matrix)/sizeof(matrix[0]); i++){ NDBT_TestCaseImpl1 *pt = new NDBT_TestCaseImpl1(&ts, matrix[i].name, ""); diff --git a/storage/ndb/test/run-test/daily-basic-tests.txt b/storage/ndb/test/run-test/daily-basic-tests.txt index ee669ba5f1c..f9551c8d526 100644 --- a/storage/ndb/test/run-test/daily-basic-tests.txt +++ b/storage/ndb/test/run-test/daily-basic-tests.txt @@ -646,7 +646,15 @@ args: max-time: 5000 cmd: testOIBasic -args: +args: -case abcdefz + +max-time: 2000 +cmd: testOIBasic +args: -case gz + +max-time: 2000 +cmd: testOIBasic +args: -case hz max-time: 2500 cmd: testBitfield diff --git a/storage/ndb/test/src/NDBT_Tables.cpp b/storage/ndb/test/src/NDBT_Tables.cpp index 520892f17da..3223edd351f 100644 --- a/storage/ndb/test/src/NDBT_Tables.cpp +++ b/storage/ndb/test/src/NDBT_Tables.cpp @@ -1039,6 +1039,11 @@ loop: j++; } j++; + if (tmpTab.getTemporary()) + { + tmpIndx.setTemporary(true); + tmpIndx.setLogging(false); + } if(pNdb->getDictionary()->createIndex(tmpIndx) != 0){ ndbout << pNdb->getDictionary()->getNdbError() << endl; return NDBT_FAILED; diff --git a/storage/ndb/test/src/NDBT_Test.cpp b/storage/ndb/test/src/NDBT_Test.cpp index 5bec0607255..37d1fa09691 100644 --- a/storage/ndb/test/src/NDBT_Test.cpp +++ b/storage/ndb/test/src/NDBT_Test.cpp @@ -770,6 +770,7 @@ NDBT_TestSuite::NDBT_TestSuite(const char* pname):name(pname){ diskbased = false; tsname = NULL; createAllTables = false; + temporaryTables = false; } @@ -791,6 +792,14 @@ void NDBT_TestSuite::setCreateAllTables(bool _flag){ createAllTables = _flag; } +void NDBT_TestSuite::setTemporaryTables(bool val){ + temporaryTables = val; +} + +bool NDBT_TestSuite::getTemporaryTables() const { + return temporaryTables; +} + bool NDBT_TestSuite::timerIsOn(){ return (timer != 0); } @@ -805,6 +814,7 @@ static int g_create_hook(Ndb* ndb, NdbDictionary::Table& tab, int when, void* arg) { NDBT_TestSuite* ts = (NDBT_TestSuite*)arg; + return ts->createHook(ndb, tab, when); } @@ -942,14 +952,23 @@ int NDBT_TestSuite::createHook(Ndb* ndb, NdbDictionary::Table& tab, int when) { if (when == 0) { - if (diskbased) { - for (int i = 0; i < tab.getNoOfColumns(); i++) { + if (diskbased) + { + for (int i = 0; i < tab.getNoOfColumns(); i++) + { NdbDictionary::Column* col = tab.getColumn(i); - if (! col->getPrimaryKey()) { + if (! col->getPrimaryKey()) + { col->setStorageType(NdbDictionary::Column::StorageTypeDisk); } } } + else if (temporaryTables) + { + tab.setTemporary(true); + tab.setLogging(false); + } + if (tsname != NULL) { tab.setTablespace(tsname); } diff --git a/storage/ndb/test/src/NdbBackup.cpp b/storage/ndb/test/src/NdbBackup.cpp index 42ebf31fc47..13572ede1a4 100644 --- a/storage/ndb/test/src/NdbBackup.cpp +++ b/storage/ndb/test/src/NdbBackup.cpp @@ -350,7 +350,8 @@ int FailS_codes[] = { 10025, 10027, - 10033 + 10033, + 10035 }; int @@ -362,7 +363,8 @@ FailM_codes[] = { 10027, 10028, 10031, - 10033 + 10033, + 10035 }; int diff --git a/storage/ndb/tools/ndb_size.pl b/storage/ndb/tools/ndb_size.pl index c285a7590fd..3d1ea3f4231 100644 --- a/storage/ndb/tools/ndb_size.pl +++ b/storage/ndb/tools/ndb_size.pl @@ -57,7 +57,7 @@ if(@ARGV < 3 || $ARGV[0] eq '--usage' || $ARGV[0] eq '--help') $template->param(dsn => $dsn); } -my @releases = ({rel=>'4.1'},{rel=>'5.0'},{rel=>'5.1'}); +my @releases = ({rel=>'4.1'},{rel=>'5.0'},{rel=>'5.1'}); #,{rel=>'5.1-dd'}); $template->param(releases => \@releases); my $tables = $dbh->selectall_arrayref("show tables"); @@ -81,25 +81,29 @@ sub align { return @aligned; } -foreach(@{$tables}) -{ - my $table= @{$_}[0]; +sub do_table { + my $table= shift; + my $info= shift; + my %indexes= %{$_[0]}; + my @count= @{$_[1]}; + my @columns; - my $info= $dbh->selectall_hashref('describe `'.$table.'`',"Field"); - my @count = $dbh->selectrow_array('select count(*) from `'.$table.'`'); my %columnsize; # used for index calculations - # We now work out the DataMemory usage - # sizes for 4.1, 5.0, 5.1 - my @totalsize= (0,0,0); + # sizes for 4.1, 5.0, 5.1 and 5.1-dd + my @totalsize= (0,0,0,0); + @totalsize= @totalsize[0..$#releases]; # limit to releases we're outputting + my $nrvarsize= 0; foreach(keys %$info) { - my @realsize = (0,0,0); + my @realsize = (0,0,0,0); + my @varsize = (0,0,0,0); my $type; my $size; my $name= $_; + my $is_varsize= 0; if($$info{$_}{Type} =~ /^(.*?)\((\d+)\)/) { @@ -112,54 +116,86 @@ foreach(@{$tables}) } if($type =~ /tinyint/) - {@realsize=(1,1,1)} + {@realsize=(1,1,1,1)} elsif($type =~ /smallint/) - {@realsize=(2,2,2)} + {@realsize=(2,2,2,2)} elsif($type =~ /mediumint/) - {@realsize=(3,3,3)} + {@realsize=(3,3,3,3)} elsif($type =~ /bigint/) - {@realsize=(8,8,8)} + {@realsize=(8,8,8,8)} elsif($type =~ /int/) - {@realsize=(4,4,4)} + {@realsize=(4,4,4,4)} elsif($type =~ /float/) { if($size<=24) - {@realsize=(4,4,4)} + {@realsize=(4,4,4,4)} else - {@realsize=(8,8,8)} + {@realsize=(8,8,8,8)} } elsif($type =~ /double/ || $type =~ /real/) - {@realsize=(8,8,8)} + {@realsize=(8,8,8,8)} elsif($type =~ /bit/) { my $a=($size+7)/8; - @realsize = ($a,$a,$a); + @realsize = ($a,$a,$a,$a); } elsif($type =~ /datetime/) - {@realsize=(8,8,8)} + {@realsize=(8,8,8,8)} elsif($type =~ /timestamp/) - {@realsize=(4,4,4)} + {@realsize=(4,4,4,4)} elsif($type =~ /date/ || $type =~ /time/) - {@realsize=(3,3,3)} + {@realsize=(3,3,3,3)} elsif($type =~ /year/) - {@realsize=(1,1,1)} + {@realsize=(1,1,1,1)} elsif($type =~ /varchar/ || $type =~ /varbinary/) { - my $fixed= 1+$size; + my $fixed=$size+ceil($size/256); my @dynamic=$dbh->selectrow_array("select avg(length(`" .$name ."`)) from `".$table.'`'); $dynamic[0]=0 if !$dynamic[0]; - @realsize= ($fixed,$fixed,ceil($dynamic[0])); + $dynamic[0]+=ceil($dynamic[0]/256); # size bit + $nrvarsize++; + $is_varsize= 1; + $varsize[3]= ceil($dynamic[0]); + @realsize= ($fixed,$fixed,ceil($dynamic[0]),$fixed); } elsif($type =~ /binary/ || $type =~ /char/) - {@realsize=($size,$size,$size)} + {@realsize=($size,$size,$size,$size)} elsif($type =~ /text/ || $type =~ /blob/) { - @realsize=(256,256,1); - $NoOfTables[$_]{val} += 1 foreach 0..$#releases; # blob uses table - } # FIXME check if 5.1 is correct + @realsize=(8+256,8+256,8+256,8+256); + + my $blobhunk= 2000; + $blobhunk= 8000 if $type=~ /longblob/; + $blobhunk= 4000 if $type=~ /mediumblob/; + + my @blobsize=$dbh->selectrow_array("select SUM(CEILING(". + "length(`$name`)/$blobhunk))". + "from `".$table."`"); + $blobsize[0]=0 if !defined($blobsize[0]); + #$NoOfTables[$_]{val} += 1 foreach 0..$#releases; # blob uses table + do_table($table."\$BLOB_$name", + {'PK'=>{Type=>'int'}, + 'DIST'=>{Type=>'int'}, + 'PART'=>{Type=>'int'}, + 'DATA'=>{Type=>"binary($blobhunk)"} + }, + {'PRIMARY' => { + 'unique' => 1, + 'comment' => '', + 'columns' => [ + 'PK', + 'DIST', + 'PART', + ], + 'type' => 'HASH' + } + }, + \@blobsize); + } + @realsize= @realsize[0..$#releases]; @realsize= align(4,@realsize); $totalsize[$_]+=$realsize[$_] foreach 0..$#totalsize; @@ -170,6 +206,7 @@ foreach(@{$tables}) push @columns, { name=>$name, type=>$type, + is_varsize=>$is_varsize, size=>$size, key=>$$info{$_}{Key}, datamemory=>\@realout, @@ -183,24 +220,10 @@ foreach(@{$tables}) # Firstly, we assemble some information about the indexes. # We use SHOW INDEX instead of using INFORMATION_SCHEMA so # we can still connect to pre-5.0 mysqlds. - my %indexes; - { - my $sth= $dbh->prepare("show index from `".$table.'`'); - $sth->execute; - while(my $i = $sth->fetchrow_hashref) - { - $indexes{${%$i}{Key_name}}= { - type=>${%$i}{Index_type}, - unique=>!${%$i}{Non_unique}, - comment=>${%$i}{Comment}, - } if !defined($indexes{${%$i}{Key_name}}); - - $indexes{${%$i}{Key_name}}{columns}[${%$i}{Seq_in_index}-1]= - ${%$i}{Column_name}; - } - } if(!defined($indexes{PRIMARY})) { + my @usage= ({val=>8},{val=>8},{val=>8},{val=>8}); + @usage= @usage[0..$#releases]; $indexes{PRIMARY}= { type=>'BTREE', unique=>1, @@ -212,20 +235,22 @@ foreach(@{$tables}) type=>'bigint', size=>8, key=>'PRI', - datamemory=>[{val=>8},{val=>8},{val=>8}], + datamemory=>\@usage, }; $columnsize{'HIDDEN_NDB_PKEY'}= [8,8,8]; } - my @IndexDataMemory= ({val=>0},{val=>0},{val=>0}); - my @RowIndexMemory= ({val=>0},{val=>0},{val=>0}); + my @IndexDataMemory= ({val=>0},{val=>0},{val=>0},{val=>0}); + my @RowIndexMemory= ({val=>0},{val=>0},{val=>0},{val=>0}); + @IndexDataMemory= @IndexDataMemory[0..$#releases]; + @RowIndexMemory= @RowIndexMemory[0..$#releases]; my @indexes; foreach my $index (keys %indexes) { my $im41= 25; $im41+=$columnsize{$_}[0] foreach @{$indexes{$index}{columns}}; - my @im = ({val=>$im41},{val=>25},{val=>25}); - my @dm = ({val=>10},{val=>10},{val=>10}); + my @im = ({val=>$im41},{val=>25},{val=>25}); #,{val=>25}); + my @dm = ({val=>10},{val=>10},{val=>10}); #,{val=>10}); push @indexes, { name=>$index, type=>$indexes{$index}{type}, @@ -233,13 +258,22 @@ foreach(@{$tables}) indexmemory=>\@im, datamemory=>\@dm, }; - $IndexDataMemory[$_]{val}+=$dm[$_]{val} foreach 0..2; - $RowIndexMemory[$_]{val}+=$im[$_]{val} foreach 0..2; + $IndexDataMemory[$_]{val}+=$dm[$_]{val} foreach 0..$#releases; + $RowIndexMemory[$_]{val}+=$im[$_]{val} foreach 0..$#releases; } # total size + 16 bytes overhead my @TotalDataMemory; - $TotalDataMemory[$_]{val}=$IndexDataMemory[$_]{val}+$totalsize[$_]+16 foreach 0..2; + my @RowOverhead = ({val=>16},{val=>16},{val=>16}); #,{val=>24}); + # 5.1 has ptr to varsize page, and per-varsize overhead + my @nrvarsize_mem= ({val=>0},{val=>0}, + {val=>8}); #,{val=>0}); + { + my @a= align(4,$nrvarsize*2); + $nrvarsize_mem[2]{val}+=$a[0]+$nrvarsize*4; + } + + $TotalDataMemory[$_]{val}=$IndexDataMemory[$_]{val}+$totalsize[$_]+$RowOverhead[$_]{val}+$nrvarsize_mem[$_]{val} foreach 0..$#releases; my @RowDataMemory; push @RowDataMemory,{val=>$_} foreach @totalsize; @@ -260,12 +294,18 @@ foreach(@{$tables}) my @counts; $counts[$_]{val}= $count foreach 0..$#releases; + my @nrvarsize_rel= ({val=>0},{val=>0}, + {val=>$nrvarsize}); #,{val=>0}); + push @table_size, { table=>$table, indexes=>\@indexes, columns=>\@columns, count=>\@counts, + RowOverhead=>\@RowOverhead, RowDataMemory=>\@RowDataMemory, + nrvarsize=>\@nrvarsize_rel, + nrvarsize_mem=>\@nrvarsize_mem, releases=>\@releases, IndexDataMemory=>\@IndexDataMemory, TotalDataMemory=>\@TotalDataMemory, @@ -283,6 +323,31 @@ foreach(@{$tables}) $NoOfIndexes[$_]{val} += @indexes foreach 0..$#releases; } +foreach(@{$tables}) +{ + my $table= @{$_}[0]; + my $info= $dbh->selectall_hashref('describe `'.$table.'`',"Field"); + my @count = $dbh->selectrow_array('select count(*) from `'.$table.'`'); + + my %indexes; + { + my $sth= $dbh->prepare("show index from `".$table.'`'); + $sth->execute; + while(my $i = $sth->fetchrow_hashref) + { + $indexes{${%$i}{Key_name}}= { + type=>${%$i}{Index_type}, + unique=>!${%$i}{Non_unique}, + comment=>${%$i}{Comment}, + } if !defined($indexes{${%$i}{Key_name}}); + + $indexes{${%$i}{Key_name}}{columns}[${%$i}{Seq_in_index}-1]= + ${%$i}{Column_name}; + } + } + do_table($table, $info, \%indexes, \@count); +} + my @NoOfTriggers; # for unique hash indexes $NoOfTriggers[$_]{val} += $NoOfIndexes[$_]{val}*3 foreach 0..$#releases; diff --git a/storage/ndb/tools/ndb_size.tmpl b/storage/ndb/tools/ndb_size.tmpl index dc02b5a5970..1e19ea132ba 100644 --- a/storage/ndb/tools/ndb_size.tmpl +++ b/storage/ndb/tools/ndb_size.tmpl @@ -15,6 +15,8 @@ td,th { border: 1px solid black } <p>This information should be valid for MySQL 4.1 and 5.0. Since 5.1 is not a final release yet, the numbers should be used as a guide only.</p> +<p>5.1-dd is for tables stored on disk. The ndb_size.pl estimates are <b>experimental</b> and should not be trusted. Notably we don't take into account indexed columns being in DataMemory versus non-indexed on disk.</p> + <h2>Parameter Settings</h2> <p><b>NOTE</b> the configuration parameters below do not take into account system tables and other requirements.</p> <table> @@ -69,6 +71,7 @@ td,th { border: 1px solid black } <tr> <th>Column</th> <th>Type</th> + <th>VARSIZE</th> <th>Size</th> <th>Key</th> <TMPL_LOOP NAME=releases> @@ -79,6 +82,7 @@ td,th { border: 1px solid black } <tr> <td><TMPL_VAR NAME=name></td> <td><TMPL_VAR NAME=type></td> + <td><TMPL_IF NAME=is_varsize>YES<TMPL_ELSE> </TMPL_IF></td> <td><TMPL_VAR NAME=size></td> <td><TMPL_VAR NAME=key></td> <TMPL_LOOP NAME=datamemory> @@ -129,9 +133,21 @@ td,th { border: 1px solid black } </TMPL_LOOP> </tr> <tr> + <th>Nr Varsized Attributes</th> + <TMPL_LOOP NAME=nrvarsize> + <td><TMPL_VAR NAME=val></td> + </TMPL_LOOP> +</tr> +<tr> <th>Row Overhead</th> - <TMPL_LOOP NAME=releases> - <td>16</td> + <TMPL_LOOP NAME=RowOverhead> + <td><TMPL_VAR NAME=val></td> + </TMPL_LOOP> +</tr> +<tr> + <th>Varsized Overhead</th> + <TMPL_LOOP NAME=nrvarsize_mem> + <td><TMPL_VAR NAME=val></td> </TMPL_LOOP> </tr> <tr> diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh index 29b19d86e89..60548210b7d 100644 --- a/support-files/mysql.spec.sh +++ b/support-files/mysql.spec.sh @@ -327,7 +327,7 @@ then cp -fp mysql-debug-%{mysql_version}/config.log "$MYSQL_DEBUGCONFLOG_DEST" fi -(cd mysql-debug-%{mysql_version} ; \ +(cd mysql-debug-%{mysql_version}/mysql-test ; \ ./mysql-test-run.pl --comment=debug --skip-rpl --skip-ndbcluster --force ; \ true) @@ -357,12 +357,13 @@ then cp -fp mysql-release-%{mysql_version}/config.log "$MYSQL_CONFLOG_DEST" fi -(cd mysql-release-%{mysql_version} ; \ - ./mysql-test-run.pl --comment=normal --force ; \ - ./mysql-test-run.pl --comment=ps --ps-protocol --force ; \ - ./mysql-test-run.pl --comment=normal+rowrepl --mysqld=--binlog-format=row --force ; \ - ./mysql-test-run.pl --comment=ps+rowrepl --ps-protocol --mysqld=--binlog-format=row --force ; \ - true) +cd mysql-release-%{mysql_version}/mysql-test +./mysql-test-run.pl --comment=normal --force --skip-ndbcluster --timer || true +./mysql-test-run.pl --comment=ps --ps-protocol --force --skip-ndbcluster --timer || true +./mysql-test-run.pl --comment=normal+rowrepl --mysqld=--binlog-format=row --force --skip-ndbcluster --timer || true +./mysql-test-run.pl --comment=ps+rowrepl+NDB --ps-protocol --mysqld=--binlog-format=row --force --timer || true +./mysql-test-run.pl --comment=NDB --with-ndbcluster-only --force --timer || true +cd ../.. ############################################################################## @@ -522,7 +523,6 @@ fi %doc %attr(644, root, man) %{_mandir}/man1/myisamchk.1* %doc %attr(644, root, man) %{_mandir}/man1/myisamlog.1* %doc %attr(644, root, man) %{_mandir}/man1/myisampack.1* -%doc %attr(644, root, man) %{_mandir}/man1/mysql_explain_log.1* %doc %attr(644, root, man) %{_mandir}/man8/mysqld.8* %doc %attr(644, root, man) %{_mandir}/man1/mysqld_multi.1* %doc %attr(644, root, man) %{_mandir}/man1/mysqld_safe.1* diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 148295398f4..624d9d9cce5 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -121,8 +121,9 @@ static void client_disconnect(); void die(const char *file, int line, const char *expr) { + fflush(stdout); fprintf(stderr, "%s:%d: check failed: '%s'\n", file, line, expr); - fflush(NULL); + fflush(stderr); abort(); } @@ -7496,10 +7497,22 @@ static void test_explain_bug() MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, 0, 0, "", 3, 0); - verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT", - mysql_get_server_version(mysql) <= 50000 ? - MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, - 0, 0, "", 64, 0); + if ( mysql_get_server_version(mysql) >= 50027 ) + { + /* The patch for bug#23037 changes column type of DEAULT to blob */ + verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT", + MYSQL_TYPE_BLOB, 0, 0, "", 0, 0); + } + else + { + verify_prepare_field(result, 4, "Default", "COLUMN_DEFAULT", + mysql_get_server_version(mysql) >= 50027 ? + MYSQL_TYPE_BLOB : + mysql_get_server_version(mysql) <= 50000 ? + MYSQL_TYPE_STRING : MYSQL_TYPE_VAR_STRING, + 0, 0, "", + mysql_get_server_version(mysql) >= 50027 ? 0 :64, 0); + } verify_prepare_field(result, 5, "Extra", "EXTRA", mysql_get_server_version(mysql) <= 50000 ? @@ -11977,6 +11990,19 @@ static void test_cursors_with_union() fetch_n(queries, sizeof(queries)/sizeof(*queries), USE_STORE_RESULT); } + +static void test_cursors_with_procedure() +{ + const char *queries[]= + { + "SELECT * FROM t1 procedure analyse()" + }; + myheader("test_cursors_with_procedure"); + fetch_n(queries, sizeof(queries)/sizeof(*queries), USE_ROW_BY_ROW_FETCH); + fetch_n(queries, sizeof(queries)/sizeof(*queries), USE_STORE_RESULT); +} + + /* Altough mysql_create_db(), mysql_rm_db() are deprecated since 4.0 they should not crash server and should not hang in case of errors. @@ -14454,6 +14480,7 @@ static void test_bug11718() printf("return type: %s", (res->fields[0].type == MYSQL_TYPE_DATE)?"DATE": "not DATE"); DIE_UNLESS(res->fields[0].type == MYSQL_TYPE_DATE); + mysql_free_result(res); rc= mysql_query(mysql, "drop table t1, t2"); myquery(rc); } @@ -14920,6 +14947,8 @@ static void test_bug15613() DIE_UNLESS(field[4].length == 255); DIE_UNLESS(field[5].length == 255); DIE_UNLESS(field[6].length == 255); + mysql_free_result(metadata); + mysql_stmt_free_result(stmt); /* III. Cleanup */ rc= mysql_query(mysql, "drop table t1"); @@ -15096,6 +15125,9 @@ static void test_bug14169() if (!opt_silent) printf("GROUP_CONCAT() result type %i", field[1].type); DIE_UNLESS(field[1].type == MYSQL_TYPE_BLOB); + mysql_free_result(res); + mysql_stmt_free_result(stmt); + mysql_stmt_close(stmt); rc= mysql_query(mysql, "drop table t1"); myquery(rc); @@ -15343,7 +15375,7 @@ static void test_bug15752() MYSQL mysql_local; int rc, i; const int ITERATION_COUNT= 100; - char *query= "CALL p1()"; + const char *query= "CALL p1()"; myheader("test_bug15752"); @@ -15702,6 +15734,7 @@ static struct my_tests_st my_tests[]= { { "test_view_insert_fields", test_view_insert_fields }, { "test_basic_cursors", test_basic_cursors }, { "test_cursors_with_union", test_cursors_with_union }, + { "test_cursors_with_procedure", test_cursors_with_procedure }, { "test_truncation", test_truncation }, { "test_truncation_option", test_truncation_option }, { "test_client_character_set", test_client_character_set }, diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index fceac951aff..29dc765950f 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -152,11 +152,19 @@ static signal_entry install_signal[]= { { SIGABRT, handle_core_signal }, { SIGFPE, handle_core_signal }, { SIGSEGV, handle_core_signal }, - { SIGBUS, handle_core_signal }, - { SIGXCPU, handle_core_signal }, - { SIGXFSZ, handle_core_signal }, - { SIGSYS, handle_core_signal }, - { SIGTRAP, handle_core_signal } + { SIGBUS, handle_core_signal } +#ifdef SIGXCPU + , { SIGXCPU, handle_core_signal } +#endif +#ifdef SIGXCPU + , { SIGXFSZ, handle_core_signal } +#endif +#ifdef SIGXCPU + , { SIGSYS, handle_core_signal } +#endif +#ifdef SIGXCPU + , { SIGTRAP, handle_core_signal } +#endif }; void diff --git a/vio/viossl.c b/vio/viossl.c index 180c7a50fa7..b5fd0e11c02 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -26,6 +26,10 @@ #ifdef HAVE_OPENSSL #ifdef __NETWARE__ + +/* yaSSL already uses BSD sockets */ +#ifndef HAVE_YASSL + /* The default OpenSSL implementation on NetWare uses WinSock. This code allows us to use the BSD sockets. @@ -47,6 +51,7 @@ static int SSL_set_fd_bsd(SSL *s, int fd) #define SSL_set_fd(A, B) SSL_set_fd_bsd((A), (B)) +#endif /* HAVE_YASSL */ #endif /* __NETWARE__ */ @@ -82,7 +87,7 @@ int vio_ssl_read(Vio *vio, gptr buf, int size) { int r; DBUG_ENTER("vio_ssl_read"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d, ssl_: 0x%p", + DBUG_PRINT("enter", ("sd: %d, buf: 0x%lx, size: %d, ssl_: 0x%lx", vio->sd, buf, size, vio->ssl_arg)); r= SSL_read((SSL*) vio->ssl_arg, buf, size); @@ -99,7 +104,7 @@ int vio_ssl_write(Vio *vio, const gptr buf, int size) { int r; DBUG_ENTER("vio_ssl_write"); - DBUG_PRINT("enter", ("sd: %d, buf: 0x%p, size: %d", vio->sd, buf, size)); + DBUG_PRINT("enter", ("sd: %d, buf: 0x%lx, size: %d", vio->sd, buf, size)); r= SSL_write((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c index ca7a96d5801..bce70078b3e 100644 --- a/vio/viosslfactories.c +++ b/vio/viosslfactories.c @@ -180,11 +180,15 @@ void netware_ssl_cleanup() /* free memory from SSL_library_init() */ EVP_cleanup(); +/* OpenSSL NetWare port specific functions */ +#ifndef HAVE_YASSL + /* free global X509 method */ X509_STORE_method_cleanup(); /* free the thread_hash error table */ ERR_free_state_table(); +#endif } |