From a5b881594da4258257b18cc42f5ce7be3524e02c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 20 Sep 2011 12:49:25 +0200 Subject: [PATCH 01/45] MWL#192: Non-blocking client API for libmysqlclient. All client functions that can block on I/O have alternate _start() and _cont() versions that do not block but return control back to the application, which can then issue I/O wait in its own fashion and later call back into the library to continue the operation. Works behind the scenes by spawning a co-routine/fiber to run the blocking operation and suspend it while waiting for I/O. This co-routine/fiber use is invisible to applications. For i368/x86_64 on GCC, uses very fast assembler co-routine support. On Windows uses native Win32 Fibers. Falls back to POSIX ucontext on other platforms. Assembler routines for more platforms are relatively easy to add by extending mysys/my_context.c, eg. similar to the Lua lcoco library. For testing, mysqltest and mysql_client_test are extended with the option --non-blocking-api. This causes the programs to use the non-blocking API for database access. mysql-test-run.pl has a similar option --non-blocking-api that uses this, as well as additional testcases. An example program tests/async_queries.c is included that uses the new non-blocking API with libevent to show how, in a single-threaded program, to issue many queries in parallel against a database. client/async_example.c: Fix const warning ****** Fix bug with wrong timeout value for poll(). include/Makefile.am: Fix missing include for `make dist` include/mysql.h: Add prototypes for all non-blocking API calls. include/mysql.h.pp: Add prototypes for all non-blocking API calls. mysys/my_context.c: Fix type warning for makecontext() function pointer argument. sql-common/mysql_async.c: Fix crashes in the non-blocking API for functions that can take MYSQL argument that is NULL. tests/Makefile.am: Add header file to `make dist` tests/mysql_client_test.c: Replace blocking calls with wrappers around the non-blocking calls, used in mysql_client_test to test the new non-blocking API. tests/nonblock-wrappers.h: Replace blocking calls with wrappers around the non-blocking calls, used in mysql_client_test to test the new non-blocking API. --- .bzrignore | 4 + client/CMakeLists.txt | 3 + client/Makefile.am | 7 + client/async_example.c | 207 +++ client/mysqltest.cc | 31 +- dbug/dbug.c | 50 + include/Makefile.am | 2 +- include/my_context.h | 222 +++ include/my_dbug.h | 2 + include/mysql.h | 160 +- include/mysql.h.pp | 137 +- include/sql_common.h | 11 + include/violite.h | 2 + libmysql/CMakeLists.txt | 3 +- libmysql/Makefile.shared | 5 +- libmysqld/CMakeLists.txt | 1 + libmysqld/Makefile.am | 2 +- mysql-test/mysql-test-run.pl | 8 + .../r/mysql_client_test_nonblock.result | 5 + mysql-test/r/non_blocking_api.result | 9 + .../t/mysql_client_test_nonblock-master.opt | 1 + mysql-test/t/mysql_client_test_nonblock.test | 23 + mysql-test/t/named_pipe.test | 2 + mysql-test/t/non_blocking_api.test | 18 + mysys/CMakeLists.txt | 1 + mysys/Makefile.am | 2 +- mysys/my_context.c | 749 +++++++++ server-tools/instance-manager/CMakeLists.txt | 3 +- server-tools/instance-manager/Makefile.am | 1 + sql-common/Makefile.am | 3 +- sql-common/client.c | 196 ++- sql-common/mysql_async.c | 1431 +++++++++++++++++ sql/CMakeLists.txt | 1 + sql/Makefile.am | 5 +- tests/Makefile.am | 8 + tests/async_queries.c | 435 +++++ tests/check_async_queries.pl | 73 + tests/mysql_client_test.c | 16 + tests/nonblock-wrappers.h | 514 ++++++ vio/viosocket.c | 59 +- vio/viossl.c | 15 +- 41 files changed, 4389 insertions(+), 38 deletions(-) create mode 100644 client/async_example.c create mode 100644 include/my_context.h create mode 100644 mysql-test/r/mysql_client_test_nonblock.result create mode 100644 mysql-test/r/non_blocking_api.result create mode 100644 mysql-test/t/mysql_client_test_nonblock-master.opt create mode 100644 mysql-test/t/mysql_client_test_nonblock.test create mode 100644 mysql-test/t/non_blocking_api.test create mode 100644 mysys/my_context.c create mode 100644 sql-common/mysql_async.c create mode 100644 tests/async_queries.c create mode 100644 tests/check_async_queries.pl create mode 100644 tests/nonblock-wrappers.h diff --git a/.bzrignore b/.bzrignore index 6b18d09723b..cd92df693fc 100644 --- a/.bzrignore +++ b/.bzrignore @@ -350,6 +350,7 @@ client/ssl_test client/thimble client/thread_test client/tmp.diff +client/async_example client_debug/* client_release/* client_test @@ -681,6 +682,7 @@ libmysqld/unireg.cc libmysqld/discover_xt.cc libmysqld/ha_pbxt.cc libmysqld/myxt_xt.cc +libmysqld/mysql_async.c libmysqltest/*.ds? libmysqltest/*.vcproj libmysqltest/mytest.c @@ -1867,6 +1869,7 @@ tests/bug25714 tests/client_test tests/connect_test tests/mysql_client_test +tests/async_queries thr_insert_test/* thr_test/* thread_test @@ -1952,6 +1955,7 @@ client/sql_list.cc client/sql_list.h libmysqld/client_plugin.c sql/client_plugin.c +sql/mysql_async.c *.dgcov libmysqld/create_options.cc storage/pbxt/bin/xtstat diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index ecfd3a0f0ce..53c445c21d8 100755 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -68,5 +68,8 @@ MYSQL_ADD_EXECUTABLE(mysqlslap mysqlslap.c DESTINATION bin) SET_SOURCE_FILES_PROPERTIES(mysqlslap.c PROPERTIES COMPILE_FLAGS "-DTHREADS") TARGET_LINK_LIBRARIES(mysqlslap mysqlclient mysys zlib wsock32 dbug) +MYSQL_ADD_EXECUTABLE(async_example async_example.c) +TARGET_LINK_LIBRARIES(async_example mysqlclient mysys zlib wsock32 dbug) + MYSQL_ADD_EXECUTABLE(echo echo.c COMPONENT Test) diff --git a/client/Makefile.am b/client/Makefile.am index f3f964ace7b..f4d9c8faf73 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -51,6 +51,8 @@ bin_PROGRAMS = mysql \ mysqltest \ mysql_upgrade +noinst_PROGRAMS = async_example + mysql_SOURCES = mysql.cc readline.cc sql_string.cc \ completion_hash.cc mysql_LDADD = @readline_link@ @TERMCAP_LIB@ \ @@ -96,6 +98,11 @@ mysqltest_LDADD = $(CXXLDFLAGS) $(CLIENT_THREAD_LIBS) \ mysql_upgrade_SOURCES= mysql_upgrade.c \ $(top_srcdir)/mysys/my_getpagesize.c +async_example_SOURCES= async_example.c +async_example_LDADD = $(CXXLDFLAGS) $(CLIENT_THREAD_LIBS) \ + @CLIENT_EXTRA_LDFLAGS@ \ + $(LIBMYSQLCLIENT_LA) + # Fix for mit-threads DEFS = -DMYSQL_CLIENT_NO_THREADS \ -DDEFAULT_MYSQL_HOME='"$(prefix)"' \ diff --git a/client/async_example.c b/client/async_example.c new file mode 100644 index 00000000000..de9d455171c --- /dev/null +++ b/client/async_example.c @@ -0,0 +1,207 @@ +/* + Copyright 2011 Kristian Nielsen and Monty Program Ab. + + Experiments with non-blocking libmysql. + + This 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 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. If not, see . +*/ + + +#ifndef __WIN__ +#include +#else +#include +#endif + +#include +#include +#include + +#define SL(s) (s), sizeof(s) + +static const char *my_groups[]= { "client", NULL }; + +static int +wait_for_mysql(MYSQL *mysql, int status) +{ +#ifdef __WIN__ + fd_set rs, ws, es; + int res; + struct timeval tv, *timeout; + my_socket s= mysql_get_socket(mysql); + FD_ZERO(&rs); + FD_ZERO(&ws); + FD_ZERO(&es); + if (status & MYSQL_WAIT_READ) + FD_SET(s, &rs); + if (status & MYSQL_WAIT_WRITE) + FD_SET(s, &ws); + if (status & MYSQL_WAIT_EXCEPT) + FD_SET(s, &es); + if (status & MYSQL_WAIT_TIMEOUT) + { + tv.tv_sec= mysql_get_timeout_value(mysql); + tv.tv_usec= 0; + timeout= &tv; + } + else + timeout= NULL; + res= select(1, &rs, &ws, &es, timeout); + if (res == 0) + return MYSQL_WAIT_TIMEOUT; + else if (res == SOCKET_ERROR) + { + /* + In a real event framework, we should handle errors and re-try the select. + */ + return MYSQL_WAIT_TIMEOUT; + } + else + { + int status= 0; + if (FD_ISSET(s, &rs)) + status|= MYSQL_WAIT_READ; + if (FD_ISSET(s, &ws)) + status|= MYSQL_WAIT_WRITE; + if (FD_ISSET(s, &es)) + status|= MYSQL_WAIT_EXCEPT; + return status; + } +#else + struct pollfd pfd; + int timeout; + int res; + + pfd.fd= mysql_get_socket(mysql); + pfd.events= + (status & MYSQL_WAIT_READ ? POLLIN : 0) | + (status & MYSQL_WAIT_WRITE ? POLLOUT : 0) | + (status & MYSQL_WAIT_EXCEPT ? POLLPRI : 0); + if (status & MYSQL_WAIT_TIMEOUT) + timeout= 1000*mysql_get_timeout_value(mysql); + else + timeout= -1; + res= poll(&pfd, 1, timeout); + if (res == 0) + return MYSQL_WAIT_TIMEOUT; + else if (res < 0) + { + /* + In a real event framework, we should handle EINTR and re-try the poll. + */ + return MYSQL_WAIT_TIMEOUT; + } + else + { + int status= 0; + if (pfd.revents & POLLIN) + status|= MYSQL_WAIT_READ; + if (pfd.revents & POLLOUT) + status|= MYSQL_WAIT_WRITE; + if (pfd.revents & POLLPRI) + status|= MYSQL_WAIT_EXCEPT; + return status; + } +#endif +} + +static void +fatal(MYSQL *mysql, const char *msg) +{ + fprintf(stderr, "%s: %s\n", msg, mysql_error(mysql)); + exit(1); +} + +static void +doit(const char *host, const char *user, const char *password) +{ + int err; + MYSQL mysql, *ret; + MYSQL_RES *res; + MYSQL_ROW row; + int status; + + mysql_init(&mysql); + mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "myapp"); + + /* Returns 0 when done, else flag for what to wait for when need to block. */ + status= mysql_real_connect_start(&ret, &mysql, host, user, password, NULL, + 0, NULL, 0); + while (status) + { + status= wait_for_mysql(&mysql, status); + status= mysql_real_connect_cont(&ret, &mysql, status); + } + + if (!ret) + fatal(&mysql, "Failed to mysql_real_connect()"); + + status= mysql_real_query_start(&err, &mysql, SL("SHOW STATUS")); + while (status) + { + status= wait_for_mysql(&mysql, status); + status= mysql_real_query_cont(&err, &mysql, status); + } + if (err) + fatal(&mysql, "mysql_real_query() returns error"); + + /* This method cannot block. */ + res= mysql_use_result(&mysql); + if (!res) + fatal(&mysql, "mysql_use_result() returns error"); + + for (;;) + { + status= mysql_fetch_row_start(&row, res); + while (status) + { + status= wait_for_mysql(&mysql, status); + status= mysql_fetch_row_cont(&row, res, status); + } + if (!row) + break; + printf("%s: %s\n", row[0], row[1]); + } + if (mysql_errno(&mysql)) + fatal(&mysql, "Got error while retrieving rows"); + mysql_free_result(res); + + /* I suppose this must be non-blocking too. */ + mysql_close(&mysql); +} + +int +main(int argc, char *argv[]) +{ + int err; + + if (argc != 4) + { + fprintf(stderr, "Usage: %s \n", argv[0]); + exit(1); + } + + err= mysql_library_init(argc, argv, (char **)my_groups); + if (err) + { + fprintf(stderr, "Fatal: mysql_library_init() returns error: %d\n", err); + exit(1); + } + + doit(argv[1], argv[2], argv[3]); + + mysql_library_end(); + + return 0; +} diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 772dd69c089..7aeaa48519d 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -60,6 +60,12 @@ #define SIGNAL_FMT "signal %d" #endif +static my_bool non_blocking_api_enabled= 0; +#if !defined(EMBEDDED_LIBRARY) +#define WRAP_NONBLOCK_ENABLED non_blocking_api_enabled +#include "../tests/nonblock-wrappers.h" +#endif + /* Use cygwin for --exec and --system before 5.0 */ #if MYSQL_VERSION_ID < 50000 #define USE_CYGWIN @@ -84,7 +90,7 @@ enum { OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL, OPT_MAX_CONNECT_RETRIES, OPT_MAX_CONNECTIONS, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES, - OPT_GLOBAL_SUBST, OPT_MY_CONNECT_TIMEOUT + OPT_GLOBAL_SUBST, OPT_MY_CONNECT_TIMEOUT, OPT_NON_BLOCKING_API }; static int record= 0, opt_sleep= -1; @@ -305,6 +311,7 @@ enum enum_commands { Q_LOWERCASE, Q_START_TIMER, Q_END_TIMER, Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL, + Q_ENABLE_NON_BLOCKING_API, Q_DISABLE_NON_BLOCKING_API, Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT, Q_IF, Q_DISABLE_PARSING, Q_ENABLE_PARSING, @@ -386,6 +393,8 @@ const char *command_names[]= "character_set", "disable_ps_protocol", "enable_ps_protocol", + "enable_non_blocking_api", + "disable_non_blocking_api", "disable_reconnect", "enable_reconnect", "if", @@ -5235,7 +5244,10 @@ void do_connect(struct st_command *command) int con_port= opt_port; char *con_options; my_bool con_ssl= 0, con_compress= 0; - my_bool con_pipe= 0, con_shm= 0; + my_bool con_pipe= 0; +#ifdef HAVE_SMEM + my_bool con_shm= 0; +#endif struct st_connection* con_slot; static DYNAMIC_STRING ds_connection_name; @@ -5324,7 +5336,11 @@ void do_connect(struct st_command *command) else if (length == 4 && !strncmp(con_options, "PIPE", 4)) con_pipe= 1; else if (length == 3 && !strncmp(con_options, "SHM", 3)) +#ifdef HAVE_SMEM con_shm= 1; +#else + { } +#endif else die("Illegal option to connect: %.*s", (int) (end - con_options), con_options); @@ -6146,6 +6162,10 @@ static struct my_option my_long_options[] = "Use prepared-statement protocol for communication.", &ps_protocol, &ps_protocol, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"non-blocking-api", OPT_NON_BLOCKING_API, + "Use the non-blocking client API for communication.", + &non_blocking_api_enabled, &non_blocking_api_enabled, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"quiet", 's', "Suppress all normal output.", &silent, &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"record", 'r', "Record output of test_file into result file.", @@ -8130,6 +8150,7 @@ int main(int argc, char **argv) next_con= connections + 1; var_set_int("$PS_PROTOCOL", ps_protocol); + var_set_int("$NON_BLOCKING_API", non_blocking_api_enabled); var_set_int("$SP_PROTOCOL", sp_protocol); var_set_int("$VIEW_PROTOCOL", view_protocol); var_set_int("$CURSOR_PROTOCOL", cursor_protocol); @@ -8538,6 +8559,12 @@ int main(int argc, char **argv) case Q_ENABLE_PS_PROTOCOL: ps_protocol_enabled= ps_protocol; break; + case Q_DISABLE_NON_BLOCKING_API: + non_blocking_api_enabled= 0; + break; + case Q_ENABLE_NON_BLOCKING_API: + non_blocking_api_enabled= 1; + break; case Q_DISABLE_RECONNECT: set_reconnect(cur_con->mysql, 0); break; diff --git a/dbug/dbug.c b/dbug/dbug.c index 0ea0b0df6ad..6fa7da37504 100644 --- a/dbug/dbug.c +++ b/dbug/dbug.c @@ -404,6 +404,27 @@ static CODE_STATE *code_state(void) return cs; } +void +dbug_swap_code_state(void **code_state_store) +{ + CODE_STATE *cs, **cs_ptr; + + if (!(cs_ptr= (CODE_STATE**) my_thread_var_dbug())) + return; + cs= *cs_ptr; + *cs_ptr= *code_state_store; + *code_state_store= cs; +} + +void dbug_free_code_state(void **code_state_store) +{ + if (*code_state_store) + { + free(*code_state_store); + *code_state_store= NULL; + } +} + #else /* !THREAD */ static CODE_STATE static_code_state= @@ -424,6 +445,35 @@ static CODE_STATE *code_state(void) return &static_code_state; } +void +dbug_swap_code_state(void **code_state_store) +{ + CODE_STATE temp, *cs; + + if (!(cs= *code_state_store)) + { + cs= (CODE_STATE *)DbugMalloc(sizeof(*cs)); + cs->process= db_process ? db_process : "dbug"; + cs->func="?func"; + cs->file="?file"; + cs->stack=&init_settings; + *code_state_store= cs; + } + memcpy(&temp, cs, sizeof(*cs)); + memcpy(cs, &static_code_state, sizeof(*cs)); + memcpy(&static_code_state, &temp, sizeof(*cs)); +} + +void +dbug_free_code_state(void **code_state_store) +{ + if (*code_state_store) + { + free(*code_state_store); + *code_state_store= NULL; + } +} + #define pthread_mutex_lock(A) {} #define pthread_mutex_unlock(A) {} #endif diff --git a/include/Makefile.am b/include/Makefile.am index e23fd94a7fc..e13e7755670 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -46,7 +46,7 @@ noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \ atomic/rwlock.h atomic/x86-gcc.h \ atomic/generic-msvc.h \ atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ - wqueue.h waiting_threads.h + wqueue.h waiting_threads.h my_context.h EXTRA_DIST = mysql.h.pp mysql/plugin_auth.h.pp mysql/client_plugin.h.pp CMakeLists.txt diff --git a/include/my_context.h b/include/my_context.h new file mode 100644 index 00000000000..e19ee89a8be --- /dev/null +++ b/include/my_context.h @@ -0,0 +1,222 @@ +/* + Copyright 2011 Kristian Nielsen + + Experiments with non-blocking libmysql. + + This 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 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. If not, see . +*/ + +/* + Simple API for spawning a co-routine, to be used for async libmysqlclient. + + Idea is that by implementing this interface using whatever facilities are + available for given platform, we can use the same code for the generic + libmysqlclient-async code. + + (This particular implementation uses Posix ucontext swapcontext().) +*/ + +#ifdef __WIN__ +#define MY_CONTEXT_USE_WIN32_FIBERS 1 +#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__x86_64__) +#define MY_CONTEXT_USE_X86_64_GCC_ASM +#elif defined(__GNUC__) && __GNUC__ >= 3 && defined(__i386__) +#define MY_CONTEXT_USE_I386_GCC_ASM +#else +#define MY_CONTEXT_USE_UCONTEXT +#endif + +#ifdef MY_CONTEXT_USE_WIN32_FIBERS +struct my_context { + void (*user_func)(void *); + void *user_arg; + void *app_fiber; + void *lib_fiber; + int return_value; +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_UCONTEXT +#include + +struct my_context { + void (*user_func)(void *); + void *user_data; + void *stack; + size_t stack_size; + ucontext_t base_context; + ucontext_t spawned_context; + int active; +#ifdef HAVE_VALGRIND_VALGRIND_H + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_X86_64_GCC_ASM +#include + +struct my_context { + uint64_t save[9]; + void *stack_top; + void *stack_bot; +#ifdef HAVE_VALGRIND_VALGRIND_H + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +#ifdef MY_CONTEXT_USE_I386_GCC_ASM +#include + +struct my_context { + uint64_t save[7]; + void *stack_top; + void *stack_bot; +#ifdef HAVE_VALGRIND_VALGRIND_H + unsigned int valgrind_stack_id; +#endif +#ifndef DBUG_OFF + void *dbug_state; +#endif +}; +#endif + + +/* + Initialize an asynchroneous context object. + Returns 0 on success, non-zero on failure. +*/ +extern int my_context_init(struct my_context *c, size_t stack_size); + +/* Free an asynchroneous context object, deallocating any resources used. */ +extern void my_context_destroy(struct my_context *c); + +/* + Spawn an asynchroneous context. The context will run the supplied user + function, passing the supplied user data pointer. + + The context must have been initialised with my_context_init() prior to + this call. + + The user function may call my_context_yield(), which will cause this + function to return 1. Then later my_context_continue() may be called, which + will resume the asynchroneous context by returning from the previous + my_context_yield() call. + + When the user function returns, this function returns 0. + + In case of error, -1 is returned. +*/ +extern int my_context_spawn(struct my_context *c, void (*f)(void *), void *d); + +/* + Suspend an asynchroneous context started with my_context_spawn. + + When my_context_yield() is called, execution immediately returns from the + last my_context_spawn() or my_context_continue() call. Then when later + my_context_continue() is called, execution resumes by returning from this + my_context_yield() call. + + Returns 0 if ok, -1 in case of error. +*/ +extern int my_context_yield(struct my_context *c); + +/* + Resume an asynchroneous context. The context was spawned by + my_context_spawn(), and later suspended inside my_context_yield(). + + The asynchroneous context may be repeatedly suspended with + my_context_yield() and resumed with my_context_continue(). + + Each time it is suspended, this function returns 1. When the originally + spawned user function returns, this function returns 0. + + In case of error, -1 is returned. +*/ +extern int my_context_continue(struct my_context *c); + + +struct mysql_async_context { + /* + This is set to the value that should be returned from foo_start() or + foo_cont() when a call is suspended. + It is also set to the event(s) that triggered when a suspended call is + resumed, eg. whether we woke up due to connection completed or timeout + in mysql_real_connect_cont(). + */ + unsigned int ret_status; + /* + This is set to the result of the whole asynchronous operation when it + completes. It uses a union, as different calls have different return + types. + */ + union { + void *r_ptr; + const void *r_const_ptr; + int r_int; + my_bool r_my_bool; + } ret_result; + /* + The timeout value, for suspended calls that need to wake up on a timeout + (eg. mysql_real_connect_start(). + */ + unsigned int timeout_value; + /* + This flag is set when we are executing inside some asynchronous call + foo_start() or foo_cont(). It is used to decide whether to use the + synchronous or asynchronous version of calls that may block such as + recv(). + + Note that this flag is not set when a call is suspended, eg. after + returning from foo_start() and before re-entering foo_cont(). + */ + my_bool active; + /* + This flag is set when an asynchronous operation is in progress, but + suspended. Ie. it is set when foo_start() or foo_cont() returns because + the operation needs to block, suspending the operation. + + It is used to give an error (rather than crash) if the application + attempts to call some foo_cont() method when no suspended operation foo is + in progress. + */ + my_bool suspended; + /* + If non-NULL, this is a pointer to a callback hook that will be invoked with + the user data argument just before the context is suspended, and just after + it is resumed. + */ + void (*suspend_resume_hook)(my_bool suspend, void *user_data); + void *suspend_resume_hook_user_data; + /* + This is used to save the execution contexts so that we can suspend an + operation and switch back to the application context, to resume the + suspended context later when the application re-invokes us with + foo_cont(). + */ + struct my_context async_context; +}; diff --git a/include/my_dbug.h b/include/my_dbug.h index ef30c95e32a..a58c6588d61 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -83,6 +83,8 @@ extern void _db_lock_file_(void); extern void _db_unlock_file_(void); extern FILE *_db_fp_(void); extern void _db_flush_(); +extern void dbug_swap_code_state(void **code_state_store); +extern void dbug_free_code_state(void **code_state_store); #ifdef __cplusplus diff --git a/include/mysql.h b/include/mysql.h index 19aab89283b..b1ef4720879 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -264,6 +264,8 @@ typedef struct character_set struct st_mysql_methods; struct st_mysql_stmt; +struct st_mysql_extension; + typedef struct st_mysql { NET net; /* Communication parameters */ @@ -318,7 +320,7 @@ typedef struct st_mysql my_bool *unbuffered_fetch_owner; /* needed for embedded server - no net buffer to store the 'info' */ char *info_buffer; - void *extension; + struct st_mysql_extension *extension; } MYSQL; @@ -376,6 +378,19 @@ typedef struct st_mysql_parameters void *extension; } MYSQL_PARAMETERS; +/* + Flag bits, the asynchronous methods return a combination of these ORed + together to let the application know when to resume the suspended operation. +*/ +typedef enum { + MYSQL_WAIT_READ= 1, /* Wait for data to be available on socket to read */ + /* mysql_get_socket_fd() will return socket descriptor*/ + MYSQL_WAIT_WRITE= 2, /* Wait for socket to be ready to write data */ + MYSQL_WAIT_EXCEPT= 4, /* Wait for select() to mark exception on socket */ + MYSQL_WAIT_TIMEOUT= 8 /* Wait until timeout occurs. Value of timeout can be */ + /* obtained from mysql_get_timeout_value() */ +} MYSQL_ASYNC_STATUS; + #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY) #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet) #define net_buffer_length (*mysql_get_parameters()->p_net_buffer_length) @@ -437,6 +452,10 @@ const char * STDCALL mysql_info(MYSQL *mysql); unsigned long STDCALL mysql_thread_id(MYSQL *mysql); const char * STDCALL mysql_character_set_name(MYSQL *mysql); int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname); +int STDCALL mysql_set_character_set_start(int *ret, MYSQL *mysql, + const char *csname); +int STDCALL mysql_set_character_set_cont(int *ret, MYSQL *mysql, + int status); MYSQL * STDCALL mysql_init(MYSQL *mysql); my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, @@ -445,6 +464,12 @@ my_bool STDCALL mysql_ssl_set(MYSQL *mysql, const char *key, const char * STDCALL mysql_get_ssl_cipher(MYSQL *mysql); my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db); +int STDCALL mysql_change_user_start(my_bool *ret, MYSQL *mysql, + const char *user, + const char *passwd, + const char *db); +int STDCALL mysql_change_user_cont(my_bool *ret, MYSQL *mysql, + int status); MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, @@ -452,13 +477,44 @@ MYSQL * STDCALL mysql_real_connect(MYSQL *mysql, const char *host, unsigned int port, const char *unix_socket, unsigned long clientflag); +int STDCALL mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, + const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long clientflag); +int STDCALL mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, + int status); int STDCALL mysql_select_db(MYSQL *mysql, const char *db); +int STDCALL mysql_select_db_start(int *ret, MYSQL *mysql, + const char *db); +int STDCALL mysql_select_db_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_query(MYSQL *mysql, const char *q); +int STDCALL mysql_query_start(int *ret, MYSQL *mysql, + const char *q); +int STDCALL mysql_query_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_send_query(MYSQL *mysql, const char *q, unsigned long length); +int STDCALL mysql_send_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int STDCALL mysql_send_query_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_real_query(MYSQL *mysql, const char *q, unsigned long length); +int STDCALL mysql_real_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int STDCALL mysql_real_query_cont(int *ret, MYSQL *mysql, + int status); MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); +int STDCALL mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql); +int STDCALL mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); /* perform query on master */ @@ -526,15 +582,39 @@ int STDCALL mysql_add_slave(MYSQL* mysql, const char* host, int STDCALL mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level); +int STDCALL mysql_shutdown_start(int *ret, MYSQL *mysql, + enum mysql_enum_shutdown_level + shutdown_level); +int STDCALL mysql_shutdown_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_dump_debug_info(MYSQL *mysql); +int STDCALL mysql_dump_debug_info_start(int *ret, MYSQL *mysql); +int STDCALL mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_refresh(MYSQL *mysql, unsigned int refresh_options); +int STDCALL mysql_refresh_start(int *ret, MYSQL *mysql, + unsigned int refresh_options); +int STDCALL mysql_refresh_cont(int *ret, MYSQL *mysql, int status); int STDCALL mysql_kill(MYSQL *mysql,unsigned long pid); +int STDCALL mysql_kill_start(int *ret, MYSQL *mysql, + unsigned long pid); +int STDCALL mysql_kill_cont(int *ret, MYSQL *mysql, int status); int STDCALL mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option); +int STDCALL mysql_set_server_option_start(int *ret, MYSQL *mysql, + enum enum_mysql_set_option + option); +int STDCALL mysql_set_server_option_cont(int *ret, MYSQL *mysql, + int status); int STDCALL mysql_ping(MYSQL *mysql); +int STDCALL mysql_ping_start(int *ret, MYSQL *mysql); +int STDCALL mysql_ping_cont(int *ret, MYSQL *mysql, int status); const char * STDCALL mysql_stat(MYSQL *mysql); +int STDCALL mysql_stat_start(const char **ret, MYSQL *mysql); +int STDCALL mysql_stat_cont(const char **ret, MYSQL *mysql, + int status); const char * STDCALL mysql_get_server_info(MYSQL *mysql); const char * STDCALL mysql_get_server_name(MYSQL *mysql); const char * STDCALL mysql_get_client_info(void); @@ -543,11 +623,25 @@ const char * STDCALL mysql_get_host_info(MYSQL *mysql); unsigned long STDCALL mysql_get_server_version(MYSQL *mysql); unsigned int STDCALL mysql_get_proto_info(MYSQL *mysql); MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild); +int STDCALL mysql_list_dbs_start(MYSQL_RES **ret, MYSQL *mysql, + const char *wild); +int STDCALL mysql_list_dbs_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql,const char *wild); +int STDCALL mysql_list_tables_start(MYSQL_RES **ret, MYSQL *mysql, + const char *wild); +int STDCALL mysql_list_tables_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * STDCALL mysql_list_processes(MYSQL *mysql); +int STDCALL mysql_list_processes_start(MYSQL_RES **ret, + MYSQL *mysql); +int STDCALL mysql_list_processes_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg); void STDCALL mysql_free_result(MYSQL_RES *result); +int STDCALL mysql_free_result_start(MYSQL_RES *result); +int STDCALL mysql_free_result_cont(MYSQL_RES *result, int status); void STDCALL mysql_data_seek(MYSQL_RES *result, my_ulonglong offset); MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, @@ -555,10 +649,19 @@ MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset); MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result); +int STDCALL mysql_fetch_row_start(MYSQL_ROW *ret, + MYSQL_RES *result); +int STDCALL mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, + int status); unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result); MYSQL_FIELD * STDCALL mysql_fetch_field(MYSQL_RES *result); MYSQL_RES * STDCALL mysql_list_fields(MYSQL *mysql, const char *table, const char *wild); +int STDCALL mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, + const char *table, + const char *wild); +int STDCALL mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); unsigned long STDCALL mysql_escape_string(char *to,const char *from, unsigned long from_length); unsigned long STDCALL mysql_hex_string(char *to,const char *from, @@ -584,6 +687,10 @@ int STDCALL mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf, int res_buf_size); my_bool STDCALL mysql_read_query_result(MYSQL *mysql); +int STDCALL mysql_read_query_result_start(my_bool *ret, + MYSQL *mysql); +int STDCALL mysql_read_query_result_cont(my_bool *ret, + MYSQL *mysql, int status); /* @@ -760,16 +867,25 @@ enum enum_stmt_attr_type STMT_ATTR_PREFETCH_ROWS }; - MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql); int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length); +int STDCALL mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt, + const char *query, unsigned long length); +int STDCALL mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int status); int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int status); int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int status); int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset); int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt, + int status); unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT * stmt); my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, @@ -780,12 +896,25 @@ my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool STDCALL mysql_stmt_close(MYSQL_STMT * stmt); +int STDCALL mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status); my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt); +int STDCALL mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt); +int STDCALL mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status); my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt); +int STDCALL mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt); +int STDCALL mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length); +int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, + unsigned int param_number, + const char *data, + unsigned long len); +int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); MYSQL_RES *STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt); MYSQL_RES *STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt); unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT * stmt); @@ -801,12 +930,24 @@ my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt); unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt); my_bool STDCALL mysql_commit(MYSQL * mysql); +int STDCALL mysql_commit_start(my_bool *ret, MYSQL * mysql); +int STDCALL mysql_commit_cont(my_bool *ret, MYSQL * mysql, int status); my_bool STDCALL mysql_rollback(MYSQL * mysql); +int STDCALL mysql_rollback_start(my_bool *ret, MYSQL * mysql); +int STDCALL mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status); my_bool STDCALL mysql_autocommit(MYSQL * mysql, my_bool auto_mode); +int STDCALL mysql_autocommit_start(my_bool *ret, MYSQL * mysql, + my_bool auto_mode); +int STDCALL mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status); my_bool STDCALL mysql_more_results(MYSQL *mysql); int STDCALL mysql_next_result(MYSQL *mysql); +int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql); +int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status); void STDCALL mysql_close(MYSQL *sock); - +int STDCALL mysql_close_start(MYSQL *sock); +int STDCALL mysql_close_cont(MYSQL *sock, int status); +my_socket STDCALL mysql_get_socket(const MYSQL *mysql); +unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql); /* status return codes */ #define MYSQL_NO_DATA 100 @@ -817,7 +958,20 @@ void STDCALL mysql_close(MYSQL *sock); #ifdef USE_OLD_FUNCTIONS MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd); +int STDCALL mysql_connect_start(MYSQL **ret, MYSQL *mysql, + const char *host, const char *user, + const char *passwd); +int STDCALL mysql_connect_cont(MYSQL **ret, MYSQL *mysql, + int status); int STDCALL mysql_create_db(MYSQL *mysql, const char *DB); +int STDCALL mysql_create_db_start(int *ret, MYSQL *mysql, + const char *DB); +int STDCALL mysql_create_db_cont(int *ret, MYSQL *mysql, + int status); +int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); +int STDCALL mysql_drop_db_start(int *ret, MYSQL *mysql, + const char *DB); +int STDCALL mysql_drop_db_cont(int *ret, MYSQL *mysql, int status); int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT) #endif diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 6e71f886eba..f66d92c06a1 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -318,6 +318,7 @@ typedef struct character_set } MY_CHARSET_INFO; struct st_mysql_methods; struct st_mysql_stmt; +struct st_mysql_extension; typedef struct st_mysql { NET net; @@ -353,7 +354,7 @@ typedef struct st_mysql void *thd; my_bool *unbuffered_fetch_owner; char *info_buffer; - void *extension; + struct st_mysql_extension *extension; } MYSQL; typedef struct st_mysql_res { my_ulonglong row_count; @@ -391,6 +392,12 @@ typedef struct st_mysql_parameters unsigned long *p_net_buffer_length; void *extension; } MYSQL_PARAMETERS; +typedef enum { + MYSQL_WAIT_READ= 1, + MYSQL_WAIT_WRITE= 2, + MYSQL_WAIT_EXCEPT= 4, + MYSQL_WAIT_TIMEOUT= 8 +} MYSQL_ASYNC_STATUS; int mysql_server_init(int argc, char **argv, char **groups); void mysql_server_end(void); MYSQL_PARAMETERS * mysql_get_parameters(void); @@ -415,6 +422,10 @@ const char * mysql_info(MYSQL *mysql); unsigned long mysql_thread_id(MYSQL *mysql); const char * mysql_character_set_name(MYSQL *mysql); int mysql_set_character_set(MYSQL *mysql, const char *csname); +int mysql_set_character_set_start(int *ret, MYSQL *mysql, + const char *csname); +int mysql_set_character_set_cont(int *ret, MYSQL *mysql, + int status); MYSQL * mysql_init(MYSQL *mysql); my_bool mysql_ssl_set(MYSQL *mysql, const char *key, const char *cert, const char *ca, @@ -422,6 +433,12 @@ my_bool mysql_ssl_set(MYSQL *mysql, const char *key, const char * mysql_get_ssl_cipher(MYSQL *mysql); my_bool mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db); +int mysql_change_user_start(my_bool *ret, MYSQL *mysql, + const char *user, + const char *passwd, + const char *db); +int mysql_change_user_cont(my_bool *ret, MYSQL *mysql, + int status); MYSQL * mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, @@ -429,13 +446,44 @@ MYSQL * mysql_real_connect(MYSQL *mysql, const char *host, unsigned int port, const char *unix_socket, unsigned long clientflag); +int mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, + const char *host, + const char *user, + const char *passwd, + const char *db, + unsigned int port, + const char *unix_socket, + unsigned long clientflag); +int mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, + int status); int mysql_select_db(MYSQL *mysql, const char *db); +int mysql_select_db_start(int *ret, MYSQL *mysql, + const char *db); +int mysql_select_db_cont(int *ret, MYSQL *mysql, + int status); int mysql_query(MYSQL *mysql, const char *q); +int mysql_query_start(int *ret, MYSQL *mysql, + const char *q); +int mysql_query_cont(int *ret, MYSQL *mysql, + int status); int mysql_send_query(MYSQL *mysql, const char *q, unsigned long length); +int mysql_send_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int mysql_send_query_cont(int *ret, MYSQL *mysql, + int status); int mysql_real_query(MYSQL *mysql, const char *q, unsigned long length); +int mysql_real_query_start(int *ret, MYSQL *mysql, + const char *q, + unsigned long length); +int mysql_real_query_cont(int *ret, MYSQL *mysql, + int status); MYSQL_RES * mysql_store_result(MYSQL *mysql); +int mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql); +int mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * mysql_use_result(MYSQL *mysql); my_bool mysql_master_query(MYSQL *mysql, const char *q, unsigned long length); @@ -478,15 +526,39 @@ int mysql_add_slave(MYSQL* mysql, const char* host, int mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level); +int mysql_shutdown_start(int *ret, MYSQL *mysql, + enum mysql_enum_shutdown_level + shutdown_level); +int mysql_shutdown_cont(int *ret, MYSQL *mysql, + int status); int mysql_dump_debug_info(MYSQL *mysql); +int mysql_dump_debug_info_start(int *ret, MYSQL *mysql); +int mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, + int status); int mysql_refresh(MYSQL *mysql, unsigned int refresh_options); +int mysql_refresh_start(int *ret, MYSQL *mysql, + unsigned int refresh_options); +int mysql_refresh_cont(int *ret, MYSQL *mysql, int status); int mysql_kill(MYSQL *mysql,unsigned long pid); +int mysql_kill_start(int *ret, MYSQL *mysql, + unsigned long pid); +int mysql_kill_cont(int *ret, MYSQL *mysql, int status); int mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option); +int mysql_set_server_option_start(int *ret, MYSQL *mysql, + enum enum_mysql_set_option + option); +int mysql_set_server_option_cont(int *ret, MYSQL *mysql, + int status); int mysql_ping(MYSQL *mysql); +int mysql_ping_start(int *ret, MYSQL *mysql); +int mysql_ping_cont(int *ret, MYSQL *mysql, int status); const char * mysql_stat(MYSQL *mysql); +int mysql_stat_start(const char **ret, MYSQL *mysql); +int mysql_stat_cont(const char **ret, MYSQL *mysql, + int status); const char * mysql_get_server_info(MYSQL *mysql); const char * mysql_get_server_name(MYSQL *mysql); const char * mysql_get_client_info(void); @@ -495,11 +567,25 @@ const char * mysql_get_host_info(MYSQL *mysql); unsigned long mysql_get_server_version(MYSQL *mysql); unsigned int mysql_get_proto_info(MYSQL *mysql); MYSQL_RES * mysql_list_dbs(MYSQL *mysql,const char *wild); +int mysql_list_dbs_start(MYSQL_RES **ret, MYSQL *mysql, + const char *wild); +int mysql_list_dbs_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * mysql_list_tables(MYSQL *mysql,const char *wild); +int mysql_list_tables_start(MYSQL_RES **ret, MYSQL *mysql, + const char *wild); +int mysql_list_tables_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); MYSQL_RES * mysql_list_processes(MYSQL *mysql); +int mysql_list_processes_start(MYSQL_RES **ret, + MYSQL *mysql); +int mysql_list_processes_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); int mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg); void mysql_free_result(MYSQL_RES *result); +int mysql_free_result_start(MYSQL_RES *result); +int mysql_free_result_cont(MYSQL_RES *result, int status); void mysql_data_seek(MYSQL_RES *result, my_ulonglong offset); MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES *result, @@ -507,10 +593,19 @@ MYSQL_ROW_OFFSET mysql_row_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET mysql_field_seek(MYSQL_RES *result, MYSQL_FIELD_OFFSET offset); MYSQL_ROW mysql_fetch_row(MYSQL_RES *result); +int mysql_fetch_row_start(MYSQL_ROW *ret, + MYSQL_RES *result); +int mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, + int status); unsigned long * mysql_fetch_lengths(MYSQL_RES *result); MYSQL_FIELD * mysql_fetch_field(MYSQL_RES *result); MYSQL_RES * mysql_list_fields(MYSQL *mysql, const char *table, const char *wild); +int mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, + const char *table, + const char *wild); +int mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, + int status); unsigned long mysql_escape_string(char *to,const char *from, unsigned long from_length); unsigned long mysql_hex_string(char *to,const char *from, @@ -536,6 +631,10 @@ int mysql_manager_fetch_line(MYSQL_MANAGER* con, char* res_buf, int res_buf_size); my_bool mysql_read_query_result(MYSQL *mysql); +int mysql_read_query_result_start(my_bool *ret, + MYSQL *mysql); +int mysql_read_query_result_cont(my_bool *ret, + MYSQL *mysql, int status); enum enum_mysql_stmt_state { MYSQL_STMT_INIT_DONE= 1, MYSQL_STMT_PREPARE_DONE, MYSQL_STMT_EXECUTE_DONE, @@ -605,12 +704,22 @@ enum enum_stmt_attr_type MYSQL_STMT * mysql_stmt_init(MYSQL *mysql); int mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, unsigned long length); +int mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt, + const char *query, unsigned long length); +int mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int status); int mysql_stmt_execute(MYSQL_STMT *stmt); +int mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt); +int mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int status); int mysql_stmt_fetch(MYSQL_STMT *stmt); +int mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt); +int mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int status); int mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind_arg, unsigned int column, unsigned long offset); int mysql_stmt_store_result(MYSQL_STMT *stmt); +int mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt); +int mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt, + int status); unsigned long mysql_stmt_param_count(MYSQL_STMT * stmt); my_bool mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, @@ -621,12 +730,25 @@ my_bool mysql_stmt_attr_get(MYSQL_STMT *stmt, my_bool mysql_stmt_bind_param(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool mysql_stmt_bind_result(MYSQL_STMT * stmt, MYSQL_BIND * bnd); my_bool mysql_stmt_close(MYSQL_STMT * stmt); +int mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt); +int mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status); my_bool mysql_stmt_reset(MYSQL_STMT * stmt); +int mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt); +int mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status); my_bool mysql_stmt_free_result(MYSQL_STMT *stmt); +int mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt); +int mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); my_bool mysql_stmt_send_long_data(MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length); +int mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, + unsigned int param_number, + const char *data, + unsigned long len); +int mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, + int status); MYSQL_RES * mysql_stmt_result_metadata(MYSQL_STMT *stmt); MYSQL_RES * mysql_stmt_param_metadata(MYSQL_STMT *stmt); unsigned int mysql_stmt_errno(MYSQL_STMT * stmt); @@ -641,8 +763,21 @@ my_ulonglong mysql_stmt_affected_rows(MYSQL_STMT *stmt); my_ulonglong mysql_stmt_insert_id(MYSQL_STMT *stmt); unsigned int mysql_stmt_field_count(MYSQL_STMT *stmt); my_bool mysql_commit(MYSQL * mysql); +int mysql_commit_start(my_bool *ret, MYSQL * mysql); +int mysql_commit_cont(my_bool *ret, MYSQL * mysql, int status); my_bool mysql_rollback(MYSQL * mysql); +int mysql_rollback_start(my_bool *ret, MYSQL * mysql); +int mysql_rollback_cont(my_bool *ret, MYSQL * mysql, int status); my_bool mysql_autocommit(MYSQL * mysql, my_bool auto_mode); +int mysql_autocommit_start(my_bool *ret, MYSQL * mysql, + my_bool auto_mode); +int mysql_autocommit_cont(my_bool *ret, MYSQL * mysql, int status); my_bool mysql_more_results(MYSQL *mysql); int mysql_next_result(MYSQL *mysql); +int mysql_next_result_start(int *ret, MYSQL *mysql); +int mysql_next_result_cont(int *ret, MYSQL *mysql, int status); void mysql_close(MYSQL *sock); +int mysql_close_start(MYSQL *sock); +int mysql_close_cont(MYSQL *sock, int status); +my_socket mysql_get_socket(const MYSQL *mysql); +unsigned int mysql_get_timeout_value(const MYSQL *mysql); diff --git a/include/sql_common.h b/include/sql_common.h index 6b66ae2fd81..8bb33e3779c 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -26,11 +26,18 @@ extern const char *unknown_sqlstate; extern const char *cant_connect_sqlstate; extern const char *not_error_sqlstate; + +struct mysql_async_context; + struct st_mysql_options_extention { char *plugin_dir; char *default_auth; }; +struct st_mysql_extension { + struct mysql_async_context *async_context; +}; + typedef struct st_mysql_methods { my_bool (*read_query_result)(MYSQL *mysql); @@ -102,6 +109,10 @@ void mysql_client_plugin_deinit(); struct st_mysql_client_plugin; extern struct st_mysql_client_plugin *mysql_client_builtins[]; +/* Non-blocking client API. */ +void my_context_install_suspend_resume_hook(struct mysql_async_context *b, + void (*)(my_bool, void *), void *); + #ifdef __cplusplus } #endif diff --git a/include/violite.h b/include/violite.h index c61ce4855c6..d5c9c083bdd 100644 --- a/include/violite.h +++ b/include/violite.h @@ -194,6 +194,8 @@ struct st_vio char *read_pos; /* start of unfetched data in the read buffer */ char *read_end; /* end of unfetched data */ + struct mysql_async_context *async_context; /* For non-blocking API */ + uint read_timeout, write_timeout; /* function pointers. They are similar for socket/SSL/whatever */ void (*viodelete)(Vio*); int (*vioerrno)(Vio*); diff --git a/libmysql/CMakeLists.txt b/libmysql/CMakeLists.txt index 4ac0b9a01ee..fc781a6dffc 100755 --- a/libmysql/CMakeLists.txt +++ b/libmysql/CMakeLists.txt @@ -95,7 +95,8 @@ SET(CLIENT_SOURCES ../mysys/array.c ../strings/bchange.c ../strings/bmove.c ../strings/strtoll.c ../strings/strtoull.c ../strings/strxmov.c ../strings/strxnmov.c ../mysys/thr_mutex.c ../mysys/typelib.c ../vio/vio.c ../vio/viosocket.c ../vio/viossl.c ../vio/viosslfactories.c ../strings/xml.c ../mysys/mf_qsort.c - ../mysys/my_getsystime.c ../mysys/my_sync.c ../sql-common/client_plugin.c ${LIB_SOURCES}) + ../mysys/my_getsystime.c ../mysys/my_sync.c ../sql-common/client_plugin.c + ../sql-common/mysql_async.c ../mysys/my_context.c ${LIB_SOURCES}) # Need to set USE_TLS for building the DLL, since __declspec(thread) # approach to thread local storage does not work properly in DLLs. diff --git a/libmysql/Makefile.shared b/libmysql/Makefile.shared index f9698f91a21..93bc527f915 100644 --- a/libmysql/Makefile.shared +++ b/libmysql/Makefile.shared @@ -71,9 +71,10 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ mf_iocache2.lo my_seek.lo my_sleep.lo \ my_pread.lo mf_cache.lo md5.lo sha1.lo my_rnd.lo \ my_getopt.lo my_port.lo \ - my_rename.lo my_chsize.lo my_sync.lo my_getsystime.lo + my_rename.lo my_chsize.lo my_sync.lo my_getsystime.lo \ + my_context.lo sqlobjects = net.lo -sql_cmn_objects = pack.lo client.lo my_time.lo client_plugin.lo +sql_cmn_objects = pack.lo client.lo my_time.lo client_plugin.lo mysql_async.lo # Not needed in the minimum library mysysobjects2 = my_lib.lo mf_qsort.lo diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt index 412902f5746..c751c5fa8c0 100644 --- a/libmysqld/CMakeLists.txt +++ b/libmysqld/CMakeLists.txt @@ -104,6 +104,7 @@ SET(LIBMYSQLD_SOURCES libmysqld.c emb_qcache.cc lib_sql.cc ../sql-common/my_user.c ../sql-common/pack.c ../sql/password.c ../sql/discover.cc ../sql/derror.cc ../sql/field.cc ../sql/field_conv.cc ../sql-common/client_plugin.c + ../sql-common/mysql_async.c ../sql/filesort.cc ../sql/gstream.cc ../sql/ha_partition.cc ../sql/handler.cc ../sql/hash_filo.cc ../sql/hostname.cc ../sql/init.cc ../sql/item_buff.cc ../sql/item_cmpfunc.cc diff --git a/libmysqld/Makefile.am b/libmysqld/Makefile.am index ef17a0a6923..926b339003d 100644 --- a/libmysqld/Makefile.am +++ b/libmysqld/Makefile.am @@ -41,7 +41,7 @@ pkglib_LTLIBRARIES = libmysqld.la SUBDIRS = . examples libmysqld_sources= libmysqld.c lib_sql.cc emb_qcache.cc libmysqlsources = errmsg.c get_password.c libmysql.c client.c pack.c \ - my_time.c client_plugin.c + my_time.c client_plugin.c mysql_async.c noinst_HEADERS = embedded_priv.h emb_qcache.h diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 88f175b636f..19b9b97e22d 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -185,6 +185,7 @@ my $opt_ps_protocol; my $opt_sp_protocol; my $opt_cursor_protocol; my $opt_view_protocol; +my $opt_non_blocking_api; our $opt_debug; our $opt_debug_server; @@ -964,6 +965,7 @@ sub command_line_setup { 'sp-protocol' => \$opt_sp_protocol, 'view-protocol' => \$opt_view_protocol, 'cursor-protocol' => \$opt_cursor_protocol, + 'non-blocking-api' => \$opt_non_blocking_api, 'ssl|with-openssl' => \$opt_ssl, 'skip-ssl' => \$opt_skip_ssl, 'compress' => \$opt_compress, @@ -5468,6 +5470,11 @@ sub start_mysqltest ($) { mtr_add_arg($args, "--cursor-protocol"); } + if ( $opt_non_blocking_api ) + { + mtr_add_arg($args, "--non-blocking-api"); + } + if ( $opt_strace_client ) { $exe= $opt_strace_client || "strace"; @@ -5915,6 +5922,7 @@ Options to control what engine/variation to run (implies --ps-protocol) view-protocol Create a view to execute all non updating queries sp-protocol Create a stored procedure to execute all queries + non-blocking-api Use the non-blocking client API compress Use the compressed protocol between client and server ssl Use ssl protocol between client and server skip-ssl Dont start server with support for ssl connections diff --git a/mysql-test/r/mysql_client_test_nonblock.result b/mysql-test/r/mysql_client_test_nonblock.result new file mode 100644 index 00000000000..edda7980e97 --- /dev/null +++ b/mysql-test/r/mysql_client_test_nonblock.result @@ -0,0 +1,5 @@ +SET @old_general_log= @@global.general_log; +SET @old_slow_query_log= @@global.slow_query_log; +ok +SET @@global.general_log= @old_general_log; +SET @@global.slow_query_log= @old_slow_query_log; diff --git a/mysql-test/r/non_blocking_api.result b/mysql-test/r/non_blocking_api.result new file mode 100644 index 00000000000..470e3e067f6 --- /dev/null +++ b/mysql-test/r/non_blocking_api.result @@ -0,0 +1,9 @@ +CREATE TABLE t1 (a INT PRIMARY KEY); +INSERT INTO t1 VALUES (1); +SELECT * FROM t1; +a +1 +SELECT * FROM t1; +a +1 +DROP TABLE t1; diff --git a/mysql-test/t/mysql_client_test_nonblock-master.opt b/mysql-test/t/mysql_client_test_nonblock-master.opt new file mode 100644 index 00000000000..4c683f7f0a2 --- /dev/null +++ b/mysql-test/t/mysql_client_test_nonblock-master.opt @@ -0,0 +1 @@ +--log=$MYSQLTEST_VARDIR/log/master.log --log-output=FILE,TABLE diff --git a/mysql-test/t/mysql_client_test_nonblock.test b/mysql-test/t/mysql_client_test_nonblock.test new file mode 100644 index 00000000000..f212fe6abda --- /dev/null +++ b/mysql-test/t/mysql_client_test_nonblock.test @@ -0,0 +1,23 @@ +# This runs the mysql_client_test using the non-blocking API. + +# This test should work in embedded server after we fix mysqltest +-- source include/not_embedded.inc + +SET @old_general_log= @@global.general_log; +SET @old_slow_query_log= @@global.slow_query_log; + +# We run with different binaries for normal and --embedded-server +# +# If this test fails with "command "$MYSQL_CLIENT_TEST" failed", +# you should either run mysql_client_test separartely against a running +# server or run mysql-test-run --debug mysql_client_test and check +# var/log/mysql_client_test.trace + +--exec echo "$MYSQL_CLIENT_TEST --non-blocking-api" > $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1 +--exec $MYSQL_CLIENT_TEST --non-blocking-api --getopt-ll-test=25600M >> $MYSQLTEST_VARDIR/log/mysql_client_test.out.log 2>&1 + +# End of 4.1 tests +echo ok; + +SET @@global.general_log= @old_general_log; +SET @@global.slow_query_log= @old_slow_query_log; diff --git a/mysql-test/t/named_pipe.test b/mysql-test/t/named_pipe.test index e88fd8e1ef8..7c623abddb0 100644 --- a/mysql-test/t/named_pipe.test +++ b/mysql-test/t/named_pipe.test @@ -2,6 +2,8 @@ # in order to optimize things we skip this test on all # other platforms --source include/windows.inc +# Named pipe does not support the non-blocking API. +--disable_non_blocking_api # Only run this test if named pipe is avaliable let $nmp= query_get_value("SHOW VARIABLES LIKE 'named_pipe'", Value, 1); diff --git a/mysql-test/t/non_blocking_api.test b/mysql-test/t/non_blocking_api.test new file mode 100644 index 00000000000..b9909a1c8a4 --- /dev/null +++ b/mysql-test/t/non_blocking_api.test @@ -0,0 +1,18 @@ +# Test mixing the use of blocking and non-blocking API in a single connection. + +--enable_non_blocking_api +connect (con_nonblock,localhost,root,,test); +--disable_non_blocking_api +connect (con_normal,localhost,root,,test); + +connection con_nonblock; +CREATE TABLE t1 (a INT PRIMARY KEY); +--enable_non_blocking_api +INSERT INTO t1 VALUES (1); +--disable_non_blocking_api +SELECT * FROM t1; +--enable_non_blocking_api +SELECT * FROM t1; + +connection con_normal; +DROP TABLE t1; diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 9ab19222caf..cf222cb9819 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -44,6 +44,7 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c default.c default_ lf_alloc-pin.c lf_dynarray.c lf_hash.c my_atomic.c my_getncpus.c my_rnd.c my_uuid.c wqueue.c waiting_threads.c + my_context.c ) IF(NOT SOURCE_SUBLIBS) diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 1dd4cc0f780..050788531fb 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -58,7 +58,7 @@ libmysys_la_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \ my_compare.c my_netware.c my_largepage.c \ my_memmem.c stacktrace.c \ my_windac.c my_access.c base64.c my_libwrap.c \ - wqueue.c + wqueue.c my_context.c libmysys_la_LDFLAGS = $(AM_LDFLAGS) @WRAPLIBS@ libmysys_la_LIBADD = $(ZLIB_LIBS) diff --git a/mysys/my_context.c b/mysys/my_context.c new file mode 100644 index 00000000000..cc49c0cdbb9 --- /dev/null +++ b/mysys/my_context.c @@ -0,0 +1,749 @@ +/* + Copyright 2011 Kristian Nielsen + + Experiments with non-blocking libmysql. + + This 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 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. If not, see . +*/ + +/* + Implementation of async context spawning using Posix ucontext and + swapcontext(). +*/ + +#include +#include + +#include "mysys_priv.h" +#include "my_context.h" + +#ifdef HAVE_VALGRIND_VALGRIND_H +#include +#endif + +#ifdef MY_CONTEXT_USE_UCONTEXT +/* + The makecontext() only allows to pass integers into the created context :-( + We want to pass pointers, so we do it this kinda hackish way. + Anyway, it should work everywhere, and at least it does not break strict + aliasing. +*/ +union pass_void_ptr_as_2_int { + int a[2]; + void *p; +}; + + +/* + We use old-style function definition here, as this is passed to + makecontext(). And the type of the makecontext() argument does not match + the actual type (as the actual type can differ from call to call). +*/ +static void +my_context_spawn_internal(i0, i1) +int i0, i1; +{ + int err; + struct my_context *c; + union pass_void_ptr_as_2_int u; + + u.a[0]= i0; + u.a[1]= i1; + c= (struct my_context *)u.p; + + (*c->user_func)(c->user_data); + c->active= 0; + err= setcontext(&c->base_context); + fprintf(stderr, "Aieie, setcontext() failed: %d (errno=%d)\n", err, errno); +} + + +int +my_context_continue(struct my_context *c) +{ + int err; + + if (!c->active) + return 0; + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + err= swapcontext(&c->base_context, &c->spawned_context); +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + if (err) + { + fprintf(stderr, "Aieie, swapcontext() failed: %d (errno=%d)\n", + err, errno); + return -1; + } + + return c->active; +} + + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + int err; + union pass_void_ptr_as_2_int u; + + err= getcontext(&c->spawned_context); + if (err) + return -1; + c->spawned_context.uc_stack.ss_sp= c->stack; + c->spawned_context.uc_stack.ss_size= c->stack_size; + c->spawned_context.uc_link= NULL; + c->user_func= f; + c->user_data= d; + c->active= 1; + u.p= c; + makecontext(&c->spawned_context, my_context_spawn_internal, 2, + u.a[0], u.a[1]); + + return my_context_continue(c); +} + + +int +my_context_yield(struct my_context *c) +{ + int err; + + if (!c->active) + return -1; + + err= swapcontext(&c->spawned_context, &c->base_context); + if (err) + return -1; + return 0; +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ + if (2*sizeof(int) < sizeof(void *)) + { + fprintf(stderr, + "Error: Unable to store pointer in 2 ints on this architecture\n"); + return -1; + } + if (!(c->stack= malloc(stack_size))) + return -1; /* Out of memory */ + c->stack_size= stack_size; +#ifdef HAVE_VALGRIND_VALGRIND_H + c->valgrind_stack_id= + VALGRIND_STACK_REGISTER(c->stack, ((unsigned char *)(c->stack))+stack_size); +#endif +#ifndef DBUG_OFF + c->dbug_state= NULL; +#endif + return 0; +} + +void +my_context_destroy(struct my_context *c) +{ + if (c->stack) + { +#ifdef HAVE_VALGRIND_VALGRIND_H + VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); +#endif + free(c->stack); + } +#ifndef DBUG_OFF + dbug_free_code_state(&c->dbug_state); +#endif +} + +#endif /* MY_CONTEXT_USE_UCONTEXT */ + + +#ifdef MY_CONTEXT_USE_X86_64_GCC_ASM +/* + GCC-amd64 implementation of my_context. + + This is slightly optimized in the common case where we never yield + (eg. fetch next row and it is already fully received in buffer). In this + case we do not need to restore registers at return (though we still need to + save them as we cannot know if we will yield or not in advance). +*/ + +#include +#include + +/* + Layout of saved registers etc. + Since this is accessed through gcc inline assembler, it is simpler to just + use numbers than to try to define nice constants or structs. + + 0 0 %rsp + 1 8 %rbp + 2 16 %rbx + 3 24 %r12 + 4 32 %r13 + 5 40 %r14 + 6 48 %r15 + 7 56 %rip for done + 8 64 %rip for yield/continue +*/ + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + int ret; + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + + /* + There are 6 callee-save registers we need to save and restore when + suspending and continuing, plus stack pointer %rsp and instruction pointer + %rip. + + However, if we never suspend, the user-supplied function will in any case + restore the 6 callee-save registers, so we can avoid restoring them in + this case. + */ + __asm__ __volatile__ + ( + "movq %%rsp, (%[save])\n\t" + "movq %[stack], %%rsp\n\t" + "movq %%rbp, 8(%[save])\n\t" + "movq %%rbx, 16(%[save])\n\t" + "movq %%r12, 24(%[save])\n\t" + "movq %%r13, 32(%[save])\n\t" + "movq %%r14, 40(%[save])\n\t" + "movq %%r15, 48(%[save])\n\t" + "leaq 1f(%%rip), %%rax\n\t" + "leaq 2f(%%rip), %%rcx\n\t" + "movq %%rax, 56(%[save])\n\t" + "movq %%rcx, 64(%[save])\n\t" + /* + Constraint below puts the argument to the user function into %rdi, as + needed for the calling convention. + */ + "callq *%[f]\n\t" + "jmpq *56(%[save])\n" + /* + Come here when operation is done. + We do not need to restore callee-save registers, as the called function + will do this for us if needed. + */ + "1:\n\t" + "movq (%[save]), %%rsp\n\t" + "xorl %[ret], %[ret]\n\t" + "jmp 3f\n" + /* Come here when operation was suspended. */ + "2:\n\t" + "movl $1, %[ret]\n" + "3:\n" + : [ret] "=a" (ret), + [f] "+S" (f), + /* Need this in %rdi to follow calling convention. */ + [d] "+D" (d) + : [stack] "a" (c->stack_top), + /* Need this in callee-save register to preserve in function call. */ + [save] "b" (&c->save[0]) + : "rcx", "rdx", "r8", "r9", "r10", "r11", "memory", "cc" + ); + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + + return ret; +} + +int +my_context_continue(struct my_context *c) +{ + int ret; + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + + __asm__ __volatile__ + ( + "movq (%[save]), %%rax\n\t" + "movq %%rsp, (%[save])\n\t" + "movq %%rax, %%rsp\n\t" + "movq 8(%[save]), %%rax\n\t" + "movq %%rbp, 8(%[save])\n\t" + "movq %%rax, %%rbp\n\t" + "movq 24(%[save]), %%rax\n\t" + "movq %%r12, 24(%[save])\n\t" + "movq %%rax, %%r12\n\t" + "movq 32(%[save]), %%rax\n\t" + "movq %%r13, 32(%[save])\n\t" + "movq %%rax, %%r13\n\t" + "movq 40(%[save]), %%rax\n\t" + "movq %%r14, 40(%[save])\n\t" + "movq %%rax, %%r14\n\t" + "movq 48(%[save]), %%rax\n\t" + "movq %%r15, 48(%[save])\n\t" + "movq %%rax, %%r15\n\t" + + "leaq 1f(%%rip), %%rax\n\t" + "leaq 2f(%%rip), %%rcx\n\t" + "movq %%rax, 56(%[save])\n\t" + "movq 64(%[save]), %%rax\n\t" + "movq %%rcx, 64(%[save])\n\t" + + "movq 16(%[save]), %%rcx\n\t" + "movq %%rbx, 16(%[save])\n\t" + "movq %%rcx, %%rbx\n\t" + + "jmpq *%%rax\n" + /* + Come here when operation is done. + Be sure to use the same callee-save register for %[save] here and in + my_context_spawn(), so we preserve the value correctly at this point. + */ + "1:\n\t" + "movq (%[save]), %%rsp\n\t" + "movq 8(%[save]), %%rbp\n\t" + /* %rbx is preserved from my_context_spawn() in this case. */ + "movq 24(%[save]), %%r12\n\t" + "movq 32(%[save]), %%r13\n\t" + "movq 40(%[save]), %%r14\n\t" + "movq 48(%[save]), %%r15\n\t" + "xorl %[ret], %[ret]\n\t" + "jmp 3f\n" + /* Come here when operation is suspended. */ + "2:\n\t" + "movl $1, %[ret]\n" + "3:\n" + : [ret] "=a" (ret) + : /* Need this in callee-save register to preserve in function call. */ + [save] "b" (&c->save[0]) + : "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "memory", "cc" + ); + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + + return ret; +} + +int +my_context_yield(struct my_context *c) +{ + uint64_t *save= &c->save[0]; + __asm__ __volatile__ + ( + "movq (%[save]), %%rax\n\t" + "movq %%rsp, (%[save])\n\t" + "movq %%rax, %%rsp\n\t" + "movq 8(%[save]), %%rax\n\t" + "movq %%rbp, 8(%[save])\n\t" + "movq %%rax, %%rbp\n\t" + "movq 16(%[save]), %%rax\n\t" + "movq %%rbx, 16(%[save])\n\t" + "movq %%rax, %%rbx\n\t" + "movq 24(%[save]), %%rax\n\t" + "movq %%r12, 24(%[save])\n\t" + "movq %%rax, %%r12\n\t" + "movq 32(%[save]), %%rax\n\t" + "movq %%r13, 32(%[save])\n\t" + "movq %%rax, %%r13\n\t" + "movq 40(%[save]), %%rax\n\t" + "movq %%r14, 40(%[save])\n\t" + "movq %%rax, %%r14\n\t" + "movq 48(%[save]), %%rax\n\t" + "movq %%r15, 48(%[save])\n\t" + "movq %%rax, %%r15\n\t" + "movq 64(%[save]), %%rax\n\t" + "leaq 1f(%%rip), %%rcx\n\t" + "movq %%rcx, 64(%[save])\n\t" + + "jmpq *%%rax\n" + + "1:\n" + : [save] "+D" (save) + : + : "rax", "rcx", "rdx", "rsi", "r8", "r9", "r10", "r11", "memory", "cc" + ); + return 0; +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ + if (!(c->stack_bot= malloc(stack_size))) + return -1; /* Out of memory */ + c->stack_top= ((unsigned char *)(c->stack_bot)) + stack_size; +#ifdef HAVE_VALGRIND_VALGRIND_H + c->valgrind_stack_id= + VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top); +#endif +#ifndef DBUG_OFF + c->dbug_state= NULL; +#endif + return 0; +} + +void +my_context_destroy(struct my_context *c) +{ + if (c->stack_bot) + { + free(c->stack_bot); +#ifdef HAVE_VALGRIND_VALGRIND_H + VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); +#endif + } +#ifndef DBUG_OFF + dbug_free_code_state(&c->dbug_state); +#endif +} + +#endif /* MY_CONTEXT_USE_X86_64_GCC_ASM */ + + +#ifdef MY_CONTEXT_USE_I386_GCC_ASM +/* + GCC-i386 implementation of my_context. + + This is slightly optimized in the common case where we never yield + (eg. fetch next row and it is already fully received in buffer). In this + case we do not need to restore registers at return (though we still need to + save them as we cannot know if we will yield or not in advance). +*/ + +#include +#include + +/* + Layout of saved registers etc. + Since this is accessed through gcc inline assembler, it is simpler to just + use numbers than to try to define nice constants or structs. + + 0 0 %esp + 1 4 %ebp + 2 8 %ebx + 3 12 %esi + 4 16 %edi + 5 20 %eip for done + 6 24 %eip for yield/continue +*/ + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + int ret; + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + + /* + There are 4 callee-save registers we need to save and restore when + suspending and continuing, plus stack pointer %esp and instruction pointer + %eip. + + However, if we never suspend, the user-supplied function will in any case + restore the 4 callee-save registers, so we can avoid restoring them in + this case. + */ + __asm__ __volatile__ + ( + "movl %%esp, (%[save])\n\t" + "movl %[stack], %%esp\n\t" + /* Push the parameter on the stack. */ + "pushl %[d]\n\t" + "movl %%ebp, 4(%[save])\n\t" + "movl %%ebx, 8(%[save])\n\t" + "movl %%esi, 12(%[save])\n\t" + "movl %%edi, 16(%[save])\n\t" + /* Get label addresses in -fPIC-compatible way (no pc-relative on 32bit) */ + "call 1f\n" + "1:\n\t" + "popl %%eax\n\t" + "addl $(2f-1b), %%eax\n\t" + "movl %%eax, 20(%[save])\n\t" + "addl $(3f-2f), %%eax\n\t" + "movl %%eax, 24(%[save])\n\t" + "call *%[f]\n\t" + "jmp *20(%[save])\n" + /* + Come here when operation is done. + We do not need to restore callee-save registers, as the called function + will do this for us if needed. + */ + "2:\n\t" + "movl (%[save]), %%esp\n\t" + "xorl %[ret], %[ret]\n\t" + "jmp 4f\n" + /* Come here when operation was suspended. */ + "3:\n\t" + "movl $1, %[ret]\n" + "4:\n" + : [ret] "=a" (ret) + : [stack] "a" (c->stack_top), + /* Need this in callee-save register to preserve across function call. */ + [save] "D" (&c->save[0]), + [f] "m" (f), + [d] "m" (d) + : "ecx", "edx", "memory", "cc" + ); + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + + return ret; +} + +int +my_context_continue(struct my_context *c) +{ + int ret; + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + + __asm__ __volatile__ + ( + "movl (%[save]), %%eax\n\t" + "movl %%esp, (%[save])\n\t" + "movl %%eax, %%esp\n\t" + "movl 4(%[save]), %%eax\n\t" + "movl %%ebp, 4(%[save])\n\t" + "movl %%eax, %%ebp\n\t" + "movl 8(%[save]), %%eax\n\t" + "movl %%ebx, 8(%[save])\n\t" + "movl %%eax, %%ebx\n\t" + "movl 12(%[save]), %%eax\n\t" + "movl %%esi, 12(%[save])\n\t" + "movl %%eax, %%esi\n\t" + + "movl 24(%[save]), %%eax\n\t" + "call 1f\n" + "1:\n\t" + "popl %%ecx\n\t" + "addl $(2f-1b), %%ecx\n\t" + "movl %%ecx, 20(%[save])\n\t" + "addl $(3f-2f), %%ecx\n\t" + "movl %%ecx, 24(%[save])\n\t" + + /* Must restore %edi last as it is also our %[save] register. */ + "movl 16(%[save]), %%ecx\n\t" + "movl %%edi, 16(%[save])\n\t" + "movl %%ecx, %%edi\n\t" + + "jmp *%%eax\n" + /* + Come here when operation is done. + Be sure to use the same callee-save register for %[save] here and in + my_context_spawn(), so we preserve the value correctly at this point. + */ + "2:\n\t" + "movl (%[save]), %%esp\n\t" + "movl 4(%[save]), %%ebp\n\t" + "movl 8(%[save]), %%ebx\n\t" + "movl 12(%[save]), %%esi\n\t" + "movl 16(%[save]), %%edi\n\t" + "xorl %[ret], %[ret]\n\t" + "jmp 4f\n" + /* Come here when operation is suspended. */ + "3:\n\t" + "movl $1, %[ret]\n" + "4:\n" + : [ret] "=a" (ret) + : /* Need this in callee-save register to preserve in function call. */ + [save] "D" (&c->save[0]) + : "ecx", "edx", "memory", "cc" + ); + +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + + return ret; +} + +int +my_context_yield(struct my_context *c) +{ + uint64_t *save= &c->save[0]; + __asm__ __volatile__ + ( + "movl (%[save]), %%eax\n\t" + "movl %%esp, (%[save])\n\t" + "movl %%eax, %%esp\n\t" + "movl 4(%[save]), %%eax\n\t" + "movl %%ebp, 4(%[save])\n\t" + "movl %%eax, %%ebp\n\t" + "movl 8(%[save]), %%eax\n\t" + "movl %%ebx, 8(%[save])\n\t" + "movl %%eax, %%ebx\n\t" + "movl 12(%[save]), %%eax\n\t" + "movl %%esi, 12(%[save])\n\t" + "movl %%eax, %%esi\n\t" + "movl 16(%[save]), %%eax\n\t" + "movl %%edi, 16(%[save])\n\t" + "movl %%eax, %%edi\n\t" + + "movl 24(%[save]), %%eax\n\t" + "call 1f\n" + "1:\n\t" + "popl %%ecx\n\t" + "addl $(2f-1b), %%ecx\n\t" + "movl %%ecx, 24(%[save])\n\t" + + "jmp *%%eax\n" + + "2:\n" + : [save] "+d" (save) + : + : "eax", "ecx", "memory", "cc" + ); + return 0; +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ + if (!(c->stack_bot= malloc(stack_size))) + return -1; /* Out of memory */ + c->stack_top= ((unsigned char *)(c->stack_bot)) + stack_size; +#ifdef HAVE_VALGRIND_VALGRIND_H + c->valgrind_stack_id= + VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top); +#endif +#ifndef DBUG_OFF + c->dbug_state= NULL; +#endif + return 0; +} + +void +my_context_destroy(struct my_context *c) +{ + if (c->stack_bot) + { + free(c->stack_bot); +#ifdef HAVE_VALGRIND_VALGRIND_H + VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); +#endif + } +#ifndef DBUG_OFF + dbug_free_code_state(&c->dbug_state); +#endif +} + +#endif /* MY_CONTEXT_USE_I386_GCC_ASM */ + + +#ifdef MY_CONTEXT_USE_WIN32_FIBERS +int +my_context_yield(struct my_context *c) +{ + c->return_value= 1; + SwitchToFiber(c->app_fiber); + return 0; +} + + +static void WINAPI +my_context_trampoline(void *p) +{ + struct my_context *c= (struct my_context *)p; + /* + Reuse the Fiber by looping infinitely, each time we are scheduled we + spawn the appropriate function and switch back when it is done. + + This way we avoid the overhead of CreateFiber() for every asynchroneous + operation. + */ + for(;;) + { + (*(c->user_func))(c->user_arg); + c->return_value= 0; + SwitchToFiber(c->app_fiber); + } +} + +int +my_context_init(struct my_context *c, size_t stack_size) +{ +#ifndef DBUG_OFF + c->dbug_state= NULL; +#endif + c->lib_fiber= CreateFiber(stack_size, my_context_trampoline, c); + if (c->lib_fiber) + return 0; + else + return -1; +} + +void +my_context_destroy(struct my_context *c) +{ +#ifndef DBUG_OFF + dbug_free_code_state(&c->dbug_state); +#endif + if (c->lib_fiber) + { + DeleteFiber(c->lib_fiber); + c->lib_fiber= NULL; + } +} + +int +my_context_spawn(struct my_context *c, void (*f)(void *), void *d) +{ + void *current_fiber; + c->user_func= f; + c->user_arg= d; + /* + This seems to be a common trick to run ConvertThreadToFiber() only on the + first occurence in a thread, in a way that works on multiple Windows + versions. + */ + current_fiber= GetCurrentFiber(); + if (current_fiber == NULL || current_fiber == (void *)0x1e00) + current_fiber= ConvertThreadToFiber(c); + c->app_fiber= current_fiber; +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + SwitchToFiber(c->lib_fiber); +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + return c->return_value; +} + +int +my_context_continue(struct my_context *c) +{ +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + SwitchToFiber(c->lib_fiber); +#ifndef DBUG_OFF + dbug_swap_code_state(&c->dbug_state); +#endif + return c->return_value; +} + +#endif /* MY_CONTEXT_USE_WIN32_FIBERS */ diff --git a/server-tools/instance-manager/CMakeLists.txt b/server-tools/instance-manager/CMakeLists.txt index 8e96a3f6425..97627d08597 100755 --- a/server-tools/instance-manager/CMakeLists.txt +++ b/server-tools/instance-manager/CMakeLists.txt @@ -26,7 +26,8 @@ ADD_EXECUTABLE(mysqlmanager buffer.cc command.cc commands.cc guardian.cc instanc user_management_commands.cc ../../mysys/my_rnd.c ../../sql/net_serv.cc ../../sql-common/pack.c ../../sql/password.c ../../sql/sql_state.c ../../sql-common/client.c ../../libmysql/get_password.c - ../../libmysql/errmsg.c ../../sql-common/client_plugin.c) + ../../libmysql/errmsg.c ../../sql-common/client_plugin.c + ../../sql-common/mysql_async.c) ADD_DEPENDENCIES(mysqlmanager GenError) TARGET_LINK_LIBRARIES(mysqlmanager debug dbug mysys strings taocrypt vio yassl zlib wsock32) diff --git a/server-tools/instance-manager/Makefile.am b/server-tools/instance-manager/Makefile.am index dce7c77232d..42213993597 100644 --- a/server-tools/instance-manager/Makefile.am +++ b/server-tools/instance-manager/Makefile.am @@ -47,6 +47,7 @@ libnet_a_LIBADD= $(top_builddir)/sql/password.$(OBJEXT) \ $(top_builddir)/sql/sql_state.$(OBJEXT) \ $(top_builddir)/sql/mini_client_errors.$(OBJEXT)\ $(top_builddir)/sql/client.$(OBJEXT) \ + $(top_builddir)/sql/mysql_async.$(OBJEXT) \ $(top_builddir)/sql/client_plugin.$(OBJEXT) CLEANFILES= net_serv.cc client_settings.h diff --git a/sql-common/Makefile.am b/sql-common/Makefile.am index 2f5a049085f..379cff832ce 100644 --- a/sql-common/Makefile.am +++ b/sql-common/Makefile.am @@ -14,4 +14,5 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## Process this file with automake to create Makefile.in -EXTRA_DIST = client.c pack.c my_time.c my_user.c client_plugin.c +EXTRA_DIST = client.c pack.c my_time.c my_user.c client_plugin.c \ + mysql_async.c diff --git a/sql-common/client.c b/sql-common/client.c index 28b3cf274bc..f56a6d5111f 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -108,6 +108,7 @@ my_bool net_flush(NET *net); #include "client_settings.h" #include #include +#include "my_context.h" #define native_password_plugin_name "mysql_native_password" #define old_password_plugin_name "mysql_old_password" @@ -1050,6 +1051,15 @@ static int add_init_command(struct st_mysql_options *options, const char *cmd) return 0; } +#define mysql_extension_get(MYSQL, X) \ + ((MYSQL)->extension ? (MYSQL)->extension->X : NULL) +#define mysql_extension_set(MYSQL, X, VAL) \ + if (!(MYSQL)->extension) \ + (MYSQL)->extension= (struct st_mysql_extension *) \ + my_malloc(sizeof(struct st_mysql_extension), \ + MYF(MY_WME | MY_ZEROFILL)); \ + (MYSQL)->extension->X= VAL; + #define extension_set_string(OPTS, X, STR) \ if ((OPTS)->extension) \ my_free((OPTS)->extension->X, MYF(MY_ALLOW_ZERO_PTR)); \ @@ -1266,6 +1276,36 @@ void mysql_read_default_options(struct st_mysql_options *options, DBUG_VOID_RETURN; } +/* + Fetch the context for asynchronous API calls, allocating a new one if + necessary. +*/ +#define STACK_SIZE (4096*15) + +struct mysql_async_context * +mysql_get_async_context(MYSQL *mysql) +{ + struct mysql_async_context *b; + if ((b= mysql_extension_get(mysql, async_context))) + return b; + + if (!(b= (struct mysql_async_context *) + my_malloc(sizeof(*b), MYF(MY_ZEROFILL)))) + { + set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); + return NULL; + } + if (my_context_init(&b->async_context, STACK_SIZE)) + { + my_free(b, MYF(0)); + return NULL; + } + mysql_extension_set(mysql, async_context, b) + if (mysql->net.vio) + mysql->net.vio->async_context= b; + return b; +} + /************************************************************************** Get column lengths of the current row @@ -2537,6 +2577,26 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, } +static int +connect_sync_or_async(MYSQL *mysql, NET *net, my_socket fd, + const struct sockaddr *name, uint namelen) +{ + extern int my_connect_async(struct mysql_async_context *b, my_socket fd, + const struct sockaddr *name, uint namelen, + uint timeout); + struct mysql_async_context *actxt= mysql_extension_get(mysql, async_context); + + if (actxt && actxt->active) + { + my_bool old_mode; + vio_blocking(net->vio, FALSE, &old_mode); + return my_connect_async(actxt, fd, name, namelen, + mysql->options.connect_timeout); + } + else + return my_connect(fd, name, namelen, mysql->options.connect_timeout); +} + MYSQL * STDCALL CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, const char *passwd, const char *db, @@ -2552,6 +2612,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, struct sockaddr_in sock_addr; ulong pkt_length; NET *net= &mysql->net; + struct mysql_async_context *actxt; #ifdef MYSQL_SERVER thr_alarm_t alarmed; ALARM alarm_buff; @@ -2681,8 +2742,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); UNIXaddr.sun_family = AF_UNIX; strmake(UNIXaddr.sun_path, unix_socket, sizeof(UNIXaddr.sun_path)-1); - if (my_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr), - mysql->options.connect_timeout)) + if (connect_sync_or_async(mysql, net, sock, + (struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr))) { DBUG_PRINT("error",("Got error %d on connect to local server", socket_errno)); @@ -2763,8 +2824,9 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, if ((int) (ip_addr = inet_addr(host)) != (int) INADDR_NONE) { memcpy_fixed(&sock_addr.sin_addr,&ip_addr,sizeof(ip_addr)); - status= my_connect(sock, (struct sockaddr *) &sock_addr, - sizeof(sock_addr), mysql->options.connect_timeout); + status= connect_sync_or_async(mysql, net, sock, + (struct sockaddr *) &sock_addr, + sizeof(sock_addr)); } else { @@ -2795,8 +2857,9 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, min(sizeof(sock_addr.sin_addr), (size_t) hp->h_length)); DBUG_PRINT("info",("Trying %s...", (my_inet_ntoa(sock_addr.sin_addr, ipaddr), ipaddr))); - status= my_connect(sock, (struct sockaddr *) &sock_addr, - sizeof(sock_addr), mysql->options.connect_timeout); + status= connect_sync_or_async(mysql, net, sock, + (struct sockaddr *) &sock_addr, + sizeof(sock_addr)); } my_gethostbyname_r_free(); @@ -2818,6 +2881,9 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, goto error; } + if ((actxt= mysql_extension_get(mysql, async_context)) && actxt->active) + net->vio->async_context= actxt; + if (my_net_init(net, net->vio)) { vio_delete(net->vio); @@ -3077,9 +3143,34 @@ static void mysql_fix_pointers(MYSQL* mysql, MYSQL* old_mysql) #endif +struct my_hook_data { + MYSQL *orig_mysql; + MYSQL *new_mysql; + /* This is always NULL currently, but restoring does not hurt just in case. */ + Vio *orig_vio; +}; +/* + Callback hook to make the new VIO accessible via the old MYSQL to calling + application when suspending a non-blocking call during automatic reconnect. +*/ +static void +my_suspend_hook(my_bool suspend, void *data) +{ + struct my_hook_data *hook_data= (struct my_hook_data *)data; + if (suspend) + { + hook_data->orig_vio= hook_data->orig_mysql->net.vio; + hook_data->orig_mysql->net.vio= hook_data->new_mysql->net.vio; + } + else + hook_data->orig_mysql->net.vio= hook_data->orig_vio; +} + my_bool mysql_reconnect(MYSQL *mysql) { MYSQL tmp_mysql; + struct my_hook_data hook_data; + struct mysql_async_context *ctxt= NULL; DBUG_ENTER("mysql_reconnect"); DBUG_ASSERT(mysql); DBUG_PRINT("enter", ("mysql->reconnect: %d", mysql->reconnect)); @@ -3093,14 +3184,34 @@ my_bool mysql_reconnect(MYSQL *mysql) DBUG_RETURN(1); } mysql_init(&tmp_mysql); + tmp_mysql.extension= mysql->extension; tmp_mysql.options= mysql->options; tmp_mysql.options.my_cnf_file= tmp_mysql.options.my_cnf_group= 0; tmp_mysql.rpl_pivot= mysql->rpl_pivot; + /* + If we are automatically re-connecting inside a non-blocking API call, we + may need to suspend and yield to the user application during the reconnect. + If so, the user application will need access to the new VIO already then + so that it can correctly wait for I/O to become ready. + To achieve this, we temporarily install a hook that will temporarily put in + the VIO while we are suspended. + (The vio will be put in the original MYSQL permanently once we successfully + reconnect, or be discarded if we fail to reconnect.) + */ + if ((ctxt= mysql_extension_get(mysql, async_context)) && ctxt->active) + { + hook_data.orig_mysql= mysql; + hook_data.new_mysql= &tmp_mysql; + hook_data.orig_vio= mysql->net.vio; + my_context_install_suspend_resume_hook(ctxt, my_suspend_hook, &hook_data); + } if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, mysql->db, mysql->port, mysql->unix_socket, mysql->client_flag | CLIENT_REMEMBER_OPTIONS)) { + if (ctxt) + my_context_install_suspend_resume_hook(ctxt, NULL, NULL); mysql->net.last_errno= tmp_mysql.net.last_errno; strmov(mysql->net.last_error, tmp_mysql.net.last_error); strmov(mysql->net.sqlstate, tmp_mysql.net.sqlstate); @@ -3109,13 +3220,18 @@ my_bool mysql_reconnect(MYSQL *mysql) if (mysql_set_character_set(&tmp_mysql, mysql->charset->csname)) { DBUG_PRINT("error", ("mysql_set_character_set() failed")); + tmp_mysql.extension= NULL; bzero((char*) &tmp_mysql.options,sizeof(tmp_mysql.options)); mysql_close(&tmp_mysql); + if (ctxt) + my_context_install_suspend_resume_hook(ctxt, NULL, NULL); mysql->net.last_errno= tmp_mysql.net.last_errno; strmov(mysql->net.last_error, tmp_mysql.net.last_error); strmov(mysql->net.sqlstate, tmp_mysql.net.sqlstate); DBUG_RETURN(1); } + if (ctxt) + my_context_install_suspend_resume_hook(ctxt, NULL, NULL); DBUG_PRINT("info", ("reconnect succeded")); tmp_mysql.reconnect= 1; @@ -3125,7 +3241,11 @@ my_bool mysql_reconnect(MYSQL *mysql) tmp_mysql.stmts= mysql->stmts; mysql->stmts= 0; - /* Don't free options as these are now used in tmp_mysql */ + /* + Don't free options as these are now used in tmp_mysql. + Same with extension. + */ + mysql->extension= NULL; bzero((char*) &mysql->options,sizeof(mysql->options)); mysql->free_me=0; mysql_close(mysql); @@ -3204,6 +3324,21 @@ static void mysql_close_free_options(MYSQL *mysql) } +static void +mysql_close_free_extension(MYSQL *mysql) +{ + if (mysql->extension) + { + if (mysql->extension->async_context) + { + my_context_destroy(&mysql->extension->async_context->async_context); + my_free(mysql->extension->async_context, MYF(0)); + } + my_free(mysql->extension, MYF(0)); + mysql->extension= NULL; + } +} + static void mysql_close_free(MYSQL *mysql) { my_free((uchar*) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); @@ -3304,6 +3439,33 @@ void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused)), (As some clients call this after mysql_real_connect() fails) */ +/* + mysql_close() can actually block, at least in theory, if the socket buffer + is full when sending the COM_QUIT command. + + On the other hand, the latter part of mysql_close() needs to free the stack + used for non-blocking operation of blocking stuff, so that later part can + _not_ be done non-blocking. + + Therefore, mysql_pre_close() is used to run the parts of mysql_close() that + may block. It can be called before mysql_close(), and in that case + mysql_close() is guaranteed not to need to block. +*/ +void mysql_pre_close(MYSQL *mysql) +{ + if (!mysql) + return; + /* If connection is still up, send a QUIT message */ + if (mysql->net.vio != 0) + { + free_old_query(mysql); + mysql->status=MYSQL_STATUS_READY; /* Force command */ + mysql->reconnect=0; + simple_command(mysql,COM_QUIT,(uchar*) 0,0,1); + end_server(mysql); /* Sets mysql->net.vio= 0 */ + } +} + void STDCALL mysql_close(MYSQL *mysql) { DBUG_ENTER("mysql_close"); @@ -3311,16 +3473,9 @@ void STDCALL mysql_close(MYSQL *mysql) if (mysql) /* Some simple safety */ { - /* If connection is still up, send a QUIT message */ - if (mysql->net.vio != 0) - { - free_old_query(mysql); - mysql->status=MYSQL_STATUS_READY; /* Force command */ - mysql->reconnect=0; - simple_command(mysql,COM_QUIT,(uchar*) 0,0,1); - end_server(mysql); /* Sets mysql->net.vio= 0 */ - } + mysql_pre_close(mysql); mysql_close_free_options(mysql); + mysql_close_free_extension(mysql); mysql_close_free(mysql); mysql_detach_stmt_list(&mysql->stmts, "mysql_close"); #ifndef TO_BE_DELETED @@ -3941,3 +4096,12 @@ static int old_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) return CR_OK; } + +my_socket STDCALL +mysql_get_socket(const MYSQL *mysql) +{ + if (mysql->net.vio) + return mysql->net.vio->sd; + else + return INVALID_SOCKET; +} diff --git a/sql-common/mysql_async.c b/sql-common/mysql_async.c new file mode 100644 index 00000000000..a8e699e5012 --- /dev/null +++ b/sql-common/mysql_async.c @@ -0,0 +1,1431 @@ +/* + Copyright 2011 Kristian Nielsen + + Experiments with non-blocking libmysql. + + This 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 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. If not, see . +*/ + +/* + MySQL non-blocking client library functions. +*/ + +#include "my_global.h" +#include "my_sys.h" +#include "mysql.h" +#include "errmsg.h" +#include "sql_common.h" +#include "my_context.h" +#include "violite.h" + + +#ifdef __WIN__ +/* + Windows does not support MSG_DONTWAIT for send()/recv(). So we need to ensure + that the socket is non-blocking at the start of every operation. +*/ +#define WIN_SET_NONBLOCKING(mysql) { \ + my_bool old_mode__; \ + if ((mysql)->net.vio) vio_blocking((mysql)->net.vio, FALSE, &old_mode__); \ + } +#else +#define WIN_SET_NONBLOCKING(mysql) +#endif + +extern struct mysql_async_context *mysql_get_async_context(MYSQL *mysql); + + +void +my_context_install_suspend_resume_hook(struct mysql_async_context *b, + void (*hook)(my_bool, void *), + void *user_data) +{ + b->suspend_resume_hook= hook; + b->suspend_resume_hook_user_data= user_data; +} + + +/* Asynchronous connect(); socket must already be set non-blocking. */ +int +my_connect_async(struct mysql_async_context *b, my_socket fd, + const struct sockaddr *name, uint namelen, uint timeout) +{ + int res; +#ifdef __WIN__ + int s_err_size; +#else + socklen_t s_err_size; +#endif + + /* + Start to connect asynchronously. + If this will block, we suspend the call and return control to the + application context. The application will then resume us when the socket + polls ready for write, indicating that the connection attempt completed. + */ + res= connect(fd, name, namelen); +#ifdef __WIN__ + if (res != 0) + { + int wsa_err= WSAGetLastError(); + if (wsa_err != WSAEWOULDBLOCK) + return res; +#else + if (res < 0) + { + if (errno != EINPROGRESS && errno != EALREADY && errno != EAGAIN) + return res; +#endif + b->timeout_value= timeout; + b->ret_status= MYSQL_WAIT_WRITE | + (timeout ? MYSQL_WAIT_TIMEOUT : 0); +#ifdef __WIN__ + b->ret_status|= MYSQL_WAIT_EXCEPT; +#endif + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + if (b->ret_status & MYSQL_WAIT_TIMEOUT) + return -1; + + s_err_size= sizeof(int); + if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &res, &s_err_size) != 0) + return -1; + if (res) + { + errno= res; + return -1; + } + } + return res; +} + +ssize_t +my_recv_async(struct mysql_async_context *b, int fd, + unsigned char *buf, size_t size, uint timeout) +{ + ssize_t res; + + for (;;) + { + res= recv(fd, buf, size, +#ifdef __WIN__ + 0 +#else + MSG_DONTWAIT +#endif + ); + if (res >= 0 || +#ifdef __WIN__ + WSAGetLastError() != WSAEWOULDBLOCK +#else + (errno != EAGAIN && errno != EINTR) +#endif + ) + return res; + b->ret_status= MYSQL_WAIT_READ; + if (timeout) + { + b->ret_status|= MYSQL_WAIT_TIMEOUT; + b->timeout_value= timeout; + } + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + if (b->ret_status & MYSQL_WAIT_TIMEOUT) + return -1; + } +} + +ssize_t +my_send_async(struct mysql_async_context *b, int fd, + const unsigned char *buf, size_t size, uint timeout) +{ + ssize_t res; + + for (;;) + { + res= send(fd, buf, size, +#ifdef __WIN__ + 0 +#else + MSG_DONTWAIT +#endif + ); + if (res >= 0 || +#ifdef __WIN__ + WSAGetLastError() != WSAEWOULDBLOCK +#else + (errno != EAGAIN && errno != EINTR) +#endif + ) + return res; + b->ret_status= MYSQL_WAIT_WRITE; + if (timeout) + { + b->ret_status|= MYSQL_WAIT_TIMEOUT; + b->timeout_value= timeout; + } + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + if (b->ret_status & MYSQL_WAIT_TIMEOUT) + return -1; + } +} + + +my_bool +my_poll_read_async(struct mysql_async_context *b, uint timeout) +{ + b->ret_status= MYSQL_WAIT_READ | MYSQL_WAIT_TIMEOUT; + b->timeout_value= timeout; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + return (b->ret_status & MYSQL_WAIT_READ) ? 0 : 1; +} + + +#ifdef HAVE_OPENSSL +int +my_ssl_read_async(struct mysql_async_context *b, SSL *ssl, + void *buf, int size) +{ + int res, ssl_err; + + for (;;) + { + res= SSL_read(ssl, buf, size); + if (res >= 0) + return res; + ssl_err= SSL_get_error(ssl, res); + if (ssl_err == SSL_ERROR_WANT_READ) + b->ret_status= MYSQL_WAIT_READ; + else if (ssl_err == SSL_ERROR_WANT_WRITE) + b->ret_status= MYSQL_WAIT_WRITE; + else + return res; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + } +} + +int +my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, + const void *buf, int size) +{ + int res, ssl_err; + + for (;;) + { + res= SSL_write(ssl, buf, size); + if (res >= 0) + return res; + ssl_err= SSL_get_error(ssl, res); + if (ssl_err == SSL_ERROR_WANT_READ) + b->ret_status= MYSQL_WAIT_READ; + else if (ssl_err == SSL_ERROR_WANT_WRITE) + b->ret_status= MYSQL_WAIT_WRITE; + else + return res; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + } +} +#endif /* HAVE_OPENSSL */ + +unsigned int STDCALL +mysql_get_timeout_value(const MYSQL *mysql) +{ + if (mysql->extension && mysql->extension->async_context) + return mysql->extension->async_context->timeout_value; + else + return 0; +} + +/* + Now create non-blocking definitions for all the calls that may block. + + Each call FOO gives rise to FOO_start() that prepares the MYSQL object for + doing non-blocking calls that can suspend operation mid-way, and then starts + the call itself. And a FOO_start_internal trampoline to assist with running + the real call in a co-routine that can be suspended. And a FOO_cont() that + can continue a suspended operation. +*/ + +#define MK_ASYNC_CALLS(call__, decl_args__, invoke_args__, cont_arg__, mysql_val__, parms_mysql_val__, parms_assign__, ret_type__, err_val__, ok_val__, extra1__) \ +static void \ +call__ ## _start_internal(void *d) \ +{ \ + struct call__ ## _params *parms; \ + ret_type__ ret; \ + struct mysql_async_context *b; \ + \ + parms= (struct call__ ## _params *)d; \ + b= (parms_mysql_val__)->extension->async_context; \ + \ + ret= call__ invoke_args__; \ + b->ret_result. ok_val__ = ret; \ + b->ret_status= 0; \ +} \ +int STDCALL \ +call__ ## _start decl_args__ \ +{ \ + int res; \ + struct mysql_async_context *b; \ + struct call__ ## _params parms; \ + \ + extra1__ \ + if (!(b= mysql_get_async_context((mysql_val__)))) \ + { \ + *ret= err_val__; \ + return 0; \ + } \ + parms_assign__ \ + \ + b->active= 1; \ + res= my_context_spawn(&b->async_context, call__ ## _start_internal, &parms);\ + b->active= 0; \ + if (res < 0) \ + { \ + set_mysql_error((mysql_val__), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + b->suspended= 0; \ + *ret= err_val__; \ + return 0; \ + } \ + else if (res > 0) \ + { \ + /* Suspended. */ \ + b->suspended= 1; \ + return b->ret_status; \ + } \ + else \ + { \ + /* Finished. */ \ + b->suspended= 0; \ + *ret= b->ret_result. ok_val__; \ + return 0; \ + } \ +} \ +int STDCALL \ +call__ ## _cont(ret_type__ *ret, cont_arg__, int ready_status) \ +{ \ + int res; \ + struct mysql_async_context *b; \ + \ + b= (mysql_val__)->extension->async_context; \ + if (!b || !b->suspended) \ + { \ + set_mysql_error((mysql_val__), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);\ + *ret= err_val__; \ + return 0; \ + } \ + \ + b->active= 1; \ + b->ret_status= ready_status; \ + res= my_context_continue(&b->async_context); \ + b->active= 0; \ + if (res < 0) \ + { \ + set_mysql_error((mysql_val__), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + b->suspended= 0; \ + *ret= err_val__; \ + return 0; \ + } \ + else if (res > 0) \ + { \ + /* Suspended. */ \ + return b->ret_status; \ + } \ + else \ + { \ + /* Finished. */ \ + b->suspended= 0; \ + *ret= b->ret_result. ok_val__; \ + return 0; \ + } \ +} + +#define MK_ASYNC_CALLS_VOID_RETURN(call__, decl_args__, invoke_args__, cont_arg__, mysql_val__, parms_mysql_val__, parms_assign__, extra1__) \ +static void \ +call__ ## _start_internal(void *d) \ +{ \ + struct call__ ## _params *parms; \ + struct mysql_async_context *b; \ + \ + parms= (struct call__ ## _params *)d; \ + b= (parms_mysql_val__)->extension->async_context; \ + \ + call__ invoke_args__; \ + b->ret_status= 0; \ +} \ +int STDCALL \ +call__ ## _start decl_args__ \ +{ \ + int res; \ + struct mysql_async_context *b; \ + struct call__ ## _params parms; \ + \ + extra1__ \ + if (!(b= mysql_get_async_context((mysql_val__)))) \ + { \ + return 0; \ + } \ + parms_assign__ \ + \ + b->active= 1; \ + res= my_context_spawn(&b->async_context, call__ ## _start_internal, &parms);\ + b->active= 0; \ + if (res < 0) \ + { \ + set_mysql_error((mysql_val__), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + b->suspended= 0; \ + return 0; \ + } \ + else if (res > 0) \ + { \ + /* Suspended. */ \ + b->suspended= 1; \ + return b->ret_status; \ + } \ + else \ + { \ + /* Finished. */ \ + b->suspended= 0; \ + return 0; \ + } \ +} \ +int STDCALL \ +call__ ## _cont(cont_arg__, int ready_status) \ +{ \ + int res; \ + struct mysql_async_context *b; \ + \ + b= (mysql_val__)->extension->async_context; \ + if (!b || !b->suspended) \ + { \ + set_mysql_error((mysql_val__), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);\ + return 0; \ + } \ + \ + b->active= 1; \ + b->ret_status= ready_status; \ + res= my_context_continue(&b->async_context); \ + b->active= 0; \ + if (res < 0) \ + { \ + set_mysql_error((mysql_val__), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + b->suspended= 0; \ + return 0; \ + } \ + else if (res > 0) \ + { \ + /* Suspended. */ \ + return b->ret_status; \ + } \ + else \ + { \ + /* Finished. */ \ + b->suspended= 0; \ + return 0; \ + } \ +} + +struct mysql_real_connect_params { + MYSQL *mysql; + const char *host; + const char *user; + const char *passwd; + const char *db; + unsigned int port; + const char *unix_socket; + unsigned long client_flags; +}; +MK_ASYNC_CALLS( + mysql_real_connect, + (MYSQL **ret, MYSQL *mysql, const char *host, const char *user, + const char *passwd, const char *db, unsigned int port, + const char *unix_socket, unsigned long client_flags), + (parms->mysql, parms->host, parms->user, parms->passwd, parms->db, + parms->port, parms->unix_socket, parms->client_flags), + MYSQL *mysql, + mysql, + parms->mysql, + { + parms.mysql= mysql; + parms.host= host; + parms.user= user; + parms.passwd= passwd; + parms.db= db; + parms.port= port; + parms.unix_socket= unix_socket; + parms.client_flags= client_flags; + }, + MYSQL *, + NULL, + r_ptr, + /* Nothing */) + +struct mysql_real_query_params { + MYSQL *mysql; + const char *stmt_str; + unsigned long length; +}; +MK_ASYNC_CALLS( + mysql_real_query, + (int *ret, MYSQL *mysql, const char *stmt_str, unsigned long length), + (parms->mysql, parms->stmt_str, parms->length), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.stmt_str= stmt_str; + parms.length= length; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_fetch_row_params { + MYSQL_RES *result; +}; +MK_ASYNC_CALLS( + mysql_fetch_row, + (MYSQL_ROW *ret, MYSQL_RES *result), + (parms->result), + MYSQL_RES *result, + result->handle, + parms->result->handle, + { + WIN_SET_NONBLOCKING(result->handle) + parms.result= result; + }, + MYSQL_ROW, + NULL, + r_ptr, + /* + If we already fetched all rows from server (eg. mysql_store_result()), + then result->handle will be NULL and we cannot suspend. But that is fine, + since in this case mysql_fetch_row cannot block anyway. Just return + directly. + */ + if (!result->handle) + { + *ret= mysql_fetch_row(result); + return 0; + } +) + +struct mysql_set_character_set_params { + MYSQL *mysql; + const char *csname; +}; +MK_ASYNC_CALLS( + mysql_set_character_set, + (int *ret, MYSQL *mysql, const char *csname), + (parms->mysql, parms->csname), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.csname= csname; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_select_db_params { + MYSQL *mysql; + const char *db; +}; +MK_ASYNC_CALLS( + mysql_select_db, + (int *ret, MYSQL *mysql, const char *db), + (parms->mysql, parms->db), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.db= db; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_send_query_params { + MYSQL *mysql; + const char *q; + unsigned long length; +}; +MK_ASYNC_CALLS( + mysql_send_query, + (int *ret, MYSQL *mysql, const char *q, unsigned long length), + (parms->mysql, parms->q, parms->length), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.q= q; + parms.length= length; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_store_result_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_store_result, + (MYSQL_RES **ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + MYSQL_RES *, + NULL, + r_ptr, + /* Nothing */) + +struct mysql_free_result_params { + MYSQL_RES *result; +}; +MK_ASYNC_CALLS_VOID_RETURN( + mysql_free_result, + (MYSQL_RES *result), + (parms->result), + MYSQL_RES *result, + result->handle, + parms->result->handle, + { + WIN_SET_NONBLOCKING(result->handle) + parms.result= result; + }, + /* + mysql_free_result() can have NULL in result->handle (this happens when all + rows have been fetched and mysql_fetch_row() returned NULL.) + So we cannot suspend, but it does not matter, as in this case + mysql_free_result() cannot block. + It is also legitimate to have NULL result, which will do nothing. + */ + if (!result || !result->handle) + { + mysql_free_result(result); + return 0; + }) + +struct mysql_pre_close_params { + MYSQL *sock; +}; +/* + We need special handling for mysql_close(), as the first part may block, + while the last part needs to free our extra library context stack. + + So we do the first part (mysql_pre_close()) non-blocking, but the last part + blocking. +*/ +extern void mysql_pre_close(MYSQL *mysql); +MK_ASYNC_CALLS_VOID_RETURN( + mysql_pre_close, + (MYSQL *sock), + (parms->sock), + MYSQL *sock, + sock, + parms->sock, + { + WIN_SET_NONBLOCKING(sock) + parms.sock= sock; + }, + /* Nothing */) +int STDCALL +mysql_close_start(MYSQL *sock) +{ + int res; + + /* It is legitimate to have NULL sock argument, which will do nothing. */ + if (sock) + { + res= mysql_pre_close_start(sock); + /* If we need to block, return now and do the rest in mysql_close_cont(). */ + if (res) + return res; + } + mysql_close(sock); + return 0; +} +int STDCALL +mysql_close_cont(MYSQL *sock, int ready_status) +{ + int res; + + res= mysql_pre_close_cont(sock, ready_status); + if (res) + return res; + mysql_close(sock); + return 0; +} + +#ifdef USE_OLD_FUNCTIONS +struct mysql_connect_params { + MYSQL *mysql; + const char *host; + const char *user; + const char *passwd; +}; +MK_ASYNC_CALLS( + mysql_connect, + (MYSQL **ret, MYSQL *mysql, const char *host, const char *user, const char *passwd), + (parms->mysql, parms->host, parms->user, parms->passwd), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.host= host; + parms.user= user; + parms.passwd= passwd; + }, + MYSQL *, + NULL, + r_ptr, + /* Nothing */) + +struct mysql_create_db_params { + MYSQL *mysql; + const char *DB; +}; +MK_ASYNC_CALLS( + mysql_create_db, + (int *ret, MYSQL *mysql, const char *DB), + (parms->mysql, parms->DB), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.DB= DB; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_drop_db_params { + MYSQL *mysql; + const char *DB; +}; +MK_ASYNC_CALLS( + mysql_drop_db, + (int *ret, MYSQL *mysql, const char *DB), + (parms->mysql, parms->DB), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.DB= DB; + }, + int, + 1, + r_int, + /* Nothing */) + +#endif + +/* + These following are not available inside the server (neither blocking or + non-blocking). +*/ +#ifndef MYSQL_SERVER +struct mysql_change_user_params { + MYSQL *mysql; + const char *user; + const char *passwd; + const char *db; +}; +MK_ASYNC_CALLS( + mysql_change_user, + (my_bool *ret, MYSQL *mysql, const char *user, const char *passwd, const char *db), + (parms->mysql, parms->user, parms->passwd, parms->db), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.user= user; + parms.passwd= passwd; + parms.db= db; + }, + my_bool, + TRUE, + r_my_bool, + /* Nothing */) + +struct mysql_query_params { + MYSQL *mysql; + const char *q; +}; +MK_ASYNC_CALLS( + mysql_query, + (int *ret, MYSQL *mysql, const char *q), + (parms->mysql, parms->q), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.q= q; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_shutdown_params { + MYSQL *mysql; + enum mysql_enum_shutdown_level shutdown_level; +}; +MK_ASYNC_CALLS( + mysql_shutdown, + (int *ret, MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level), + (parms->mysql, parms->shutdown_level), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.shutdown_level= shutdown_level; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_dump_debug_info_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_dump_debug_info, + (int *ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_refresh_params { + MYSQL *mysql; + unsigned int refresh_options; +}; +MK_ASYNC_CALLS( + mysql_refresh, + (int *ret, MYSQL *mysql, unsigned int refresh_options), + (parms->mysql, parms->refresh_options), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.refresh_options= refresh_options; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_kill_params { + MYSQL *mysql; + unsigned long pid; +}; +MK_ASYNC_CALLS( + mysql_kill, + (int *ret, MYSQL *mysql, unsigned long pid), + (parms->mysql, parms->pid), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.pid= pid; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_set_server_option_params { + MYSQL *mysql; + enum enum_mysql_set_option option; +}; +MK_ASYNC_CALLS( + mysql_set_server_option, + (int *ret, MYSQL *mysql, enum enum_mysql_set_option option), + (parms->mysql, parms->option), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.option= option; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_ping_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_ping, + (int *ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + int, + 1, + r_int, + /* Nothing */) + +struct mysql_stat_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_stat, + (const char **ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + const char *, + NULL, + r_const_ptr, + /* Nothing */) + +struct mysql_list_dbs_params { + MYSQL *mysql; + const char *wild; +}; +MK_ASYNC_CALLS( + mysql_list_dbs, + (MYSQL_RES **ret, MYSQL *mysql, const char *wild), + (parms->mysql, parms->wild), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.wild= wild; + }, + MYSQL_RES *, + NULL, + r_ptr, + /* Nothing */) + +struct mysql_list_tables_params { + MYSQL *mysql; + const char *wild; +}; +MK_ASYNC_CALLS( + mysql_list_tables, + (MYSQL_RES **ret, MYSQL *mysql, const char *wild), + (parms->mysql, parms->wild), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.wild= wild; + }, + MYSQL_RES *, + NULL, + r_ptr, + /* Nothing */) + +struct mysql_list_processes_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_list_processes, + (MYSQL_RES **ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + MYSQL_RES *, + NULL, + r_ptr, + /* Nothing */) + +struct mysql_list_fields_params { + MYSQL *mysql; + const char *table; + const char *wild; +}; +MK_ASYNC_CALLS( + mysql_list_fields, + (MYSQL_RES **ret, MYSQL *mysql, const char *table, const char *wild), + (parms->mysql, parms->table, parms->wild), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.table= table; + parms.wild= wild; + }, + MYSQL_RES *, + NULL, + r_ptr, + /* Nothing */) + +struct mysql_read_query_result_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_read_query_result, + (my_bool *ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + my_bool, + TRUE, + r_my_bool, + /* Nothing */) + +struct mysql_stmt_prepare_params { + MYSQL_STMT *stmt; + const char *query; + unsigned long length; +}; +MK_ASYNC_CALLS( + mysql_stmt_prepare, + (int *ret, MYSQL_STMT *stmt, const char *query, unsigned long length), + (parms->stmt, parms->query, parms->length), + MYSQL_STMT *stmt, + stmt->mysql, + parms->stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + parms.query= query; + parms.length= length; + }, + int, + 1, + r_int, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_prepare(stmt, query, length); + return 0; + }) + +struct mysql_stmt_execute_params { + MYSQL_STMT *stmt; +}; +MK_ASYNC_CALLS( + mysql_stmt_execute, + (int *ret, MYSQL_STMT *stmt), + (parms->stmt), + MYSQL_STMT *stmt, + stmt->mysql, + parms->stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + int, + 1, + r_int, + /* + If eg. mysql_change_user(), stmt->mysql will be NULL. + In this case, we cannot block. + */ + if (!stmt->mysql) + { + *ret= mysql_stmt_execute(stmt); + return 0; + }) + +struct mysql_stmt_fetch_params { + MYSQL_STMT *stmt; +}; +MK_ASYNC_CALLS( + mysql_stmt_fetch, + (int *ret, MYSQL_STMT *stmt), + (parms->stmt), + MYSQL_STMT *stmt, + stmt->mysql, + parms->stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + int, + 1, + r_int, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_fetch(stmt); + return 0; + }) + +struct mysql_stmt_store_result_params { + MYSQL_STMT *stmt; +}; +MK_ASYNC_CALLS( + mysql_stmt_store_result, + (int *ret, MYSQL_STMT *stmt), + (parms->stmt), + MYSQL_STMT *stmt, + stmt->mysql, + parms->stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + int, + 1, + r_int, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_store_result(stmt); + return 0; + }) + +struct mysql_stmt_close_params { + MYSQL_STMT *stmt; +}; +MK_ASYNC_CALLS( + mysql_stmt_close, + (my_bool *ret, MYSQL_STMT *stmt), + (parms->stmt), + MYSQL_STMT *stmt, + stmt->mysql, + parms->stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + my_bool, + TRUE, + r_my_bool, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_close(stmt); + return 0; + }) + +struct mysql_stmt_reset_params { + MYSQL_STMT *stmt; +}; +MK_ASYNC_CALLS( + mysql_stmt_reset, + (my_bool *ret, MYSQL_STMT *stmt), + (parms->stmt), + MYSQL_STMT *stmt, + stmt->mysql, + parms->stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + my_bool, + TRUE, + r_my_bool, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_reset(stmt); + return 0; + }) + +struct mysql_stmt_free_result_params { + MYSQL_STMT *stmt; +}; +MK_ASYNC_CALLS( + mysql_stmt_free_result, + (my_bool *ret, MYSQL_STMT *stmt), + (parms->stmt), + MYSQL_STMT *stmt, + stmt->mysql, + parms->stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + }, + my_bool, + TRUE, + r_my_bool, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_free_result(stmt); + return 0; + }) + +struct mysql_stmt_send_long_data_params { + MYSQL_STMT *stmt; + unsigned int param_number; + const char *data; + unsigned long length; +}; +MK_ASYNC_CALLS( + mysql_stmt_send_long_data, + (my_bool *ret, MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length), + (parms->stmt, parms->param_number, parms->data, parms->length), + MYSQL_STMT *stmt, + stmt->mysql, + parms->stmt->mysql, + { + WIN_SET_NONBLOCKING(stmt->mysql) + parms.stmt= stmt; + parms.param_number= param_number; + parms.data= data; + parms.length= length; + }, + my_bool, + TRUE, + r_my_bool, + /* If stmt->mysql==NULL then we will not block so can call directly. */ + if (!stmt->mysql) + { + *ret= mysql_stmt_send_long_data(stmt, param_number, data, length); + return 0; + }) + +struct mysql_commit_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_commit, + (my_bool *ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + my_bool, + TRUE, + r_my_bool, + /* Nothing */) + +struct mysql_rollback_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_rollback, + (my_bool *ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + my_bool, + TRUE, + r_my_bool, + /* Nothing */) + +struct mysql_autocommit_params { + MYSQL *mysql; + my_bool auto_mode; +}; +MK_ASYNC_CALLS( + mysql_autocommit, + (my_bool *ret, MYSQL *mysql, my_bool auto_mode), + (parms->mysql, parms->auto_mode), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + parms.auto_mode= auto_mode; + }, + my_bool, + TRUE, + r_my_bool, + /* Nothing */) + +struct mysql_next_result_params { + MYSQL *mysql; +}; +MK_ASYNC_CALLS( + mysql_next_result, + (int *ret, MYSQL *mysql), + (parms->mysql), + MYSQL *mysql, + mysql, + parms->mysql, + { + WIN_SET_NONBLOCKING(mysql) + parms.mysql= mysql; + }, + int, + 1, + r_int, + /* Nothing */) +#endif + + +/* + The following functions can newer block, and so do not have special + non-blocking versions: + + mysql_num_rows() + mysql_num_fields() + mysql_eof() + mysql_fetch_field_direct() + mysql_fetch_fields() + mysql_row_tell() + mysql_field_tell() + mysql_field_count() + mysql_affected_rows() + mysql_insert_id() + mysql_errno() + mysql_error() + mysql_sqlstate() + mysql_warning_count() + mysql_info() + mysql_thread_id() + mysql_character_set_name() + mysql_init() + mysql_ssl_set() + mysql_get_ssl_cipher() + mysql_use_result() + mysql_get_character_set_info() + mysql_set_local_infile_handler() + mysql_set_local_infile_default() + mysql_get_server_info() + mysql_get_server_name() + mysql_get_client_info() + mysql_get_client_version() + mysql_get_host_info() + mysql_get_server_version() + mysql_get_proto_info() + mysql_options() + mysql_data_seek() + mysql_row_seek() + mysql_field_seek() + mysql_fetch_lengths() + mysql_fetch_field() + mysql_escape_string() + mysql_hex_string() + mysql_real_escape_string() + mysql_debug() + myodbc_remove_escape() + mysql_thread_safe() + mysql_embedded() + mariadb_connection() + mysql_stmt_init() + mysql_stmt_fetch_column() + mysql_stmt_param_count() + mysql_stmt_attr_set() + mysql_stmt_attr_get() + mysql_stmt_bind_param() + mysql_stmt_bind_result() + mysql_stmt_result_metadata() + mysql_stmt_param_metadata() + mysql_stmt_errno() + mysql_stmt_error() + mysql_stmt_sqlstate() + mysql_stmt_row_seek() + mysql_stmt_row_tell() + mysql_stmt_data_seek() + mysql_stmt_num_rows() + mysql_stmt_affected_rows() + mysql_stmt_insert_id() + mysql_stmt_field_count() + mysql_more_results() + mysql_get_socket() + mysql_get_timeout_value() +*/ diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index cf60b888229..e9c606646a2 100755 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -53,6 +53,7 @@ SET (SQL_SOURCE log_event_old.cc rpl_record_old.cc message.h mf_iocache.cc my_decimal.cc ../sql-common/my_time.c mysqld.cc net_serv.cc ../sql-common/client_plugin.c + ../sql-common/mysql_async.c nt_servc.cc nt_servc.h opt_range.cc opt_range.h opt_sum.cc ../sql-common/pack.c parse_file.cc password.c procedure.cc protocol.cc records.cc repl_failsafe.cc rpl_filter.cc set_var.cc diff --git a/sql/Makefile.am b/sql/Makefile.am index bfd136b978f..59c4fb9a620 100644 --- a/sql/Makefile.am +++ b/sql/Makefile.am @@ -127,7 +127,8 @@ mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \ sql_servers.cc event_parse_data.cc \ opt_table_elimination.cc create_options.cc -nodist_mysqld_SOURCES = mini_client_errors.c pack.c client.c my_time.c my_user.c client_plugin.c +nodist_mysqld_SOURCES = mini_client_errors.c pack.c client.c my_time.c \ + my_user.c client_plugin.c mysql_async.c libndb_la_CPPFLAGS= @ndbcluster_includes@ libndb_la_SOURCES= ha_ndbcluster.cc \ @@ -169,6 +170,8 @@ link_sources: @LN_CP_F@ $(top_srcdir)/sql-common/pack.c pack.c rm -f client.c @LN_CP_F@ $(top_srcdir)/sql-common/client.c client.c + rm -f mysql_async.c + @LN_CP_F@ $(top_srcdir)/sql-common/mysql_async.c mysql_async.c rm -f client_plugin.c @LN_CP_F@ $(top_srcdir)/sql-common/client_plugin.c client_plugin.c rm -f my_time.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 5283edacf25..3610d97135f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,6 +24,7 @@ else LIBMYSQLCLIENT_LA = $(top_builddir)/libmysql/libmysqlclient.la endif +noinst_HEADERS = nonblock-wrappers.h EXTRA_DIST = auto_increment.res auto_increment.tst \ function.res function.tst lock_test.pl lock_test.res \ export.pl big_record.pl \ @@ -36,6 +37,9 @@ EXTRA_DIST = auto_increment.res auto_increment.tst \ bin_PROGRAMS = mysql_client_test noinst_PROGRAMS = insert_test select_test thread_test bug25714 +if HAVE_LIBEVENT +noinst_PROGRAMS += async_queries +endif INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include \ $(openssl_includes) @@ -52,6 +56,10 @@ select_test_SOURCES= select_test.c insert_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) select_test_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) +async_queries_SOURCES= async_queries.c +async_queries_CFLAGS= $(AM_CFLAGS) @libevent_includes@ +async_queries_LDADD= $(LDADD) @libevent_libs@ + bug25714_SOURCES= bug25714.c bug25714_DEPENDENCIES= $(LIBRARIES) $(pkglib_LTLIBRARIES) diff --git a/tests/async_queries.c b/tests/async_queries.c new file mode 100644 index 00000000000..677208f11f5 --- /dev/null +++ b/tests/async_queries.c @@ -0,0 +1,435 @@ +/* + Copyright 2011 Kristian Nielsen and Monty Program Ab. + + Experiments with non-blocking libmysql. + + This 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 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. If not, see . +*/ + + +/* + Run a set of queries in parallel against a server using the non-blocking + API, and compare to running same queries with the normal blocking API. +*/ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + +#define SL(s) (s), sizeof(s) +static const char *my_groups[]= { "client", NULL }; + +/* Maintaining a list of queries to run. */ +struct query_entry { + struct query_entry *next; + char *query; + int index; +}; +static struct query_entry *query_list; +static struct query_entry **tail_ptr= &query_list; +static int query_counter= 0; + + +/* State kept for each connection. */ +struct state_data { + int ST; /* State machine current state */ + struct event ev_mysql; + MYSQL mysql; + MYSQL_RES *result; + MYSQL *ret; + int err; + MYSQL_ROW row; + struct query_entry *query_element; + int index; +}; + + +static const char *opt_db= NULL; +static const char *opt_user= NULL; +static const char *opt_password= NULL; +static int tty_password= 0; +static const char *opt_host= NULL; +static const char *opt_socket= NULL; +static unsigned int opt_port= 0; +static unsigned int opt_connections= 5; +static const char *opt_query_file= NULL; + +static struct my_option options[] = +{ + {"database", 'D', "Database to use", &opt_db, &opt_db, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, + 0, 0, 0, 0, 0}, + {"host", 'h', "Connect to host", &opt_host, &opt_host, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"password", 'p', + "Password to use when connecting to server. If password is not given it's asked from the tty.", + 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, + {"port", 'P', "Port number to use for connection.", + &opt_port, &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"socket", 'S', "Socket file to use for connection", + &opt_socket, &opt_socket, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"user", 'u', "User for login if not current user", &opt_user, + &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"connections", 'n', "Number of simultaneous connections/queries.", + &opt_connections, &opt_connections, 0, GET_UINT, REQUIRED_ARG, + 0, 0, 0, 0, 0, 0}, + {"queryfile", 'q', "Name of file containing extra queries to run", + &opt_query_file, &opt_query_file, 0, GET_STR, REQUIRED_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 +fatal(struct state_data *sd, const char *msg) +{ + fprintf(stderr, "%s: %s\n", msg, (sd ? mysql_error(&sd->mysql) : "")); + exit(1); +} + + +static void state_machine_handler(int fd, short event, void *arg); + +static void +next_event(int new_st, int status, struct state_data *sd) +{ + short wait_event= 0; + struct timeval tv, *ptv; + int fd; + + if (status & MYSQL_WAIT_READ) + wait_event|= EV_READ; + if (status & MYSQL_WAIT_WRITE) + wait_event|= EV_WRITE; + if (wait_event) + fd= mysql_get_socket(&sd->mysql); + else + fd= -1; + if (status & MYSQL_WAIT_TIMEOUT) + { + tv.tv_sec= mysql_get_timeout_value(&sd->mysql); + tv.tv_usec= 0; + ptv= &tv; + } + else + ptv= NULL; + event_set(&sd->ev_mysql, fd, wait_event, state_machine_handler, sd); + event_add(&sd->ev_mysql, ptv); + sd->ST= new_st; +} + +static int +mysql_status(short event) +{ + int status= 0; + if (event & EV_READ) + status|= MYSQL_WAIT_READ; + if (event & EV_WRITE) + status|= MYSQL_WAIT_WRITE; + if (event & EV_TIMEOUT) + status|= MYSQL_WAIT_TIMEOUT; + return status; +} + + +static int num_active_connections; + +/* Shortcut for going to new state immediately without waiting. */ +#define NEXT_IMMEDIATE(sd_, new_st) do { sd_->ST= new_st; goto again; } while (0) + +static void +state_machine_handler(int fd __attribute__((unused)), short event, void *arg) +{ + struct state_data *sd= arg; + int status; + +again: + switch(sd->ST) + { + case 0: + /* Initial state, start making the connection. */ + status= mysql_real_connect_start(&sd->ret, &sd->mysql, opt_host, opt_user, opt_password, opt_db, opt_port, opt_socket, 0); + if (status) + /* Wait for connect to complete. */ + next_event(1, status, sd); + else + NEXT_IMMEDIATE(sd, 9); + break; + + case 1: + status= mysql_real_connect_cont(&sd->ret, &sd->mysql, mysql_status(event)); + if (status) + next_event(1, status, sd); + else + NEXT_IMMEDIATE(sd, 9); + break; + + case 9: + if (!sd->ret) + fatal(sd, "Failed to mysql_real_connect()"); + NEXT_IMMEDIATE(sd, 10); + break; + + case 10: + /* Now run the next query. */ + sd->query_element= query_list; + if (!sd->query_element) + { + /* No more queries, end the connection. */ + NEXT_IMMEDIATE(sd, 40); + } + query_list= query_list->next; + + sd->index= sd->query_element->index; + printf("%d ! %s\n", sd->index, sd->query_element->query); + status= mysql_real_query_start(&sd->err, &sd->mysql, sd->query_element->query, + strlen(sd->query_element->query)); + if (status) + next_event(11, status, sd); + else + NEXT_IMMEDIATE(sd, 20); + break; + + case 11: + status= mysql_real_query_cont(&sd->err, &sd->mysql, mysql_status(event)); + if (status) + next_event(11, status, sd); + else + NEXT_IMMEDIATE(sd, 20); + break; + + case 20: + free(sd->query_element->query); + free(sd->query_element); + if (sd->err) + { + printf("%d | Error: %s\n", sd->index, mysql_error(&sd->mysql)); + NEXT_IMMEDIATE(sd, 10); + } + else + { + sd->result= mysql_use_result(&sd->mysql); + if (!sd->result) + fatal(sd, "mysql_use_result() returns error"); + NEXT_IMMEDIATE(sd, 30); + } + break; + + case 30: + status= mysql_fetch_row_start(&sd->row, sd->result); + if (status) + next_event(31, status, sd); + else + NEXT_IMMEDIATE(sd, 39); + break; + + case 31: + status= mysql_fetch_row_cont(&sd->row, sd->result, mysql_status(event)); + if (status) + next_event(31, status, sd); + else + NEXT_IMMEDIATE(sd, 39); + break; + + case 39: + if (sd->row) + { + /* Got a row. */ + unsigned int i; + printf("%d - ", sd->index); + for (i= 0; i < mysql_num_fields(sd->result); i++) + printf("%s%s", (i ? "\t" : ""), (sd->row[i] ? sd->row[i] : "(null)")); + printf ("\n"); + NEXT_IMMEDIATE(sd, 30); + } + else + { + if (mysql_errno(&sd->mysql)) + { + /* An error occured. */ + printf("%d | Error: %s\n", sd->index, mysql_error(&sd->mysql)); + } + else + { + /* EOF. */ + printf("%d | EOF\n", sd->index); + } + mysql_free_result(sd->result); + NEXT_IMMEDIATE(sd, 10); + } + break; + + case 40: + status= mysql_close_start(&sd->mysql); + if (status) + next_event(41, status, sd); + else + NEXT_IMMEDIATE(sd, 50); + break; + + case 41: + status= mysql_close_cont(&sd->mysql, mysql_status(event)); + if (status) + next_event(41, status, sd); + else + NEXT_IMMEDIATE(sd, 50); + break; + + case 50: + /* We are done! */ + num_active_connections--; + if (num_active_connections == 0) + event_loopbreak(); + break; + + default: + abort(); + } +} + + +void +add_query(const char *q) +{ + struct query_entry *e; + char *q2; + size_t len; + + e= malloc(sizeof(*e)); + q2= strdup(q); + if (!e || !q2) + fatal(NULL, "Out of memory"); + + /* Remove any trailing newline. */ + len= strlen(q2); + if (q2[len] == '\n') + q2[len--]= '\0'; + if (q2[len] == '\r') + q2[len--]= '\0'; + + e->next= NULL; + e->query= q2; + e->index= query_counter++; + *tail_ptr= e; + tail_ptr= &e->next; +} + + +static my_bool +handle_option(int optid, const struct my_option *opt __attribute__((unused)), + char *arg) +{ + switch (optid) + { + case '?': + printf("Usage: async_queries [OPTIONS] query ...\n"); + my_print_help(options); + my_print_variables(options); + exit(0); + break; + + case 'p': + if (arg) + opt_password= arg; + else + tty_password= 1; + break; + } + + return 0; +} + + +int +main(int argc, char *argv[]) +{ + struct state_data *sds; + unsigned int i; + int err; + struct event_base *libevent_base; + + err= handle_options(&argc, &argv, options, handle_option); + if (err) + exit(err); + if (tty_password) + opt_password= get_tty_password(NullS); + + if (opt_query_file) + { + FILE *f= fopen(opt_query_file, "r"); + char buf[65536]; + if (!f) + fatal(NULL, "Cannot open query file"); + while (!feof(f)) + { + if (!fgets(buf, sizeof(buf), f)) + break; + add_query(buf); + } + fclose(f); + } + /* Add extra queries directly on command line. */ + while (argc > 0) + { + --argc; + add_query(*argv++); + } + + sds= malloc(opt_connections * sizeof(*sds)); + if (!sds) + fatal(NULL, "Out of memory"); + + libevent_base= event_init(); + + err= mysql_library_init(argc, argv, (char **)my_groups); + if (err) + { + fprintf(stderr, "Fatal: mysql_library_init() returns error: %d\n", err); + exit(1); + } + + num_active_connections= 0; + for (i= 0; i < opt_connections; i++) + { + mysql_init(&sds[i].mysql); + mysql_options(&sds[i].mysql, MYSQL_READ_DEFAULT_GROUP, "async_queries"); + + /* + We put the initial connect call in the first state 0 of the state machine + and run that manually, just to have everything in one place. + */ + sds[i].ST= 0; + num_active_connections++; + state_machine_handler(-1, -1, &sds[i]); + } + + event_dispatch(); + + free(sds); + + mysql_library_end(); + + event_base_free(libevent_base); + + return 0; +} diff --git a/tests/check_async_queries.pl b/tests/check_async_queries.pl new file mode 100644 index 00000000000..b599bc334d3 --- /dev/null +++ b/tests/check_async_queries.pl @@ -0,0 +1,73 @@ +#! /usr/bin/perl + +# Read the output of async_queries.c. Run the queries again serially, using +# the normal (not asynchronous) API. Compare the two results for correctness. + +use strict; +use warnings; + +use DBI; + +my $D= []; + +die "Usage: $0 \n" + unless @ARGV == 4; + +my $dbh= DBI->connect("DBI:mysql:database=$ARGV[3];host=$ARGV[0]", + $ARGV[1], $ARGV[2], + { RaiseError => 1, PrintError => 0 }); + +while () { + chomp; + if (/^([0-9]+) ! (.*);$/) { + my ($index, $query)= ($1, $2); + $D->[$index]= { QUERY => $query, OUTPUT => [] }; + } elsif (/^([0-9]+) - (.*)$/) { + my ($index, $data)= ($1, $2); + push @{$D->[$index]{OUTPUT}}, $data; + } elsif (/^([0-9]+) \| Error: (.*)$/) { + my ($index, $errmsg)= ($1, $2); + my $rows; + my $res= eval { + my $stm= $dbh->prepare($D->[$index]{QUERY}); + $stm->execute(); + $rows= $stm->fetchall_arrayref(); + 1; + }; + if ($res) { + die "Query $index succeeded, but should have failed with error.\nquery=$D->[$index]{QUERY}\nerror=$errmsg\n"; + } + my $errmsg2= $@; + if ($errmsg2 =~ /^DBD::.*failed: (.*) at .*$/s) { + $errmsg2= $1; + } else { + die "Unexpected DBD error message format: '$errmsg2'\n"; + } + if ($errmsg2 ne $errmsg) { + die "Query $index failed with different error message\nquery=$D->[$index]{QUERY}\nerror1=$errmsg\nerror2=$errmsg2\n"; + } + print "OK $index\n"; + delete $D->[$index]; + } elsif (/^([0-9]+) \| EOF$/) { + my $index= $1; + my $rows; + my $res= eval { + my $stm= $dbh->prepare($D->[$index]{QUERY}); + $stm->execute(); + $rows= $stm->fetchall_arrayref(); + 1; + }; + if (!$res) { + die "Query $index failed, but should have succeeded.\nquery=$D->[$index]{QUERY}\nerror=$@\n"; + } + my $result_string= join("\n", sort @{$D->[$index]{OUTPUT}}); + my $result_string2= join("\n", sort(map(join("\t", map((defined($_) ? $_ : "(null)"), @$_)), @$rows))); + if ($result_string ne $result_string2) { + die "Query $index result difference.\nquery=$D->[$index]{QUERY}\noutput1=\n$$result_string\noutput2=\n$result_string2\n"; + } + delete $D->[$index]; + } else { + die "Unexpected line: '$_'\n"; + } +} +$dbh->disconnect(); diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index c6efdca60f6..1ca70fd972a 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -36,6 +36,18 @@ #include #include +/* + If non_blocking_api_enabled is true, we will re-define all the blocking + API functions as wrappers that call the corresponding non-blocking API + and use poll()/select() to wait for them to complete. This way we can get + a good coverage testing of the non-blocking API as well. +*/ +static my_bool non_blocking_api_enabled= 0; +#if !defined(EMBEDDED_LIBRARY) +#define WRAP_NONBLOCK_ENABLED non_blocking_api_enabled +#include "nonblock-wrappers.h" +#endif + #define VER "2.1" #define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ #define MAX_KEY MAX_INDEXES @@ -18614,6 +18626,10 @@ static struct my_option client_test_long_options[] = #endif {"vardir", 'v', "Data dir for tests.", (char**) &opt_vardir, (char**) &opt_vardir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"non-blocking-api", 'n', + "Use the non-blocking client API for communication.", + &non_blocking_api_enabled, &non_blocking_api_enabled, 0, + GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"getopt-ll-test", 'g', "Option for testing bug in getopt library", &opt_getopt_ll_test, &opt_getopt_ll_test, 0, GET_LL, REQUIRED_ARG, 0, 0, LONGLONG_MAX, 0, 0, 0}, diff --git a/tests/nonblock-wrappers.h b/tests/nonblock-wrappers.h new file mode 100644 index 00000000000..a7346ba641c --- /dev/null +++ b/tests/nonblock-wrappers.h @@ -0,0 +1,514 @@ +/* Copyright (c) 2011 Monty Program 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; version 2 of the License. + + 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 */ + +/* + Wrappers that re-implement the normal blocking libmysql API calls in terms + of the non-blocking API calls and explicit waiting. + + Used to test the non-blocking calls using mysql_client_test. +*/ + +#ifndef __WIN__ +#include +#else +#include +#endif + +/* + Run the appropriate poll() syscall to wait for the event that libmysql + requested. Return which event(s) occured. +*/ +static int +wait_for_mysql(MYSQL *mysql, int status) +{ +#ifdef __WIN__ + fd_set rs, ws, es; + int res; + struct timeval tv, *timeout; + my_socket s= mysql_get_socket(mysql); + FD_ZERO(&rs); + FD_ZERO(&ws); + FD_ZERO(&es); + if (status & MYSQL_WAIT_READ) + FD_SET(s, &rs); + if (status & MYSQL_WAIT_WRITE) + FD_SET(s, &ws); + if (status & MYSQL_WAIT_EXCEPT) + FD_SET(s, &es); + if (status & MYSQL_WAIT_TIMEOUT) + { + tv.tv_sec= mysql_get_timeout_value(mysql); + tv.tv_usec= 0; + timeout= &tv; + } + else + timeout= NULL; + res= select(1, &rs, &ws, &es, timeout); + if (res == 0) + return MYSQL_WAIT_TIMEOUT; + else if (res == SOCKET_ERROR) + return MYSQL_WAIT_TIMEOUT; + else + { + int status= 0; + if (FD_ISSET(s, &rs)) + status|= MYSQL_WAIT_READ; + if (FD_ISSET(s, &ws)) + status|= MYSQL_WAIT_WRITE; + if (FD_ISSET(s, &es)) + status|= MYSQL_WAIT_EXCEPT; + return status; + } +#else + struct pollfd pfd; + int timeout; + int res; + + pfd.fd= mysql_get_socket(mysql); + pfd.events= + (status & MYSQL_WAIT_READ ? POLLIN : 0) | + (status & MYSQL_WAIT_WRITE ? POLLOUT : 0) | + (status & MYSQL_WAIT_EXCEPT ? POLLPRI : 0); + if (status & MYSQL_WAIT_TIMEOUT) + timeout= 1000*mysql_get_timeout_value(mysql); + else + timeout= -1; + do { + res= poll(&pfd, 1, timeout); + /* + In a real event framework, we should re-compute the timeout on getting + EINTR to account for the time elapsed before the interruption. + */ + } while (res < 0 && errno == EINTR); + if (res == 0) + return MYSQL_WAIT_TIMEOUT; + else if (res < 0) + return MYSQL_WAIT_TIMEOUT; + else + { + int status= 0; + if (pfd.revents & POLLIN) + status|= MYSQL_WAIT_READ; + if (pfd.revents & POLLOUT) + status|= MYSQL_WAIT_WRITE; + if (pfd.revents & POLLPRI) + status|= MYSQL_WAIT_EXCEPT; + return status; + } +#endif +} + + +/* + If WRAP_NONBLOCK_ENABLED is defined, it is a variable that can be used to + enable or disable the use of non-blocking API wrappers. If true the + non-blocking API will be used, if false the normal blocking API will be + called directly. +*/ +#ifdef WRAP_NONBLOCK_ENABLED +#define USE_BLOCKING(name__, invoke_blocking__) \ + if (!(WRAP_NONBLOCK_ENABLED)) return name__ invoke_blocking__; +#define USE_BLOCKING_VOID_RETURN(name__, invoke__) \ + if (!(WRAP_NONBLOCK_ENABLED)) { name__ invoke__; return; } +#else +#define USE_BLOCKING(name__, invoke_blocking__) +#define USE_BLOCKING_VOID_RETURN(name__, invoke__) +#endif + +/* + I would preferably have declared the wrappers static. + However, if we do so, compilers will warn about definitions not used, and + with -Werror this breaks compilation :-( +*/ +#define MK_WRAPPER(ret_type__, name__, decl__, invoke__, invoke_blocking__, cont_arg__, mysql__) \ +ret_type__ wrap_ ## name__ decl__ \ +{ \ + ret_type__ res; \ + int status; \ + USE_BLOCKING(name__, invoke_blocking__) \ + status= name__ ## _start invoke__; \ + while (status) \ + { \ + status= wait_for_mysql(mysql__, status); \ + status= name__ ## _cont(&res, cont_arg__, status); \ + } \ + return res; \ +} + +#define MK_WRAPPER_VOID_RETURN(name__, decl__, invoke__, cont_arg__, mysql__) \ +void wrap_ ## name__ decl__ \ +{ \ + int status; \ + USE_BLOCKING_VOID_RETURN(name__, invoke__) \ + status= name__ ## _start invoke__; \ + while (status) \ + { \ + status= wait_for_mysql(mysql__, status); \ + status= name__ ## _cont(cont_arg__, status); \ + } \ +} + +MK_WRAPPER( + MYSQL *, + mysql_real_connect, + (MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag), + (&res, mysql, host, user, passwd, db, port, unix_socket, clientflag), + (mysql, host, user, passwd, db, port, unix_socket, clientflag), + mysql, + mysql) + + +MK_WRAPPER( + int, + mysql_real_query, + (MYSQL *mysql, const char *stmt_str, unsigned long length), + (&res, mysql, stmt_str, length), + (mysql, stmt_str, length), + mysql, + mysql) + +MK_WRAPPER( + MYSQL_ROW, + mysql_fetch_row, + (MYSQL_RES *result), + (&res, result), + (result), + result, + result->handle) + +MK_WRAPPER( + int, + mysql_set_character_set, + (MYSQL *mysql, const char *csname), + (&res, mysql, csname), + (mysql, csname), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_select_db, + (MYSQL *mysql, const char *db), + (&res, mysql, db), + (mysql, db), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_send_query, + (MYSQL *mysql, const char *q, unsigned long length), + (&res, mysql, q, length), + (mysql, q, length), + mysql, + mysql) + +MK_WRAPPER( + MYSQL_RES *, + mysql_store_result, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +MK_WRAPPER_VOID_RETURN( + mysql_free_result, + (MYSQL_RES *result), + (result), + result, + result->handle) + +MK_WRAPPER_VOID_RETURN( + mysql_close, + (MYSQL *sock), + (sock), + sock, + sock) + +MK_WRAPPER( + my_bool, + mysql_change_user, + (MYSQL *mysql, const char *user, const char *passwd, const char *db), + (&res, mysql, user, passwd, db), + (mysql, user, passwd, db), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_query, + (MYSQL *mysql, const char *q), + (&res, mysql, q), + (mysql, q), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_shutdown, + (MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level), + (&res, mysql, shutdown_level), + (mysql, shutdown_level), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_dump_debug_info, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_refresh, + (MYSQL *mysql, unsigned int refresh_options), + (&res, mysql, refresh_options), + (mysql, refresh_options), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_kill, + (MYSQL *mysql, unsigned long pid), + (&res, mysql, pid), + (mysql, pid), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_set_server_option, + (MYSQL *mysql, enum enum_mysql_set_option option), + (&res, mysql, option), + (mysql, option), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_ping, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +MK_WRAPPER( + const char *, + mysql_stat, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +MK_WRAPPER( + MYSQL_RES *, + mysql_list_dbs, + (MYSQL *mysql, const char *wild), + (&res, mysql, wild), + (mysql, wild), + mysql, + mysql) + +MK_WRAPPER( + MYSQL_RES *, + mysql_list_tables, + (MYSQL *mysql, const char *wild), + (&res, mysql, wild), + (mysql, wild), + mysql, + mysql) + +MK_WRAPPER( + MYSQL_RES *, + mysql_list_processes, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +MK_WRAPPER( + MYSQL_RES *, + mysql_list_fields, + (MYSQL *mysql, const char *table, const char *wild), + (&res, mysql, table, wild), + (mysql, table, wild), + mysql, + mysql) + +MK_WRAPPER( + my_bool, + mysql_read_query_result, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_stmt_prepare, + (MYSQL_STMT *stmt, const char *query, unsigned long length), + (&res, stmt, query, length), + (stmt, query, length), + stmt, + stmt->mysql) + +MK_WRAPPER( + int, + mysql_stmt_execute, + (MYSQL_STMT *stmt), + (&res, stmt), + (stmt), + stmt, + stmt->mysql) + +MK_WRAPPER( + int, + mysql_stmt_fetch, + (MYSQL_STMT *stmt), + (&res, stmt), + (stmt), + stmt, + stmt->mysql) + +MK_WRAPPER( + int, + mysql_stmt_store_result, + (MYSQL_STMT *stmt), + (&res, stmt), + (stmt), + stmt, + stmt->mysql) + +MK_WRAPPER( + my_bool, + mysql_stmt_close, + (MYSQL_STMT *stmt), + (&res, stmt), + (stmt), + stmt, + stmt->mysql) + +MK_WRAPPER( + my_bool, + mysql_stmt_reset, + (MYSQL_STMT *stmt), + (&res, stmt), + (stmt), + stmt, + stmt->mysql) + +MK_WRAPPER( + my_bool, + mysql_stmt_free_result, + (MYSQL_STMT *stmt), + (&res, stmt), + (stmt), + stmt, + stmt->mysql) + +MK_WRAPPER( + my_bool, + mysql_stmt_send_long_data, + (MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length), + (&res, stmt, param_number, data, length), + (stmt, param_number, data, length), + stmt, + stmt->mysql) + +MK_WRAPPER( + my_bool, + mysql_commit, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +MK_WRAPPER( + my_bool, + mysql_rollback, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +MK_WRAPPER( + my_bool, + mysql_autocommit, + (MYSQL *mysql, my_bool auto_mode), + (&res, mysql, auto_mode), + (mysql, auto_mode), + mysql, + mysql) + +MK_WRAPPER( + int, + mysql_next_result, + (MYSQL *mysql), + (&res, mysql), + (mysql), + mysql, + mysql) + +#undef USE_BLOCKING +#undef MK_WRAPPER +#undef MK_WRAPPER_VOID_RETURN + + +#define mysql_real_connect wrap_mysql_real_connect +#define mysql_real_query wrap_mysql_real_query +#define mysql_fetch_row wrap_mysql_fetch_row +#define mysql_set_character_set wrap_mysql_set_character_set +#define mysql_select_db wrap_mysql_select_db +#define mysql_send_query wrap_mysql_send_query +#define mysql_store_result wrap_mysql_store_result +#define mysql_free_result wrap_mysql_free_result +#define mysql_close wrap_mysql_close +#define mysql_change_user wrap_mysql_change_user +#define mysql_query wrap_mysql_query +#define mysql_shutdown wrap_mysql_shutdown +#define mysql_dump_debug_info wrap_mysql_dump_debug_info +#define mysql_refresh wrap_mysql_refresh +#define mysql_kill wrap_mysql_kill +#define mysql_set_server_option wrap_mysql_set_server_option +#define mysql_ping wrap_mysql_ping +#define mysql_stat wrap_mysql_stat +#define mysql_list_dbs wrap_mysql_list_dbs +#define mysql_list_tables wrap_mysql_list_tables +#define mysql_list_processes wrap_mysql_list_processes +#define mysql_list_fields wrap_mysql_list_fields +#define mysql_read_query_result wrap_mysql_read_query_result +#define mysql_stmt_prepare wrap_mysql_stmt_prepare +#define mysql_stmt_execute wrap_mysql_stmt_execute +#define mysql_stmt_fetch wrap_mysql_stmt_fetch +#define mysql_stmt_store_result wrap_mysql_stmt_store_result +#define mysql_stmt_close wrap_mysql_stmt_close +#define mysql_stmt_reset wrap_mysql_stmt_reset +#define mysql_stmt_free_result wrap_mysql_stmt_free_result +#define mysql_stmt_send_long_data wrap_mysql_stmt_send_long_data +#define mysql_commit wrap_mysql_commit +#define mysql_rollback wrap_mysql_rollback +#define mysql_autocommit wrap_mysql_autocommit +#define mysql_next_result wrap_mysql_next_result diff --git a/vio/viosocket.c b/vio/viosocket.c index f780764cbe4..878378bb837 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -21,6 +21,7 @@ */ #include "vio_priv.h" +#include "my_context.h" int vio_errno(Vio *vio __attribute__((unused))) { @@ -31,18 +32,34 @@ int vio_errno(Vio *vio __attribute__((unused))) size_t vio_read(Vio * vio, uchar* buf, size_t size) { size_t r; + extern ssize_t my_recv_async(struct mysql_async_context *b, int fd, + unsigned char *buf, size_t size, uint timeout); DBUG_ENTER("vio_read"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, (uint) size)); /* Ensure nobody uses vio_read_buff and vio_read simultaneously */ DBUG_ASSERT(vio->read_end == vio->read_pos); + if (vio->async_context && vio->async_context->active) + r= my_recv_async(vio->async_context, vio->sd, buf, size, vio->read_timeout); + else + { + if (vio->async_context) + { + /* + If switching from non-blocking to blocking API usage, set the socket + back to blocking mode. + */ + my_bool old_mode; + vio_blocking(vio, TRUE, &old_mode); + } #ifdef __WIN__ - r = recv(vio->sd, buf, size,0); + r = recv(vio->sd, buf, size,0); #else - errno=0; /* For linux */ - r = read(vio->sd, buf, size); + errno=0; /* For linux */ + r = read(vio->sd, buf, size); #endif /* __WIN__ */ + } #ifndef DBUG_OFF if (r == (size_t) -1) { @@ -102,14 +119,32 @@ size_t vio_read_buff(Vio *vio, uchar* buf, size_t size) size_t vio_write(Vio * vio, const uchar* buf, size_t size) { size_t r; + extern ssize_t my_send_async(struct mysql_async_context *b, int fd, + const unsigned char *buf, size_t size, + uint timeout); DBUG_ENTER("vio_write"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, (uint) size)); + if (vio->async_context && vio->async_context->active) + r= my_send_async(vio->async_context, vio->sd, buf, size, + vio->write_timeout); + else + { + if (vio->async_context) + { + /* + If switching from non-blocking to blocking API usage, set the socket + back to blocking mode. + */ + my_bool old_mode; + vio_blocking(vio, TRUE, &old_mode); + } #ifdef __WIN__ - r = send(vio->sd, buf, size,0); + r = send(vio->sd, buf, size,0); #else - r = write(vio->sd, buf, size); + r = write(vio->sd, buf, size); #endif /* __WIN__ */ + } #ifndef DBUG_OFF if (r == (size_t) -1) { @@ -359,12 +394,17 @@ void vio_in_addr(Vio *vio, struct in_addr *in) my_bool vio_poll_read(Vio *vio,uint timeout) { + extern my_bool my_poll_read_async(struct mysql_async_context *b, + uint timeout); #ifndef HAVE_POLL #if __WIN__ int res; struct fd_set fds; struct timeval tv; DBUG_ENTER("vio_poll"); + + if (vio->async_context && vio->async_context->active) + DBUG_RETURN(my_poll_read_async(vio->async_context, timeout)); fds.fd_count= 1; fds.fd_array[0]= vio->sd; tv.tv_sec= timeout; @@ -372,12 +412,16 @@ my_bool vio_poll_read(Vio *vio,uint timeout) res= select(1, &fds, NULL, NULL, &tv) ? 0 : 1; DBUG_RETURN(res); #else + if (vio->async_context && vio->async_context->active) + return my_poll_read_async(vio->async_context, timeout); return 0; #endif #else struct pollfd fds; int res; DBUG_ENTER("vio_poll"); + if (vio->async_context && vio->async_context->active) + DBUG_RETURN(my_poll_read_async(vio->async_context, timeout)); fds.fd=vio->sd; fds.events=POLLIN; fds.revents=0; @@ -425,6 +469,11 @@ void vio_timeout(Vio *vio, uint which, uint timeout) thr_alarm or just run without read/write timeout(s) */ #endif + /* Make timeout values available for async operations. */ + if (which) + vio->write_timeout= timeout; + else + vio->read_timeout= timeout; } diff --git a/vio/viossl.c b/vio/viossl.c index 61e4d9406a7..58e4089fcd8 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -21,6 +21,7 @@ */ #include "vio_priv.h" +#include "my_context.h" #ifdef HAVE_OPENSSL @@ -90,11 +91,16 @@ report_errors(SSL* ssl) size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size) { size_t r; + extern int my_ssl_read_async(struct mysql_async_context *b, SSL *ssl, + void *buf, int size); DBUG_ENTER("vio_ssl_read"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u ssl: 0x%lx", vio->sd, (long) buf, (uint) size, (long) vio->ssl_arg)); - r= SSL_read((SSL*) vio->ssl_arg, buf, size); + if (vio->async_context && vio->async_context->active) + r= my_ssl_read_async(vio->async_context, (SSL *)vio->ssl_arg, buf, size); + else + r= SSL_read((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); @@ -107,11 +113,16 @@ size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size) size_t vio_ssl_write(Vio *vio, const uchar* buf, size_t size) { size_t r; + extern int my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, + const void *buf, int size); DBUG_ENTER("vio_ssl_write"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, (uint) size)); - r= SSL_write((SSL*) vio->ssl_arg, buf, size); + if (vio->async_context && vio->async_context->active) + r= my_ssl_write_async(vio->async_context, (SSL *)vio->ssl_arg, buf, size); + else + r= SSL_write((SSL*) vio->ssl_arg, buf, size); #ifndef DBUG_OFF if (r == (size_t) -1) report_errors((SSL*) vio->ssl_arg); From ac3c60d5528f3abdd3a1eb9fade6c05c984fe844 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 4 Jan 2012 20:10:15 +0100 Subject: [PATCH 02/45] report innodb_file_per_table, innodb_flush_log_at_trx_commit, innodb_flush_method --- plugin/feedback/feedback.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index a8c7ee82ac2..e2daa052859 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -126,6 +126,7 @@ static LEX_STRING vars_filter[]= { {C_STRING_WITH_LEN("ft\\_m%")}, {C_STRING_WITH_LEN("have\\_%")}, {C_STRING_WITH_LEN("%\\_size")}, + {C_STRING_WITH_LEN("innodb_f%")}, {C_STRING_WITH_LEN("%\\_length%")}, {C_STRING_WITH_LEN("%\\_timeout")}, {C_STRING_WITH_LEN("large\\_%")}, From 17940b652d0a078f5a28b089aa0f5362756d438e Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 6 Jan 2012 12:43:18 +0100 Subject: [PATCH 03/45] MWL#192: non-blocking client API, after-review fixes. Main change is that non-blocking operation is now an option that must be explicitly enabled with mysql_option(mysql, MYSQL_OPT_NONBLOCK, ...) before any non-blocing operation can be used. Also the CLIENT_REMEMBER_OPTIONS flag is now always enabled and thus effectively ignored (it was not really useful anyway, and this simplifies things when non-blocking mysql_real_connect() fails). --- COPYING.LESSER | 516 +++++++ Makefile.am | 2 +- client/async_example.c | 31 +- client/mysqltest.cc | 3 + include/Makefile.am | 2 +- include/my_context.h | 23 +- include/my_dbug.h | 4 + include/mysql.h | 45 +- include/mysql.h.pp | 13 +- include/mysql_async.h | 36 + include/mysql_com.h | 9 + include/sql_common.h | 3 - mysql-test/r/non_blocking_api.result | 1 + mysql-test/t/mysql_client_test_nonblock.test | 2 +- mysql-test/t/non_blocking_api.test | 4 + mysys/my_context.c | 122 +- sql-common/client.c | 165 +- sql-common/mysql_async.c | 1443 ++++++++++++------ tests/async_queries.c | 29 +- tests/mysql_client_test.c | 2 + tests/nonblock-wrappers.h | 24 +- vio/viosocket.c | 8 +- vio/viossl.c | 5 +- 23 files changed, 1727 insertions(+), 765 deletions(-) create mode 100644 COPYING.LESSER create mode 100644 include/mysql_async.h diff --git a/COPYING.LESSER b/COPYING.LESSER new file mode 100644 index 00000000000..c2c87d69256 --- /dev/null +++ b/COPYING.LESSER @@ -0,0 +1,516 @@ + + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations +below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. +^L + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it +becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. +^L + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control +compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. +^L + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. +^L + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. +^L + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. +^L + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply, and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License +may add an explicit geographical distribution limitation excluding those +countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. +^L + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS +^L + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms +of the ordinary General Public License). + + To apply these terms, attach the following notices to the library. +It is safest to attach them to the start of each source file to most +effectively convey the exclusion of warranty; and each file should +have at least the "copyright" line and a pointer to where the full +notice is found. + + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA + +Also add information on how to contact you by electronic and paper +mail. + +You should also get your employer (if you work as a programmer) or +your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James +Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/Makefile.am b/Makefile.am index cc1156fce5a..09cfae68c04 100644 --- a/Makefile.am +++ b/Makefile.am @@ -21,7 +21,7 @@ AUTOMAKE_OPTIONS = foreign # These are built from source in the Docs directory EXTRA_DIST = INSTALL-SOURCE INSTALL-WIN-SOURCE \ README COPYING EXCEPTIONS-CLIENT \ - CMakeLists.txt \ + CMakeLists.txt COPYING.LESSER \ config/ac-macros/libevent_configure.m4 SUBDIRS = . include @docs_dirs@ @zlib_dir@ \ @readline_topdir@ sql-common scripts \ diff --git a/client/async_example.c b/client/async_example.c index de9d455171c..ccb60950904 100644 --- a/client/async_example.c +++ b/client/async_example.c @@ -1,17 +1,15 @@ /* Copyright 2011 Kristian Nielsen and Monty Program Ab. - Experiments with non-blocking libmysql. + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This 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 is distributed in the hope that it will be useful, + This library 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU General Public License along with this. If not, see . @@ -133,6 +131,7 @@ doit(const char *host, const char *user, const char *password) int status; mysql_init(&mysql); + mysql_options(&mysql, MYSQL_OPT_NONBLOCK, 0); mysql_options(&mysql, MYSQL_READ_DEFAULT_GROUP, "myapp"); /* Returns 0 when done, else flag for what to wait for when need to block. */ @@ -177,8 +176,18 @@ doit(const char *host, const char *user, const char *password) fatal(&mysql, "Got error while retrieving rows"); mysql_free_result(res); - /* I suppose this must be non-blocking too. */ - mysql_close(&mysql); + /* + mysql_close() sends a COM_QUIT packet, and so in principle could block + waiting for the socket to accept the data. + In practise, for many applications it will probably be fine to use the + blocking mysql_close(). + */ + status= mysql_close_start(&mysql); + while (status) + { + status= wait_for_mysql(&mysql, status); + status= mysql_close_cont(&mysql, status); + } } int diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 7aeaa48519d..41a75a3a646 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5368,6 +5368,7 @@ void do_connect(struct st_command *command) #endif if (!(con_slot->mysql= mysql_init(0))) die("Failed on mysql_init()"); + mysql_options(con_slot->mysql, MYSQL_OPT_NONBLOCK, 0); if (opt_compress || con_compress) mysql_options(con_slot->mysql, MYSQL_OPT_COMPRESS, NullS); mysql_options(con_slot->mysql, MYSQL_OPT_LOCAL_INFILE, 0); @@ -7491,6 +7492,7 @@ int util_query(MYSQL* org_mysql, const char* query){ /* enable local infile, in non-binary builds often disabled by default */ mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, 0); + mysql_options(mysql, MYSQL_OPT_NONBLOCK, 0); safe_connect(mysql, "util", org_mysql->host, org_mysql->user, org_mysql->passwd, org_mysql->db, org_mysql->port, org_mysql->unix_socket); @@ -8226,6 +8228,7 @@ int main(int argc, char **argv) if (!(con->name = my_strdup("default", MYF(MY_WME)))) die("Out of memory"); + mysql_options(con->mysql, MYSQL_OPT_NONBLOCK, 0); safe_connect(con->mysql, con->name, opt_host, opt_user, opt_pass, opt_db, opt_port, unix_sock); diff --git a/include/Makefile.am b/include/Makefile.am index e13e7755670..b6013a6b515 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -46,7 +46,7 @@ noinst_HEADERS = config-win.h config-netware.h lf.h my_bit.h \ atomic/rwlock.h atomic/x86-gcc.h \ atomic/generic-msvc.h \ atomic/gcc_builtins.h my_libwrap.h my_stacktrace.h \ - wqueue.h waiting_threads.h my_context.h + wqueue.h waiting_threads.h my_context.h mysql_async.h EXTRA_DIST = mysql.h.pp mysql/plugin_auth.h.pp mysql/client_plugin.h.pp CMakeLists.txt diff --git a/include/my_context.h b/include/my_context.h index e19ee89a8be..14974412075 100644 --- a/include/my_context.h +++ b/include/my_context.h @@ -1,17 +1,15 @@ /* - Copyright 2011 Kristian Nielsen + Copyright 2011 Kristian Nielsen and Monty Program Ab - Experiments with non-blocking libmysql. + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This 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 is distributed in the hope that it will be useful, + This library 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU General Public License along with this. If not, see . @@ -164,11 +162,14 @@ struct mysql_async_context { /* This is set to the value that should be returned from foo_start() or foo_cont() when a call is suspended. + */ + unsigned int events_to_wait_for; + /* It is also set to the event(s) that triggered when a suspended call is resumed, eg. whether we woke up due to connection completed or timeout in mysql_real_connect_cont(). */ - unsigned int ret_status; + unsigned int events_occured; /* This is set to the result of the whole asynchronous operation when it completes. It uses a union, as different calls have different return diff --git a/include/my_dbug.h b/include/my_dbug.h index a58c6588d61..21996614153 100644 --- a/include/my_dbug.h +++ b/include/my_dbug.h @@ -134,6 +134,8 @@ extern void dbug_free_code_state(void **code_state_store); #define DEBUGGER_OFF do { _dbug_on_= 0; } while(0) #define DEBUGGER_ON do { _dbug_on_= 1; } while(0) #define IF_DBUG(A) A +#define DBUG_SWAP_CODE_STATE(arg) dbug_swap_code_state(arg) +#define DBUG_FREE_CODE_STATE(arg) dbug_free_code_state(arg) #ifndef __WIN__ #define DBUG_ABORT() (_db_flush_(), abort()) #else @@ -193,6 +195,8 @@ extern void _db_suicide_(); #define DEBUGGER_OFF do { } while(0) #define DEBUGGER_ON do { } while(0) #define IF_DBUG(A) +#define DBUG_SWAP_CODE_STATE(arg) do { } while(0) +#define DBUG_FREE_CODE_STATE(arg) do { } while(0) #define DBUG_ABORT() do { } while(0) #define DBUG_SUICIDE() do { } while(0) diff --git a/include/mysql.h b/include/mysql.h index b1ef4720879..80a0067c914 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -169,7 +169,9 @@ enum mysql_option MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, + /* MariaDB options */ + MYSQL_OPT_NONBLOCK=6000 }; /** @@ -264,8 +266,6 @@ typedef struct character_set struct st_mysql_methods; struct st_mysql_stmt; -struct st_mysql_extension; - typedef struct st_mysql { NET net; /* Communication parameters */ @@ -320,7 +320,7 @@ typedef struct st_mysql my_bool *unbuffered_fetch_owner; /* needed for embedded server - no net buffer to store the 'info' */ char *info_buffer; - struct st_mysql_extension *extension; + void *extension; } MYSQL; @@ -382,14 +382,21 @@ typedef struct st_mysql_parameters Flag bits, the asynchronous methods return a combination of these ORed together to let the application know when to resume the suspended operation. */ -typedef enum { - MYSQL_WAIT_READ= 1, /* Wait for data to be available on socket to read */ - /* mysql_get_socket_fd() will return socket descriptor*/ - MYSQL_WAIT_WRITE= 2, /* Wait for socket to be ready to write data */ - MYSQL_WAIT_EXCEPT= 4, /* Wait for select() to mark exception on socket */ - MYSQL_WAIT_TIMEOUT= 8 /* Wait until timeout occurs. Value of timeout can be */ - /* obtained from mysql_get_timeout_value() */ -} MYSQL_ASYNC_STATUS; + +/* + Wait for data to be available on socket to read. + mysql_get_socket_fd() will return socket descriptor. +*/ +#define MYSQL_WAIT_READ 1 +/* Wait for socket to be ready to write data. */ +#define MYSQL_WAIT_WRITE 2 +/* Wait for select() to mark exception on socket. */ +#define MYSQL_WAIT_EXCEPT 4 +/* + Wait until timeout occurs. Value of timeout can be obtained from + mysql_get_timeout_value(). +*/ +#define MYSQL_WAIT_TIMEOUT 8 #if !defined(MYSQL_SERVER) && !defined(EMBEDDED_LIBRARY) #define max_allowed_packet (*mysql_get_parameters()->p_max_allowed_packet) @@ -943,6 +950,7 @@ my_bool STDCALL mysql_more_results(MYSQL *mysql); int STDCALL mysql_next_result(MYSQL *mysql); int STDCALL mysql_next_result_start(int *ret, MYSQL *mysql); int STDCALL mysql_next_result_cont(int *ret, MYSQL *mysql, int status); +void STDCALL mysql_close_slow_part(MYSQL *mysql); void STDCALL mysql_close(MYSQL *sock); int STDCALL mysql_close_start(MYSQL *sock); int STDCALL mysql_close_cont(MYSQL *sock, int status); @@ -958,20 +966,7 @@ unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql); #ifdef USE_OLD_FUNCTIONS MYSQL * STDCALL mysql_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd); -int STDCALL mysql_connect_start(MYSQL **ret, MYSQL *mysql, - const char *host, const char *user, - const char *passwd); -int STDCALL mysql_connect_cont(MYSQL **ret, MYSQL *mysql, - int status); int STDCALL mysql_create_db(MYSQL *mysql, const char *DB); -int STDCALL mysql_create_db_start(int *ret, MYSQL *mysql, - const char *DB); -int STDCALL mysql_create_db_cont(int *ret, MYSQL *mysql, - int status); -int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); -int STDCALL mysql_drop_db_start(int *ret, MYSQL *mysql, - const char *DB); -int STDCALL mysql_drop_db_cont(int *ret, MYSQL *mysql, int status); int STDCALL mysql_drop_db(MYSQL *mysql, const char *DB); #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT) #endif diff --git a/include/mysql.h.pp b/include/mysql.h.pp index f66d92c06a1..ce5790b9346 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -257,7 +257,8 @@ enum mysql_option MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, + MYSQL_OPT_NONBLOCK=6000 }; struct st_mysql_options_extention; struct st_mysql_options { @@ -318,7 +319,6 @@ typedef struct character_set } MY_CHARSET_INFO; struct st_mysql_methods; struct st_mysql_stmt; -struct st_mysql_extension; typedef struct st_mysql { NET net; @@ -354,7 +354,7 @@ typedef struct st_mysql void *thd; my_bool *unbuffered_fetch_owner; char *info_buffer; - struct st_mysql_extension *extension; + void *extension; } MYSQL; typedef struct st_mysql_res { my_ulonglong row_count; @@ -392,12 +392,6 @@ typedef struct st_mysql_parameters unsigned long *p_net_buffer_length; void *extension; } MYSQL_PARAMETERS; -typedef enum { - MYSQL_WAIT_READ= 1, - MYSQL_WAIT_WRITE= 2, - MYSQL_WAIT_EXCEPT= 4, - MYSQL_WAIT_TIMEOUT= 8 -} MYSQL_ASYNC_STATUS; int mysql_server_init(int argc, char **argv, char **groups); void mysql_server_end(void); MYSQL_PARAMETERS * mysql_get_parameters(void); @@ -776,6 +770,7 @@ my_bool mysql_more_results(MYSQL *mysql); int mysql_next_result(MYSQL *mysql); int mysql_next_result_start(int *ret, MYSQL *mysql); int mysql_next_result_cont(int *ret, MYSQL *mysql, int status); +void mysql_close_slow_part(MYSQL *mysql); void mysql_close(MYSQL *sock); int mysql_close_start(MYSQL *sock); int mysql_close_cont(MYSQL *sock, int status); diff --git a/include/mysql_async.h b/include/mysql_async.h new file mode 100644 index 00000000000..a8a79b541e9 --- /dev/null +++ b/include/mysql_async.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2012 MariaDB Services and Kristian Nielsen + + 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; version 2 of the License. + + 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 */ + +/* Common definitions for MariaDB non-blocking client library. */ + +#ifndef MYSQL_ASYNC_H +#define MYSQL_ASYNC_H + +extern int my_connect_async(struct mysql_async_context *b, my_socket fd, + const struct sockaddr *name, uint namelen, + uint timeout); +extern ssize_t my_recv_async(struct mysql_async_context *b, int fd, + unsigned char *buf, size_t size, uint timeout); +extern ssize_t my_send_async(struct mysql_async_context *b, int fd, + const unsigned char *buf, size_t size, + uint timeout); +extern my_bool my_poll_read_async(struct mysql_async_context *b, + uint timeout); +extern int my_ssl_read_async(struct mysql_async_context *b, SSL *ssl, + void *buf, int size); +extern int my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, + const void *buf, int size); + +#endif /* MYSQL_ASYNC_H */ diff --git a/include/mysql_com.h b/include/mysql_com.h index affd24a4636..da19b445372 100644 --- a/include/mysql_com.h +++ b/include/mysql_com.h @@ -159,6 +159,15 @@ enum enum_server_command #define CLIENT_PLUGIN_AUTH (1UL << 19) /* Client supports plugin authentication */ #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) +/* + It used to be that if mysql_real_connect() failed, it would delete any + options set by the client, unless the CLIENT_REMEMBER_OPTIONS flag was + given. + That behaviour does not appear very useful, and it seems unlikely that + any applications would actually depend on this. So from MariaDB 5.5 we + always preserve any options set in case of failed connect, and this + option is effectively always set. +*/ #define CLIENT_REMEMBER_OPTIONS (1UL << 31) #ifdef HAVE_COMPRESS diff --git a/include/sql_common.h b/include/sql_common.h index 8bb33e3779c..2ee4b63adc8 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -32,9 +32,6 @@ struct mysql_async_context; struct st_mysql_options_extention { char *plugin_dir; char *default_auth; -}; - -struct st_mysql_extension { struct mysql_async_context *async_context; }; diff --git a/mysql-test/r/non_blocking_api.result b/mysql-test/r/non_blocking_api.result index 470e3e067f6..248e372593b 100644 --- a/mysql-test/r/non_blocking_api.result +++ b/mysql-test/r/non_blocking_api.result @@ -1,3 +1,4 @@ +drop table if exists t1; CREATE TABLE t1 (a INT PRIMARY KEY); INSERT INTO t1 VALUES (1); SELECT * FROM t1; diff --git a/mysql-test/t/mysql_client_test_nonblock.test b/mysql-test/t/mysql_client_test_nonblock.test index f212fe6abda..fc2e0b1d01b 100644 --- a/mysql-test/t/mysql_client_test_nonblock.test +++ b/mysql-test/t/mysql_client_test_nonblock.test @@ -1,6 +1,6 @@ # This runs the mysql_client_test using the non-blocking API. -# This test should work in embedded server after we fix mysqltest +# The non-blocking API is not supported in the embedded server. -- source include/not_embedded.inc SET @old_general_log= @@global.general_log; diff --git a/mysql-test/t/non_blocking_api.test b/mysql-test/t/non_blocking_api.test index b9909a1c8a4..b6b43427a76 100644 --- a/mysql-test/t/non_blocking_api.test +++ b/mysql-test/t/non_blocking_api.test @@ -1,5 +1,9 @@ # Test mixing the use of blocking and non-blocking API in a single connection. +--disable_warnings +drop table if exists t1; +--enable_warnings + --enable_non_blocking_api connect (con_nonblock,localhost,root,,test); --disable_non_blocking_api diff --git a/mysys/my_context.c b/mysys/my_context.c index cc49c0cdbb9..e3f35f0c7e6 100644 --- a/mysys/my_context.c +++ b/mysys/my_context.c @@ -1,17 +1,15 @@ /* - Copyright 2011 Kristian Nielsen + Copyright 2011 Kristian Nielsen and Monty Program Ab - Experiments with non-blocking libmysql. + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This 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 is distributed in the hope that it will be useful, + This library 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU General Public License along with this. If not, see . @@ -22,10 +20,8 @@ swapcontext(). */ -#include -#include - #include "mysys_priv.h" +#include "m_string.h" #include "my_context.h" #ifdef HAVE_VALGRIND_VALGRIND_H @@ -77,13 +73,9 @@ my_context_continue(struct my_context *c) if (!c->active) return 0; -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); err= swapcontext(&c->base_context, &c->spawned_context); -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); if (err) { fprintf(stderr, "Aieie, swapcontext() failed: %d (errno=%d)\n", @@ -135,21 +127,16 @@ my_context_yield(struct my_context *c) int my_context_init(struct my_context *c, size_t stack_size) { - if (2*sizeof(int) < sizeof(void *)) - { - fprintf(stderr, - "Error: Unable to store pointer in 2 ints on this architecture\n"); - return -1; - } +#if SIZEOF_CHARP > SIZEOF_INT*2 +#error Error: Unable to store pointer in 2 ints on this architecture +#endif + bzero(c, sizeof(*c)) if (!(c->stack= malloc(stack_size))) return -1; /* Out of memory */ c->stack_size= stack_size; #ifdef HAVE_VALGRIND_VALGRIND_H c->valgrind_stack_id= VALGRIND_STACK_REGISTER(c->stack, ((unsigned char *)(c->stack))+stack_size); -#endif -#ifndef DBUG_OFF - c->dbug_state= NULL; #endif return 0; } @@ -164,9 +151,7 @@ my_context_destroy(struct my_context *c) #endif free(c->stack); } -#ifndef DBUG_OFF - dbug_free_code_state(&c->dbug_state); -#endif + DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_UCONTEXT */ @@ -206,9 +191,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) { int ret; -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); /* There are 6 callee-save registers we need to save and restore when @@ -262,9 +245,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) : "rcx", "rdx", "r8", "r9", "r10", "r11", "memory", "cc" ); -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); return ret; } @@ -274,9 +255,7 @@ my_context_continue(struct my_context *c) { int ret; -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); __asm__ __volatile__ ( @@ -335,9 +314,7 @@ my_context_continue(struct my_context *c) : "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "memory", "cc" ); -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); return ret; } @@ -386,15 +363,13 @@ my_context_yield(struct my_context *c) int my_context_init(struct my_context *c, size_t stack_size) { + bzero(c, sizeof(*c)); if (!(c->stack_bot= malloc(stack_size))) return -1; /* Out of memory */ c->stack_top= ((unsigned char *)(c->stack_bot)) + stack_size; #ifdef HAVE_VALGRIND_VALGRIND_H c->valgrind_stack_id= VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top); -#endif -#ifndef DBUG_OFF - c->dbug_state= NULL; #endif return 0; } @@ -409,9 +384,7 @@ my_context_destroy(struct my_context *c) VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif } -#ifndef DBUG_OFF - dbug_free_code_state(&c->dbug_state); -#endif + DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_X86_64_GCC_ASM */ @@ -449,9 +422,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) { int ret; -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); /* There are 4 callee-save registers we need to save and restore when @@ -504,9 +475,7 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) : "ecx", "edx", "memory", "cc" ); -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); return ret; } @@ -516,9 +485,7 @@ my_context_continue(struct my_context *c) { int ret; -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); __asm__ __volatile__ ( @@ -573,9 +540,7 @@ my_context_continue(struct my_context *c) : "ecx", "edx", "memory", "cc" ); -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); return ret; } @@ -622,15 +587,13 @@ my_context_yield(struct my_context *c) int my_context_init(struct my_context *c, size_t stack_size) { + bzero(c, sizeof(*c)); if (!(c->stack_bot= malloc(stack_size))) return -1; /* Out of memory */ c->stack_top= ((unsigned char *)(c->stack_bot)) + stack_size; #ifdef HAVE_VALGRIND_VALGRIND_H c->valgrind_stack_id= VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top); -#endif -#ifndef DBUG_OFF - c->dbug_state= NULL; #endif return 0; } @@ -645,9 +608,7 @@ my_context_destroy(struct my_context *c) VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif } -#ifndef DBUG_OFF - dbug_free_code_state(&c->dbug_state); -#endif + DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_I386_GCC_ASM */ @@ -685,22 +646,17 @@ my_context_trampoline(void *p) int my_context_init(struct my_context *c, size_t stack_size) { -#ifndef DBUG_OFF - c->dbug_state= NULL; -#endif + bzero(c, sizeof(*c)); c->lib_fiber= CreateFiber(stack_size, my_context_trampoline, c); if (c->lib_fiber) return 0; - else - return -1; + return -1; } void my_context_destroy(struct my_context *c) { -#ifndef DBUG_OFF - dbug_free_code_state(&c->dbug_state); -#endif + DBUG_FREE_CODE_STATE(&c->dbug_state); if (c->lib_fiber) { DeleteFiber(c->lib_fiber); @@ -723,26 +679,18 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) if (current_fiber == NULL || current_fiber == (void *)0x1e00) current_fiber= ConvertThreadToFiber(c); c->app_fiber= current_fiber; -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); SwitchToFiber(c->lib_fiber); -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); return c->return_value; } int my_context_continue(struct my_context *c) { -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); SwitchToFiber(c->lib_fiber); -#ifndef DBUG_OFF - dbug_swap_code_state(&c->dbug_state); -#endif + DBUG_SWAP_CODE_STATE(&c->dbug_state); return c->return_value; } diff --git a/sql-common/client.c b/sql-common/client.c index f56a6d5111f..ad407136b92 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -108,7 +108,8 @@ my_bool net_flush(NET *net); #include "client_settings.h" #include #include -#include "my_context.h" +#include +#include #define native_password_plugin_name "mysql_native_password" #define old_password_plugin_name "mysql_old_password" @@ -1051,23 +1052,17 @@ static int add_init_command(struct st_mysql_options *options, const char *cmd) return 0; } -#define mysql_extension_get(MYSQL, X) \ - ((MYSQL)->extension ? (MYSQL)->extension->X : NULL) -#define mysql_extension_set(MYSQL, X, VAL) \ - if (!(MYSQL)->extension) \ - (MYSQL)->extension= (struct st_mysql_extension *) \ - my_malloc(sizeof(struct st_mysql_extension), \ +#define extension_set(OPTS, X, VAL) \ + if (!(OPTS)->extension) \ + (OPTS)->extension= (struct st_mysql_options_extention *) \ + my_malloc(sizeof(struct st_mysql_options_extention), \ MYF(MY_WME | MY_ZEROFILL)); \ - (MYSQL)->extension->X= VAL; + (OPTS)->extension->X= VAL; #define extension_set_string(OPTS, X, STR) \ if ((OPTS)->extension) \ my_free((OPTS)->extension->X, MYF(MY_ALLOW_ZERO_PTR)); \ - else \ - (OPTS)->extension= (struct st_mysql_options_extention *) \ - my_malloc(sizeof(struct st_mysql_options_extention), \ - MYF(MY_WME | MY_ZEROFILL)); \ - (OPTS)->extension->X= my_strdup((STR), MYF(MY_WME)); + extension_set(OPTS, X, my_strdup((STR), MYF(MY_WME))); void mysql_read_default_options(struct st_mysql_options *options, const char *filename,const char *group) @@ -1276,36 +1271,6 @@ void mysql_read_default_options(struct st_mysql_options *options, DBUG_VOID_RETURN; } -/* - Fetch the context for asynchronous API calls, allocating a new one if - necessary. -*/ -#define STACK_SIZE (4096*15) - -struct mysql_async_context * -mysql_get_async_context(MYSQL *mysql) -{ - struct mysql_async_context *b; - if ((b= mysql_extension_get(mysql, async_context))) - return b; - - if (!(b= (struct mysql_async_context *) - my_malloc(sizeof(*b), MYF(MY_ZEROFILL)))) - { - set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); - return NULL; - } - if (my_context_init(&b->async_context, STACK_SIZE)) - { - my_free(b, MYF(0)); - return NULL; - } - mysql_extension_set(mysql, async_context, b) - if (mysql->net.vio) - mysql->net.vio->async_context= b; - return b; -} - /************************************************************************** Get column lengths of the current row @@ -2581,20 +2546,16 @@ static int connect_sync_or_async(MYSQL *mysql, NET *net, my_socket fd, const struct sockaddr *name, uint namelen) { - extern int my_connect_async(struct mysql_async_context *b, my_socket fd, - const struct sockaddr *name, uint namelen, - uint timeout); - struct mysql_async_context *actxt= mysql_extension_get(mysql, async_context); - - if (actxt && actxt->active) + if (mysql->options.extension && mysql->options.extension->async_context && + mysql->options.extension->async_context->active) { my_bool old_mode; vio_blocking(net->vio, FALSE, &old_mode); - return my_connect_async(actxt, fd, name, namelen, - mysql->options.connect_timeout); + return my_connect_async(mysql->options.extension->async_context, fd, + name, namelen, mysql->options.connect_timeout); } - else - return my_connect(fd, name, namelen, mysql->options.connect_timeout); + + return my_connect(fd, name, namelen, mysql->options.connect_timeout); } MYSQL * STDCALL @@ -2612,7 +2573,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, struct sockaddr_in sock_addr; ulong pkt_length; NET *net= &mysql->net; - struct mysql_async_context *actxt; #ifdef MYSQL_SERVER thr_alarm_t alarmed; ALARM alarm_buff; @@ -2881,8 +2841,9 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, goto error; } - if ((actxt= mysql_extension_get(mysql, async_context)) && actxt->active) - net->vio->async_context= actxt; + if (mysql->options.extension && mysql->options.extension->async_context && + mysql->options.extension->async_context->active) + net->vio->async_context= mysql->options.extension->async_context; if (my_net_init(net, net->vio)) { @@ -3114,8 +3075,6 @@ error: /* Free alloced memory */ end_server(mysql); mysql_close_free(mysql); - if (!(client_flag & CLIENT_REMEMBER_OPTIONS)) - mysql_close_free_options(mysql); } DBUG_RETURN(0); } @@ -3184,7 +3143,6 @@ my_bool mysql_reconnect(MYSQL *mysql) DBUG_RETURN(1); } mysql_init(&tmp_mysql); - tmp_mysql.extension= mysql->extension; tmp_mysql.options= mysql->options; tmp_mysql.options.my_cnf_file= tmp_mysql.options.my_cnf_group= 0; tmp_mysql.rpl_pivot= mysql->rpl_pivot; @@ -3199,7 +3157,9 @@ my_bool mysql_reconnect(MYSQL *mysql) (The vio will be put in the original MYSQL permanently once we successfully reconnect, or be discarded if we fail to reconnect.) */ - if ((ctxt= mysql_extension_get(mysql, async_context)) && ctxt->active) + if (mysql->options.extension && + (ctxt= mysql->options.extension->async_context) && + mysql->options.extension->async_context->active) { hook_data.orig_mysql= mysql; hook_data.new_mysql= &tmp_mysql; @@ -3208,7 +3168,7 @@ my_bool mysql_reconnect(MYSQL *mysql) } if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, mysql->db, mysql->port, mysql->unix_socket, - mysql->client_flag | CLIENT_REMEMBER_OPTIONS)) + mysql->client_flag)) { if (ctxt) my_context_install_suspend_resume_hook(ctxt, NULL, NULL); @@ -3220,7 +3180,6 @@ my_bool mysql_reconnect(MYSQL *mysql) if (mysql_set_character_set(&tmp_mysql, mysql->charset->csname)) { DBUG_PRINT("error", ("mysql_set_character_set() failed")); - tmp_mysql.extension= NULL; bzero((char*) &tmp_mysql.options,sizeof(tmp_mysql.options)); mysql_close(&tmp_mysql); if (ctxt) @@ -3241,11 +3200,7 @@ my_bool mysql_reconnect(MYSQL *mysql) tmp_mysql.stmts= mysql->stmts; mysql->stmts= 0; - /* - Don't free options as these are now used in tmp_mysql. - Same with extension. - */ - mysql->extension= NULL; + /* Don't free options as these are now used in tmp_mysql */ bzero((char*) &mysql->options,sizeof(mysql->options)); mysql->free_me=0; mysql_close(mysql); @@ -3315,8 +3270,14 @@ static void mysql_close_free_options(MYSQL *mysql) #endif /* HAVE_SMEM */ if (mysql->options.extension) { + struct mysql_async_context *ctxt= mysql->options.extension->async_context; my_free(mysql->options.extension->plugin_dir,MYF(MY_ALLOW_ZERO_PTR)); my_free(mysql->options.extension->default_auth,MYF(MY_ALLOW_ZERO_PTR)); + if (ctxt) + { + my_context_destroy(&ctxt->async_context); + my_free(ctxt, MYF(0)); + } my_free(mysql->options.extension,MYF(0)); } bzero((char*) &mysql->options,sizeof(mysql->options)); @@ -3324,21 +3285,6 @@ static void mysql_close_free_options(MYSQL *mysql) } -static void -mysql_close_free_extension(MYSQL *mysql) -{ - if (mysql->extension) - { - if (mysql->extension->async_context) - { - my_context_destroy(&mysql->extension->async_context->async_context); - my_free(mysql->extension->async_context, MYF(0)); - } - my_free(mysql->extension, MYF(0)); - mysql->extension= NULL; - } -} - static void mysql_close_free(MYSQL *mysql) { my_free((uchar*) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR)); @@ -3447,14 +3393,11 @@ void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused)), used for non-blocking operation of blocking stuff, so that later part can _not_ be done non-blocking. - Therefore, mysql_pre_close() is used to run the parts of mysql_close() that - may block. It can be called before mysql_close(), and in that case - mysql_close() is guaranteed not to need to block. -*/ -void mysql_pre_close(MYSQL *mysql) + Therefore, mysql_close_slow_part() is used to run the parts of mysql_close() + that may block. It can be called before mysql_close(), and in that case + mysql_close() is guaranteed not to need to block. */ +void STDCALL mysql_close_slow_part(MYSQL *mysql) { - if (!mysql) - return; /* If connection is still up, send a QUIT message */ if (mysql->net.vio != 0) { @@ -3473,9 +3416,8 @@ void STDCALL mysql_close(MYSQL *mysql) if (mysql) /* Some simple safety */ { - mysql_pre_close(mysql); + mysql_close_slow_part(mysql); mysql_close_free_options(mysql); - mysql_close_free_extension(mysql); mysql_close_free(mysql); mysql_detach_stmt_list(&mysql->stmts, "mysql_close"); #ifndef TO_BE_DELETED @@ -3806,9 +3748,14 @@ mysql_fetch_lengths(MYSQL_RES *res) } +#define ASYNC_CONTEXT_DEFAULT_STACK_SIZE (4096*15) + int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) { + struct mysql_async_context *ctxt; + size_t stacksize; + DBUG_ENTER("mysql_option"); DBUG_PRINT("enter",("option: %d",(int) option)); switch (option) { @@ -3892,6 +3839,39 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) case MYSQL_DEFAULT_AUTH: extension_set_string(&mysql->options, default_auth, arg); break; + case MYSQL_OPT_NONBLOCK: + if (mysql->options.extension && + (ctxt = mysql->options.extension->async_context) != 0) + { + /* + We must not allow changing the stack size while a non-blocking call is + suspended (as the stack is then in use). + */ + if (ctxt->suspended) + DBUG_RETURN(1); + my_context_destroy(&ctxt->async_context); + my_free(ctxt, MYF(0)); + } + if (!(ctxt= (struct mysql_async_context *) + my_malloc(sizeof(*ctxt), MYF(MY_ZEROFILL)))) + { + set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); + DBUG_RETURN(1); + } + stacksize= 0; + if (arg) + stacksize= *(const size_t *)arg; + if (!stacksize) + stacksize= ASYNC_CONTEXT_DEFAULT_STACK_SIZE; + if (my_context_init(&ctxt->async_context, stacksize)) + { + my_free(ctxt, MYF(0)); + DBUG_RETURN(1); + } + extension_set(&(mysql->options), async_context, ctxt) + if (mysql->net.vio) + mysql->net.vio->async_context= ctxt; + break; default: DBUG_RETURN(1); } @@ -4102,6 +4082,5 @@ mysql_get_socket(const MYSQL *mysql) { if (mysql->net.vio) return mysql->net.vio->sd; - else - return INVALID_SOCKET; + return INVALID_SOCKET; } diff --git a/sql-common/mysql_async.c b/sql-common/mysql_async.c index a8e699e5012..a2b818b77e2 100644 --- a/sql-common/mysql_async.c +++ b/sql-common/mysql_async.c @@ -1,17 +1,15 @@ /* - Copyright 2011 Kristian Nielsen + Copyright 2011 Kristian Nielsen and Monty Program Ab - Experiments with non-blocking libmysql. + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This 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 is distributed in the hope that it will be useful, + This library 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU General Public License along with this. If not, see . @@ -28,6 +26,7 @@ #include "sql_common.h" #include "my_context.h" #include "violite.h" +#include "mysql_async.h" #ifdef __WIN__ @@ -36,15 +35,13 @@ that the socket is non-blocking at the start of every operation. */ #define WIN_SET_NONBLOCKING(mysql) { \ - my_bool old_mode__; \ - if ((mysql)->net.vio) vio_blocking((mysql)->net.vio, FALSE, &old_mode__); \ + my_bool old_mode; \ + if ((mysql)->net.vio) vio_blocking((mysql)->net.vio, FALSE, &old_mode); \ } #else #define WIN_SET_NONBLOCKING(mysql) #endif -extern struct mysql_async_context *mysql_get_async_context(MYSQL *mysql); - void my_context_install_suspend_resume_hook(struct mysql_async_context *b, @@ -62,12 +59,9 @@ my_connect_async(struct mysql_async_context *b, my_socket fd, const struct sockaddr *name, uint namelen, uint timeout) { int res; -#ifdef __WIN__ - int s_err_size; -#else - socklen_t s_err_size; -#endif + size_socket s_err_size; + b->events_to_wait_for= 0; /* Start to connect asynchronously. If this will block, we suspend the call and return control to the @@ -75,33 +69,31 @@ my_connect_async(struct mysql_async_context *b, my_socket fd, polls ready for write, indicating that the connection attempt completed. */ res= connect(fd, name, namelen); -#ifdef __WIN__ if (res != 0) { +#ifdef __WIN__ int wsa_err= WSAGetLastError(); if (wsa_err != WSAEWOULDBLOCK) return res; + b->events_to_wait_for|= MYSQL_WAIT_EXCEPT; #else - if (res < 0) - { - if (errno != EINPROGRESS && errno != EALREADY && errno != EAGAIN) + int err= errno; + if (err != EINPROGRESS && err != EALREADY && err != EAGAIN) return res; #endif + b->events_to_wait_for|= MYSQL_WAIT_WRITE; b->timeout_value= timeout; - b->ret_status= MYSQL_WAIT_WRITE | - (timeout ? MYSQL_WAIT_TIMEOUT : 0); -#ifdef __WIN__ - b->ret_status|= MYSQL_WAIT_EXCEPT; -#endif + if (timeout) + b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; if (b->suspend_resume_hook) (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); my_context_yield(&b->async_context); if (b->suspend_resume_hook) (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); - if (b->ret_status & MYSQL_WAIT_TIMEOUT) + if (b->events_occured & MYSQL_WAIT_TIMEOUT) return -1; - s_err_size= sizeof(int); + s_err_size= sizeof(res); if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &res, &s_err_size) != 0) return -1; if (res) @@ -113,6 +105,10 @@ my_connect_async(struct mysql_async_context *b, my_socket fd, return res; } +#define IS_BLOCKING_ERROR() \ + IF_WIN(WSAGetLastError() != WSAEWOULDBLOCK, \ + (errno != EAGAIN && errno != EINTR)) + ssize_t my_recv_async(struct mysql_async_context *b, int fd, unsigned char *buf, size_t size, uint timeout) @@ -121,25 +117,13 @@ my_recv_async(struct mysql_async_context *b, int fd, for (;;) { - res= recv(fd, buf, size, -#ifdef __WIN__ - 0 -#else - MSG_DONTWAIT -#endif - ); - if (res >= 0 || -#ifdef __WIN__ - WSAGetLastError() != WSAEWOULDBLOCK -#else - (errno != EAGAIN && errno != EINTR) -#endif - ) + res= recv(fd, buf, size, IF_WIN(0, MSG_DONTWAIT)); + if (res >= 0 || IS_BLOCKING_ERROR()) return res; - b->ret_status= MYSQL_WAIT_READ; + b->events_to_wait_for= MYSQL_WAIT_READ; if (timeout) { - b->ret_status|= MYSQL_WAIT_TIMEOUT; + b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; b->timeout_value= timeout; } if (b->suspend_resume_hook) @@ -147,11 +131,12 @@ my_recv_async(struct mysql_async_context *b, int fd, my_context_yield(&b->async_context); if (b->suspend_resume_hook) (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); - if (b->ret_status & MYSQL_WAIT_TIMEOUT) + if (b->events_occured & MYSQL_WAIT_TIMEOUT) return -1; } } + ssize_t my_send_async(struct mysql_async_context *b, int fd, const unsigned char *buf, size_t size, uint timeout) @@ -160,25 +145,13 @@ my_send_async(struct mysql_async_context *b, int fd, for (;;) { - res= send(fd, buf, size, -#ifdef __WIN__ - 0 -#else - MSG_DONTWAIT -#endif - ); - if (res >= 0 || -#ifdef __WIN__ - WSAGetLastError() != WSAEWOULDBLOCK -#else - (errno != EAGAIN && errno != EINTR) -#endif - ) + res= send(fd, buf, size, IF_WIN(0, MSG_DONTWAIT)); + if (res >= 0 || IS_BLOCKING_ERROR()) return res; - b->ret_status= MYSQL_WAIT_WRITE; + b->events_to_wait_for= MYSQL_WAIT_WRITE; if (timeout) { - b->ret_status|= MYSQL_WAIT_TIMEOUT; + b->events_to_wait_for|= MYSQL_WAIT_TIMEOUT; b->timeout_value= timeout; } if (b->suspend_resume_hook) @@ -186,7 +159,7 @@ my_send_async(struct mysql_async_context *b, int fd, my_context_yield(&b->async_context); if (b->suspend_resume_hook) (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); - if (b->ret_status & MYSQL_WAIT_TIMEOUT) + if (b->events_occured & MYSQL_WAIT_TIMEOUT) return -1; } } @@ -195,41 +168,51 @@ my_send_async(struct mysql_async_context *b, int fd, my_bool my_poll_read_async(struct mysql_async_context *b, uint timeout) { - b->ret_status= MYSQL_WAIT_READ | MYSQL_WAIT_TIMEOUT; + b->events_to_wait_for= MYSQL_WAIT_READ | MYSQL_WAIT_TIMEOUT; b->timeout_value= timeout; if (b->suspend_resume_hook) (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); my_context_yield(&b->async_context); if (b->suspend_resume_hook) (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); - return (b->ret_status & MYSQL_WAIT_READ) ? 0 : 1; + return (b->events_occured & MYSQL_WAIT_READ) ? 0 : 1; } #ifdef HAVE_OPENSSL +static my_bool +my_ssl_async_check_result(int res, struct mysql_async_context *b, SSL *ssl) +{ + int ssl_err; + b->events_to_wait_for= 0; + if (res >= 0) + return 1; + ssl_err= SSL_get_error(ssl, res); + if (ssl_err == SSL_ERROR_WANT_READ) + b->events_to_wait_for|= MYSQL_WAIT_READ; + else if (ssl_err == SSL_ERROR_WANT_WRITE) + b->events_to_wait_for|= MYSQL_WAIT_WRITE; + else + return 1; + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); + my_context_yield(&b->async_context); + if (b->suspend_resume_hook) + (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); + return 0; +} + int my_ssl_read_async(struct mysql_async_context *b, SSL *ssl, void *buf, int size) { - int res, ssl_err; + int res; for (;;) { res= SSL_read(ssl, buf, size); - if (res >= 0) + if (my_ssl_async_check_result(res, b, ssl)) return res; - ssl_err= SSL_get_error(ssl, res); - if (ssl_err == SSL_ERROR_WANT_READ) - b->ret_status= MYSQL_WAIT_READ; - else if (ssl_err == SSL_ERROR_WANT_WRITE) - b->ret_status= MYSQL_WAIT_WRITE; - else - return res; - if (b->suspend_resume_hook) - (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); - my_context_yield(&b->async_context); - if (b->suspend_resume_hook) - (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); } } @@ -237,25 +220,13 @@ int my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, const void *buf, int size) { - int res, ssl_err; + int res; for (;;) { res= SSL_write(ssl, buf, size); - if (res >= 0) + if (my_ssl_async_check_result(res, b, ssl)) return res; - ssl_err= SSL_get_error(ssl, res); - if (ssl_err == SSL_ERROR_WANT_READ) - b->ret_status= MYSQL_WAIT_READ; - else if (ssl_err == SSL_ERROR_WANT_WRITE) - b->ret_status= MYSQL_WAIT_WRITE; - else - return res; - if (b->suspend_resume_hook) - (*b->suspend_resume_hook)(TRUE, b->suspend_resume_hook_user_data); - my_context_yield(&b->async_context); - if (b->suspend_resume_hook) - (*b->suspend_resume_hook)(FALSE, b->suspend_resume_hook_user_data); } } #endif /* HAVE_OPENSSL */ @@ -263,12 +234,10 @@ my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, unsigned int STDCALL mysql_get_timeout_value(const MYSQL *mysql) { - if (mysql->extension && mysql->extension->async_context) - return mysql->extension->async_context->timeout_value; - else - return 0; + return mysql->options.extension->async_context->timeout_value; } + /* Now create non-blocking definitions for all the calls that may block. @@ -279,184 +248,123 @@ mysql_get_timeout_value(const MYSQL *mysql) can continue a suspended operation. */ -#define MK_ASYNC_CALLS(call__, decl_args__, invoke_args__, cont_arg__, mysql_val__, parms_mysql_val__, parms_assign__, ret_type__, err_val__, ok_val__, extra1__) \ -static void \ -call__ ## _start_internal(void *d) \ -{ \ - struct call__ ## _params *parms; \ - ret_type__ ret; \ - struct mysql_async_context *b; \ +#define MK_ASYNC_INTERNAL_BODY(call, invoke_args, mysql_val, ret_type, ok_val)\ + struct call ## _params *parms= (struct call ## _params *)d; \ + ret_type ret; \ + struct mysql_async_context *b= \ + (mysql_val)->options.extension->async_context; \ \ - parms= (struct call__ ## _params *)d; \ - b= (parms_mysql_val__)->extension->async_context; \ - \ - ret= call__ invoke_args__; \ - b->ret_result. ok_val__ = ret; \ - b->ret_status= 0; \ -} \ -int STDCALL \ -call__ ## _start decl_args__ \ -{ \ + ret= call invoke_args; \ + b->ret_result. ok_val = ret; \ + b->events_to_wait_for= 0; + +#define MK_ASYNC_START_BODY(call, mysql_val, parms_assign, err_val, ok_val, extra1) \ int res; \ struct mysql_async_context *b; \ - struct call__ ## _params parms; \ + struct call ## _params parms; \ \ - extra1__ \ - if (!(b= mysql_get_async_context((mysql_val__)))) \ - { \ - *ret= err_val__; \ - return 0; \ - } \ - parms_assign__ \ + extra1 \ + b= mysql_val->options.extension->async_context; \ + parms_assign \ \ b->active= 1; \ - res= my_context_spawn(&b->async_context, call__ ## _start_internal, &parms);\ - b->active= 0; \ - if (res < 0) \ - { \ - set_mysql_error((mysql_val__), CR_OUT_OF_MEMORY, unknown_sqlstate); \ - b->suspended= 0; \ - *ret= err_val__; \ - return 0; \ - } \ - else if (res > 0) \ + res= my_context_spawn(&b->async_context, call ## _start_internal, &parms); \ + b->active= b->suspended= 0; \ + if (res > 0) \ { \ /* Suspended. */ \ b->suspended= 1; \ - return b->ret_status; \ + return b->events_to_wait_for; \ + } \ + if (res < 0) \ + { \ + set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + *ret= err_val; \ } \ else \ - { \ - /* Finished. */ \ - b->suspended= 0; \ - *ret= b->ret_result. ok_val__; \ - return 0; \ - } \ -} \ -int STDCALL \ -call__ ## _cont(ret_type__ *ret, cont_arg__, int ready_status) \ -{ \ + *ret= b->ret_result. ok_val; \ + return 0; + +#define MK_ASYNC_CONT_BODY(mysql_val, err_val, ok_val) \ int res; \ - struct mysql_async_context *b; \ - \ - b= (mysql_val__)->extension->async_context; \ - if (!b || !b->suspended) \ + struct mysql_async_context *b= \ + (mysql_val)->options.extension->async_context; \ + if (!b->suspended) \ { \ - set_mysql_error((mysql_val__), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);\ - *ret= err_val__; \ + set_mysql_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ + *ret= err_val; \ return 0; \ } \ \ b->active= 1; \ - b->ret_status= ready_status; \ + b->events_occured= ready_status; \ res= my_context_continue(&b->async_context); \ b->active= 0; \ + if (res > 0) \ + return b->events_to_wait_for; /* (Still) suspended */ \ + b->suspended= 0; \ if (res < 0) \ { \ - set_mysql_error((mysql_val__), CR_OUT_OF_MEMORY, unknown_sqlstate); \ - b->suspended= 0; \ - *ret= err_val__; \ - return 0; \ - } \ - else if (res > 0) \ - { \ - /* Suspended. */ \ - return b->ret_status; \ + set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + *ret= err_val; \ } \ else \ - { \ - /* Finished. */ \ - b->suspended= 0; \ - *ret= b->ret_result. ok_val__; \ - return 0; \ - } \ -} + *ret= b->ret_result. ok_val; /* Finished. */ \ + return 0; -#define MK_ASYNC_CALLS_VOID_RETURN(call__, decl_args__, invoke_args__, cont_arg__, mysql_val__, parms_mysql_val__, parms_assign__, extra1__) \ -static void \ -call__ ## _start_internal(void *d) \ -{ \ - struct call__ ## _params *parms; \ - struct mysql_async_context *b; \ +#define MK_ASYNC_INTERNAL_BODY_VOID_RETURN(call, invoke_args, mysql_val) \ + struct call ## _params *parms= (struct call ## _params *)d; \ + struct mysql_async_context *b= \ + (mysql_val)->options.extension->async_context; \ \ - parms= (struct call__ ## _params *)d; \ - b= (parms_mysql_val__)->extension->async_context; \ - \ - call__ invoke_args__; \ - b->ret_status= 0; \ -} \ -int STDCALL \ -call__ ## _start decl_args__ \ -{ \ + call invoke_args; \ + b->events_to_wait_for= 0; + +#define MK_ASYNC_START_BODY_VOID_RETURN(call, mysql_val, parms_assign, extra1)\ int res; \ struct mysql_async_context *b; \ - struct call__ ## _params parms; \ + struct call ## _params parms; \ \ - extra1__ \ - if (!(b= mysql_get_async_context((mysql_val__)))) \ - { \ - return 0; \ - } \ - parms_assign__ \ + extra1 \ + b= mysql_val->options.extension->async_context; \ + parms_assign \ \ b->active= 1; \ - res= my_context_spawn(&b->async_context, call__ ## _start_internal, &parms);\ - b->active= 0; \ - if (res < 0) \ - { \ - set_mysql_error((mysql_val__), CR_OUT_OF_MEMORY, unknown_sqlstate); \ - b->suspended= 0; \ - return 0; \ - } \ - else if (res > 0) \ + res= my_context_spawn(&b->async_context, call ## _start_internal, &parms); \ + b->active= b->suspended= 0; \ + if (res > 0) \ { \ /* Suspended. */ \ b->suspended= 1; \ - return b->ret_status; \ + return b->events_to_wait_for; \ } \ - else \ - { \ - /* Finished. */ \ - b->suspended= 0; \ - return 0; \ - } \ -} \ -int STDCALL \ -call__ ## _cont(cont_arg__, int ready_status) \ -{ \ + if (res < 0) \ + set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + return 0; + +#define MK_ASYNC_CONT_BODY_VOID_RETURN(mysql_val) \ int res; \ - struct mysql_async_context *b; \ - \ - b= (mysql_val__)->extension->async_context; \ - if (!b || !b->suspended) \ + struct mysql_async_context *b= \ + (mysql_val)->options.extension->async_context; \ + if (!b->suspended) \ { \ - set_mysql_error((mysql_val__), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);\ + set_mysql_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ return 0; \ } \ \ b->active= 1; \ - b->ret_status= ready_status; \ + b->events_occured= ready_status; \ res= my_context_continue(&b->async_context); \ b->active= 0; \ + if (res > 0) \ + return b->events_to_wait_for; /* (Still) suspended */ \ + b->suspended= 0; \ if (res < 0) \ - { \ - set_mysql_error((mysql_val__), CR_OUT_OF_MEMORY, unknown_sqlstate); \ - b->suspended= 0; \ - return 0; \ - } \ - else if (res > 0) \ - { \ - /* Suspended. */ \ - return b->ret_status; \ - } \ - else \ - { \ - /* Finished. */ \ - b->suspended= 0; \ - return 0; \ - } \ -} + set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + return 0; + +/* Structure used to pass parameters from mysql_real_connect_start(). */ struct mysql_real_connect_params { MYSQL *mysql; const char *host; @@ -467,16 +375,26 @@ struct mysql_real_connect_params { const char *unix_socket; unsigned long client_flags; }; -MK_ASYNC_CALLS( +static void +mysql_real_connect_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_real_connect, - (MYSQL **ret, MYSQL *mysql, const char *host, const char *user, - const char *passwd, const char *db, unsigned int port, - const char *unix_socket, unsigned long client_flags), (parms->mysql, parms->host, parms->user, parms->passwd, parms->db, parms->port, parms->unix_socket, parms->client_flags), - MYSQL *mysql, - mysql, parms->mysql, + MYSQL *, + r_ptr) +} +int STDCALL +mysql_real_connect_start(MYSQL **ret, MYSQL *mysql, const char *host, + const char *user, const char *passwd, const char *db, + unsigned int port, const char *unix_socket, + unsigned long client_flags) +{ +MK_ASYNC_START_BODY( + mysql_real_connect, + mysql, { parms.mysql= mysql; parms.host= host; @@ -487,49 +405,84 @@ MK_ASYNC_CALLS( parms.unix_socket= unix_socket; parms.client_flags= client_flags; }, - MYSQL *, NULL, r_ptr, /* Nothing */) +} +int STDCALL +mysql_real_connect_cont(MYSQL **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} +/* Structure used to pass parameters from mysql_real_query_start(). */ struct mysql_real_query_params { MYSQL *mysql; const char *stmt_str; unsigned long length; }; -MK_ASYNC_CALLS( +static void +mysql_real_query_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_real_query, - (int *ret, MYSQL *mysql, const char *stmt_str, unsigned long length), (parms->mysql, parms->stmt_str, parms->length), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_real_query_start(int *ret, MYSQL *mysql, const char *stmt_str, unsigned long length) +{ +MK_ASYNC_START_BODY( + mysql_real_query, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.stmt_str= stmt_str; parms.length= length; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_real_query_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_fetch_row_start(). */ struct mysql_fetch_row_params { MYSQL_RES *result; }; -MK_ASYNC_CALLS( +static void +mysql_fetch_row_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_fetch_row, - (MYSQL_ROW *ret, MYSQL_RES *result), (parms->result), - MYSQL_RES *result, - result->handle, parms->result->handle, + MYSQL_ROW, + r_ptr) +} +int STDCALL +mysql_fetch_row_start(MYSQL_ROW *ret, MYSQL_RES *result) +{ +MK_ASYNC_START_BODY( + mysql_fetch_row, + result->handle, { WIN_SET_NONBLOCKING(result->handle) parms.result= result; }, - MYSQL_ROW, NULL, r_ptr, /* @@ -542,103 +495,191 @@ MK_ASYNC_CALLS( { *ret= mysql_fetch_row(result); return 0; - } -) + }) +} +int STDCALL +mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, int ready_status) +{ +MK_ASYNC_CONT_BODY( + result->handle, + NULL, + r_ptr) +} +/* Structure used to pass parameters from mysql_set_character_set_start(). */ struct mysql_set_character_set_params { MYSQL *mysql; const char *csname; }; -MK_ASYNC_CALLS( +static void +mysql_set_character_set_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_set_character_set, - (int *ret, MYSQL *mysql, const char *csname), (parms->mysql, parms->csname), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_set_character_set_start(int *ret, MYSQL *mysql, const char *csname) +{ +MK_ASYNC_START_BODY( + mysql_set_character_set, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.csname= csname; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_set_character_set_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_sekect_db_start(). */ struct mysql_select_db_params { MYSQL *mysql; const char *db; }; -MK_ASYNC_CALLS( +static void +mysql_select_db_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_select_db, - (int *ret, MYSQL *mysql, const char *db), (parms->mysql, parms->db), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_select_db_start(int *ret, MYSQL *mysql, const char *db) +{ +MK_ASYNC_START_BODY( + mysql_select_db, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.db= db; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_select_db_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_send_query_start(). */ struct mysql_send_query_params { MYSQL *mysql; const char *q; unsigned long length; }; -MK_ASYNC_CALLS( +static void +mysql_send_query_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_send_query, - (int *ret, MYSQL *mysql, const char *q, unsigned long length), (parms->mysql, parms->q, parms->length), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_send_query_start(int *ret, MYSQL *mysql, const char *q, unsigned long length) +{ +MK_ASYNC_START_BODY( + mysql_send_query, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.q= q; parms.length= length; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_send_query_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_store_result_start(). */ struct mysql_store_result_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_store_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_store_result, - (MYSQL_RES **ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_store_result_start(MYSQL_RES **ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_store_result, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - MYSQL_RES *, NULL, r_ptr, /* Nothing */) +} +int STDCALL +mysql_store_result_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} +/* Structure used to pass parameters from mysql_free_result_start(). */ struct mysql_free_result_params { MYSQL_RES *result; }; -MK_ASYNC_CALLS_VOID_RETURN( +static void +mysql_free_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY_VOID_RETURN( mysql_free_result, - (MYSQL_RES *result), (parms->result), - MYSQL_RES *result, + parms->result->handle) +} +int STDCALL +mysql_free_result_start(MYSQL_RES *result) +{ +MK_ASYNC_START_BODY_VOID_RETURN( + mysql_free_result, result->handle, - parms->result->handle, { WIN_SET_NONBLOCKING(result->handle) parms.result= result; @@ -655,30 +696,49 @@ MK_ASYNC_CALLS_VOID_RETURN( mysql_free_result(result); return 0; }) +} +int STDCALL +mysql_free_result_cont(MYSQL_RES *result, int ready_status) +{ +MK_ASYNC_CONT_BODY_VOID_RETURN(result->handle) +} -struct mysql_pre_close_params { +/* Structure used to pass parameters from mysql_close_slow_part_start(). */ +struct mysql_close_slow_part_params { MYSQL *sock; }; /* We need special handling for mysql_close(), as the first part may block, while the last part needs to free our extra library context stack. - So we do the first part (mysql_pre_close()) non-blocking, but the last part - blocking. + So we do the first part (mysql_close_slow_part()) non-blocking, but the last + part blocking. */ -extern void mysql_pre_close(MYSQL *mysql); -MK_ASYNC_CALLS_VOID_RETURN( - mysql_pre_close, - (MYSQL *sock), +static void +mysql_close_slow_part_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY_VOID_RETURN( + mysql_close_slow_part, (parms->sock), - MYSQL *sock, + parms->sock) +} +int STDCALL +mysql_close_slow_part_start(MYSQL *sock) +{ +MK_ASYNC_START_BODY_VOID_RETURN( + mysql_close_slow_part, sock, - parms->sock, { WIN_SET_NONBLOCKING(sock) parms.sock= sock; }, /* Nothing */) +} +int STDCALL +mysql_close_slow_part_cont(MYSQL *sock, int ready_status) +{ +MK_ASYNC_CONT_BODY_VOID_RETURN(sock) +} int STDCALL mysql_close_start(MYSQL *sock) { @@ -687,7 +747,7 @@ mysql_close_start(MYSQL *sock) /* It is legitimate to have NULL sock argument, which will do nothing. */ if (sock) { - res= mysql_pre_close_start(sock); + res= mysql_close_slow_part_start(sock); /* If we need to block, return now and do the rest in mysql_close_cont(). */ if (res) return res; @@ -700,101 +760,41 @@ mysql_close_cont(MYSQL *sock, int ready_status) { int res; - res= mysql_pre_close_cont(sock, ready_status); + res= mysql_close_slow_part_cont(sock, ready_status); if (res) return res; mysql_close(sock); return 0; } -#ifdef USE_OLD_FUNCTIONS -struct mysql_connect_params { - MYSQL *mysql; - const char *host; - const char *user; - const char *passwd; -}; -MK_ASYNC_CALLS( - mysql_connect, - (MYSQL **ret, MYSQL *mysql, const char *host, const char *user, const char *passwd), - (parms->mysql, parms->host, parms->user, parms->passwd), - MYSQL *mysql, - mysql, - parms->mysql, - { - WIN_SET_NONBLOCKING(mysql) - parms.mysql= mysql; - parms.host= host; - parms.user= user; - parms.passwd= passwd; - }, - MYSQL *, - NULL, - r_ptr, - /* Nothing */) - -struct mysql_create_db_params { - MYSQL *mysql; - const char *DB; -}; -MK_ASYNC_CALLS( - mysql_create_db, - (int *ret, MYSQL *mysql, const char *DB), - (parms->mysql, parms->DB), - MYSQL *mysql, - mysql, - parms->mysql, - { - WIN_SET_NONBLOCKING(mysql) - parms.mysql= mysql; - parms.DB= DB; - }, - int, - 1, - r_int, - /* Nothing */) - -struct mysql_drop_db_params { - MYSQL *mysql; - const char *DB; -}; -MK_ASYNC_CALLS( - mysql_drop_db, - (int *ret, MYSQL *mysql, const char *DB), - (parms->mysql, parms->DB), - MYSQL *mysql, - mysql, - parms->mysql, - { - WIN_SET_NONBLOCKING(mysql) - parms.mysql= mysql; - parms.DB= DB; - }, - int, - 1, - r_int, - /* Nothing */) - -#endif - /* These following are not available inside the server (neither blocking or non-blocking). */ #ifndef MYSQL_SERVER +/* Structure used to pass parameters from mysql_change_user_start(). */ struct mysql_change_user_params { MYSQL *mysql; const char *user; const char *passwd; const char *db; }; -MK_ASYNC_CALLS( +static void +mysql_change_user_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_change_user, - (my_bool *ret, MYSQL *mysql, const char *user, const char *passwd, const char *db), (parms->mysql, parms->user, parms->passwd, parms->db), - MYSQL *mysql, - mysql, parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_change_user_start(my_bool *ret, MYSQL *mysql, const char *user, const char *passwd, const char *db) +{ +MK_ASYNC_START_BODY( + mysql_change_user, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; @@ -802,295 +802,549 @@ MK_ASYNC_CALLS( parms.passwd= passwd; parms.db= db; }, - my_bool, TRUE, r_my_bool, /* Nothing */) +} +int STDCALL +mysql_change_user_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_query_start(). */ struct mysql_query_params { MYSQL *mysql; const char *q; }; -MK_ASYNC_CALLS( +static void +mysql_query_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_query, - (int *ret, MYSQL *mysql, const char *q), (parms->mysql, parms->q), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_query_start(int *ret, MYSQL *mysql, const char *q) +{ +MK_ASYNC_START_BODY( + mysql_query, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.q= q; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_query_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_shutdown_start(). */ struct mysql_shutdown_params { MYSQL *mysql; enum mysql_enum_shutdown_level shutdown_level; }; -MK_ASYNC_CALLS( +static void +mysql_shutdown_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_shutdown, - (int *ret, MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level), (parms->mysql, parms->shutdown_level), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_shutdown_start(int *ret, MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level) +{ +MK_ASYNC_START_BODY( + mysql_shutdown, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.shutdown_level= shutdown_level; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_shutdown_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_dump_debug_info_start(). */ struct mysql_dump_debug_info_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_dump_debug_info_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_dump_debug_info, - (int *ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_dump_debug_info_start(int *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_dump_debug_info, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_dump_debug_info_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_refresh_start(). */ struct mysql_refresh_params { MYSQL *mysql; unsigned int refresh_options; }; -MK_ASYNC_CALLS( +static void +mysql_refresh_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_refresh, - (int *ret, MYSQL *mysql, unsigned int refresh_options), (parms->mysql, parms->refresh_options), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_refresh_start(int *ret, MYSQL *mysql, unsigned int refresh_options) +{ +MK_ASYNC_START_BODY( + mysql_refresh, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.refresh_options= refresh_options; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_refresh_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_kill_start(). */ struct mysql_kill_params { MYSQL *mysql; unsigned long pid; }; -MK_ASYNC_CALLS( +static void +mysql_kill_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_kill, - (int *ret, MYSQL *mysql, unsigned long pid), (parms->mysql, parms->pid), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_kill_start(int *ret, MYSQL *mysql, unsigned long pid) +{ +MK_ASYNC_START_BODY( + mysql_kill, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.pid= pid; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_kill_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_set_server_option_start(). */ struct mysql_set_server_option_params { MYSQL *mysql; enum enum_mysql_set_option option; }; -MK_ASYNC_CALLS( +static void +mysql_set_server_option_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_set_server_option, - (int *ret, MYSQL *mysql, enum enum_mysql_set_option option), (parms->mysql, parms->option), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_set_server_option_start(int *ret, MYSQL *mysql, + enum enum_mysql_set_option option) +{ +MK_ASYNC_START_BODY( + mysql_set_server_option, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.option= option; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_set_server_option_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_ping_start(). */ struct mysql_ping_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_ping_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_ping, - (int *ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_ping_start(int *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_ping, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_ping_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_stat_start(). */ struct mysql_stat_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_stat_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stat, - (const char **ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + const char *, + r_const_ptr) +} +int STDCALL +mysql_stat_start(const char **ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_stat, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - const char *, NULL, r_const_ptr, /* Nothing */) +} +int STDCALL +mysql_stat_cont(const char **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_const_ptr) +} +/* Structure used to pass parameters from mysql_list_dbs_start(). */ struct mysql_list_dbs_params { MYSQL *mysql; const char *wild; }; -MK_ASYNC_CALLS( +static void +mysql_list_dbs_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_list_dbs, - (MYSQL_RES **ret, MYSQL *mysql, const char *wild), (parms->mysql, parms->wild), - MYSQL *mysql, - mysql, parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_list_dbs_start(MYSQL_RES **ret, MYSQL *mysql, const char *wild) +{ +MK_ASYNC_START_BODY( + mysql_list_dbs, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.wild= wild; }, - MYSQL_RES *, NULL, r_ptr, /* Nothing */) +} +int STDCALL +mysql_list_dbs_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} +/* Structure used to pass parameters from mysql_list_tables_start(). */ struct mysql_list_tables_params { MYSQL *mysql; const char *wild; }; -MK_ASYNC_CALLS( +static void +mysql_list_tables_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_list_tables, - (MYSQL_RES **ret, MYSQL *mysql, const char *wild), (parms->mysql, parms->wild), - MYSQL *mysql, - mysql, parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_list_tables_start(MYSQL_RES **ret, MYSQL *mysql, const char *wild) +{ +MK_ASYNC_START_BODY( + mysql_list_tables, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.wild= wild; }, - MYSQL_RES *, NULL, r_ptr, /* Nothing */) +} +int STDCALL +mysql_list_tables_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} +/* Structure used to pass parameters from mysql_list_processes_start(). */ struct mysql_list_processes_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_list_processes_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_list_processes, - (MYSQL_RES **ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_list_processes_start(MYSQL_RES **ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_list_processes, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - MYSQL_RES *, NULL, r_ptr, /* Nothing */) +} +int STDCALL +mysql_list_processes_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} +/* Structure used to pass parameters from mysql_list_fields_start(). */ struct mysql_list_fields_params { MYSQL *mysql; const char *table; const char *wild; }; -MK_ASYNC_CALLS( +static void +mysql_list_fields_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_list_fields, - (MYSQL_RES **ret, MYSQL *mysql, const char *table, const char *wild), (parms->mysql, parms->table, parms->wild), - MYSQL *mysql, - mysql, parms->mysql, + MYSQL_RES *, + r_ptr) +} +int STDCALL +mysql_list_fields_start(MYSQL_RES **ret, MYSQL *mysql, const char *table, + const char *wild) +{ +MK_ASYNC_START_BODY( + mysql_list_fields, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.table= table; parms.wild= wild; }, - MYSQL_RES *, NULL, r_ptr, /* Nothing */) +} +int STDCALL +mysql_list_fields_cont(MYSQL_RES **ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + NULL, + r_ptr) +} +/* Structure used to pass parameters from mysql_read_query_result_start(). */ struct mysql_read_query_result_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_read_query_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_read_query_result, - (my_bool *ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_read_query_result_start(my_bool *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_read_query_result, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - my_bool, TRUE, r_my_bool, /* Nothing */) +} +int STDCALL +mysql_read_query_result_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_stmt_prepare_start(). */ struct mysql_stmt_prepare_params { MYSQL_STMT *stmt; const char *query; unsigned long length; }; -MK_ASYNC_CALLS( +static void +mysql_stmt_prepare_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stmt_prepare, - (int *ret, MYSQL_STMT *stmt, const char *query, unsigned long length), (parms->stmt, parms->query, parms->length), - MYSQL_STMT *stmt, - stmt->mysql, parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_prepare_start(int *ret, MYSQL_STMT *stmt, const char *query, + unsigned long length) +{ +MK_ASYNC_START_BODY( + mysql_stmt_prepare, + stmt->mysql, { WIN_SET_NONBLOCKING(stmt->mysql) parms.stmt= stmt; parms.query= query; parms.length= length; }, - int, 1, r_int, /* If stmt->mysql==NULL then we will not block so can call directly. */ @@ -1099,22 +1353,40 @@ MK_ASYNC_CALLS( *ret= mysql_stmt_prepare(stmt, query, length); return 0; }) +} +int STDCALL +mysql_stmt_prepare_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_stmt_execute_start(). */ struct mysql_stmt_execute_params { MYSQL_STMT *stmt; }; -MK_ASYNC_CALLS( +static void +mysql_stmt_execute_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stmt_execute, - (int *ret, MYSQL_STMT *stmt), (parms->stmt), - MYSQL_STMT *stmt, - stmt->mysql, parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_execute_start(int *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_execute, + stmt->mysql, { WIN_SET_NONBLOCKING(stmt->mysql) parms.stmt= stmt; }, - int, 1, r_int, /* @@ -1126,22 +1398,40 @@ MK_ASYNC_CALLS( *ret= mysql_stmt_execute(stmt); return 0; }) +} +int STDCALL +mysql_stmt_execute_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_stmt_fetch_start(). */ struct mysql_stmt_fetch_params { MYSQL_STMT *stmt; }; -MK_ASYNC_CALLS( +static void +mysql_stmt_fetch_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stmt_fetch, - (int *ret, MYSQL_STMT *stmt), (parms->stmt), - MYSQL_STMT *stmt, - stmt->mysql, parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_fetch_start(int *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_fetch, + stmt->mysql, { WIN_SET_NONBLOCKING(stmt->mysql) parms.stmt= stmt; }, - int, 1, r_int, /* If stmt->mysql==NULL then we will not block so can call directly. */ @@ -1150,22 +1440,40 @@ MK_ASYNC_CALLS( *ret= mysql_stmt_fetch(stmt); return 0; }) +} +int STDCALL +mysql_stmt_fetch_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_stmt_store_result_start(). */ struct mysql_stmt_store_result_params { MYSQL_STMT *stmt; }; -MK_ASYNC_CALLS( +static void +mysql_stmt_store_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stmt_store_result, - (int *ret, MYSQL_STMT *stmt), (parms->stmt), - MYSQL_STMT *stmt, - stmt->mysql, parms->stmt->mysql, + int, + r_int) +} +int STDCALL +mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_store_result, + stmt->mysql, { WIN_SET_NONBLOCKING(stmt->mysql) parms.stmt= stmt; }, - int, 1, r_int, /* If stmt->mysql==NULL then we will not block so can call directly. */ @@ -1174,22 +1482,40 @@ MK_ASYNC_CALLS( *ret= mysql_stmt_store_result(stmt); return 0; }) +} +int STDCALL +mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + 1, + r_int) +} +/* Structure used to pass parameters from mysql_stmt_close_start(). */ struct mysql_stmt_close_params { MYSQL_STMT *stmt; }; -MK_ASYNC_CALLS( +static void +mysql_stmt_close_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stmt_close, - (my_bool *ret, MYSQL_STMT *stmt), (parms->stmt), - MYSQL_STMT *stmt, - stmt->mysql, parms->stmt->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_close, + stmt->mysql, { WIN_SET_NONBLOCKING(stmt->mysql) parms.stmt= stmt; }, - my_bool, TRUE, r_my_bool, /* If stmt->mysql==NULL then we will not block so can call directly. */ @@ -1198,22 +1524,40 @@ MK_ASYNC_CALLS( *ret= mysql_stmt_close(stmt); return 0; }) +} +int STDCALL +mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_stmt_reset_start(). */ struct mysql_stmt_reset_params { MYSQL_STMT *stmt; }; -MK_ASYNC_CALLS( +static void +mysql_stmt_reset_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stmt_reset, - (my_bool *ret, MYSQL_STMT *stmt), (parms->stmt), - MYSQL_STMT *stmt, - stmt->mysql, parms->stmt->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_reset, + stmt->mysql, { WIN_SET_NONBLOCKING(stmt->mysql) parms.stmt= stmt; }, - my_bool, TRUE, r_my_bool, /* If stmt->mysql==NULL then we will not block so can call directly. */ @@ -1222,22 +1566,40 @@ MK_ASYNC_CALLS( *ret= mysql_stmt_reset(stmt); return 0; }) +} +int STDCALL +mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_stmt_free_result_start(). */ struct mysql_stmt_free_result_params { MYSQL_STMT *stmt; }; -MK_ASYNC_CALLS( +static void +mysql_stmt_free_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stmt_free_result, - (my_bool *ret, MYSQL_STMT *stmt), (parms->stmt), - MYSQL_STMT *stmt, - stmt->mysql, parms->stmt->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt) +{ +MK_ASYNC_START_BODY( + mysql_stmt_free_result, + stmt->mysql, { WIN_SET_NONBLOCKING(stmt->mysql) parms.stmt= stmt; }, - my_bool, TRUE, r_my_bool, /* If stmt->mysql==NULL then we will not block so can call directly. */ @@ -1246,20 +1608,41 @@ MK_ASYNC_CALLS( *ret= mysql_stmt_free_result(stmt); return 0; }) +} +int STDCALL +mysql_stmt_free_result_cont(my_bool *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_stmt_send_long_data_start(). */ struct mysql_stmt_send_long_data_params { MYSQL_STMT *stmt; unsigned int param_number; const char *data; unsigned long length; }; -MK_ASYNC_CALLS( +static void +mysql_stmt_send_long_data_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_stmt_send_long_data, - (my_bool *ret, MYSQL_STMT *stmt, unsigned int param_number, const char *data, unsigned long length), (parms->stmt, parms->param_number, parms->data, parms->length), - MYSQL_STMT *stmt, - stmt->mysql, parms->stmt->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, + unsigned int param_number, + const char *data, unsigned long length) +{ +MK_ASYNC_START_BODY( + mysql_stmt_send_long_data, + stmt->mysql, { WIN_SET_NONBLOCKING(stmt->mysql) parms.stmt= stmt; @@ -1267,7 +1650,6 @@ MK_ASYNC_CALLS( parms.data= data; parms.length= length; }, - my_bool, TRUE, r_my_bool, /* If stmt->mysql==NULL then we will not block so can call directly. */ @@ -1276,87 +1658,176 @@ MK_ASYNC_CALLS( *ret= mysql_stmt_send_long_data(stmt, param_number, data, length); return 0; }) +} +int STDCALL +mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, int ready_status) +{ +MK_ASYNC_CONT_BODY( + stmt->mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_commit_start(). */ struct mysql_commit_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_commit_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_commit, - (my_bool *ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_commit_start(my_bool *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_commit, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - my_bool, TRUE, r_my_bool, /* Nothing */) +} +int STDCALL +mysql_commit_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_rollback_start(). */ struct mysql_rollback_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_rollback_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_rollback, - (my_bool *ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_rollback_start(my_bool *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_rollback, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - my_bool, TRUE, r_my_bool, /* Nothing */) +} +int STDCALL +mysql_rollback_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_autocommit_start(). */ struct mysql_autocommit_params { MYSQL *mysql; my_bool auto_mode; }; -MK_ASYNC_CALLS( +static void +mysql_autocommit_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_autocommit, - (my_bool *ret, MYSQL *mysql, my_bool auto_mode), (parms->mysql, parms->auto_mode), - MYSQL *mysql, - mysql, parms->mysql, + my_bool, + r_my_bool) +} +int STDCALL +mysql_autocommit_start(my_bool *ret, MYSQL *mysql, my_bool auto_mode) +{ +MK_ASYNC_START_BODY( + mysql_autocommit, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; parms.auto_mode= auto_mode; }, - my_bool, TRUE, r_my_bool, /* Nothing */) +} +int STDCALL +mysql_autocommit_cont(my_bool *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + TRUE, + r_my_bool) +} +/* Structure used to pass parameters from mysql_next_result_start(). */ struct mysql_next_result_params { MYSQL *mysql; }; -MK_ASYNC_CALLS( +static void +mysql_next_result_start_internal(void *d) +{ +MK_ASYNC_INTERNAL_BODY( mysql_next_result, - (int *ret, MYSQL *mysql), (parms->mysql), - MYSQL *mysql, - mysql, parms->mysql, + int, + r_int) +} +int STDCALL +mysql_next_result_start(int *ret, MYSQL *mysql) +{ +MK_ASYNC_START_BODY( + mysql_next_result, + mysql, { WIN_SET_NONBLOCKING(mysql) parms.mysql= mysql; }, - int, 1, r_int, /* Nothing */) +} +int STDCALL +mysql_next_result_cont(int *ret, MYSQL *mysql, int ready_status) +{ +MK_ASYNC_CONT_BODY( + mysql, + 1, + r_int) +} #endif +/* + The following functions are deprecated, and so have no non-blocking version: + + mysql_connect + mysql_create_db + mysql_drop_db +*/ + /* The following functions can newer block, and so do not have special non-blocking versions: diff --git a/tests/async_queries.c b/tests/async_queries.c index 677208f11f5..0f9b39e1938 100644 --- a/tests/async_queries.c +++ b/tests/async_queries.c @@ -1,17 +1,15 @@ /* Copyright 2011 Kristian Nielsen and Monty Program Ab. - Experiments with non-blocking libmysql. + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - This 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 is distributed in the hope that it will be useful, + This library 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. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. You should have received a copy of the GNU General Public License along with this. If not, see . @@ -93,7 +91,7 @@ static struct my_option options[] = &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"connections", 'n', "Number of simultaneous connections/queries.", &opt_connections, &opt_connections, 0, GET_UINT, REQUIRED_ARG, - 0, 0, 0, 0, 0, 0}, + 5, 0, 0, 0, 0, 0}, {"queryfile", 'q', "Name of file containing extra queries to run", &opt_query_file, &opt_query_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -219,8 +217,8 @@ again: break; case 20: - free(sd->query_element->query); - free(sd->query_element); + my_free(sd->query_element->query, MYF(0)); + my_free(sd->query_element, MYF(0)); if (sd->err) { printf("%d | Error: %s\n", sd->index, mysql_error(&sd->mysql)); @@ -315,8 +313,8 @@ add_query(const char *q) char *q2; size_t len; - e= malloc(sizeof(*e)); - q2= strdup(q); + e= my_malloc(sizeof(*e), MYF(0)); + q2= my_strdup(q, MYF(0)); if (!e || !q2) fatal(NULL, "Out of memory"); @@ -395,7 +393,7 @@ main(int argc, char *argv[]) add_query(*argv++); } - sds= malloc(opt_connections * sizeof(*sds)); + sds= my_malloc(opt_connections * sizeof(*sds), MYF(0)); if (!sds) fatal(NULL, "Out of memory"); @@ -412,6 +410,7 @@ main(int argc, char *argv[]) for (i= 0; i < opt_connections; i++) { mysql_init(&sds[i].mysql); + mysql_options(&sds[i].mysql, MYSQL_OPT_NONBLOCK, 0); mysql_options(&sds[i].mysql, MYSQL_READ_DEFAULT_GROUP, "async_queries"); /* diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index 1ca70fd972a..8ceeaf57399 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -260,6 +260,8 @@ static MYSQL *mysql_client_init(MYSQL* con) if (res && shared_memory_base_name) mysql_options(res, MYSQL_SHARED_MEMORY_BASE_NAME, shared_memory_base_name); #endif + if (res && non_blocking_api_enabled) + mysql_options(res, MYSQL_OPT_NONBLOCK, 0); return res; } diff --git a/tests/nonblock-wrappers.h b/tests/nonblock-wrappers.h index a7346ba641c..3ed470b3400 100644 --- a/tests/nonblock-wrappers.h +++ b/tests/nonblock-wrappers.h @@ -1,17 +1,19 @@ -/* Copyright (c) 2011 Monty Program Ab +/* + Copyright 2011 Kristian Nielsen and Monty Program 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; version 2 of the License. + This file is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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. + This library 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 + Lesser 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 */ + You should have received a copy of the GNU General Public License + along with this. If not, see . +*/ /* Wrappers that re-implement the normal blocking libmysql API calls in terms diff --git a/vio/viosocket.c b/vio/viosocket.c index 878378bb837..63e3d4558a4 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -22,6 +22,7 @@ #include "vio_priv.h" #include "my_context.h" +#include int vio_errno(Vio *vio __attribute__((unused))) { @@ -32,8 +33,6 @@ int vio_errno(Vio *vio __attribute__((unused))) size_t vio_read(Vio * vio, uchar* buf, size_t size) { size_t r; - extern ssize_t my_recv_async(struct mysql_async_context *b, int fd, - unsigned char *buf, size_t size, uint timeout); DBUG_ENTER("vio_read"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, (uint) size)); @@ -119,9 +118,6 @@ size_t vio_read_buff(Vio *vio, uchar* buf, size_t size) size_t vio_write(Vio * vio, const uchar* buf, size_t size) { size_t r; - extern ssize_t my_send_async(struct mysql_async_context *b, int fd, - const unsigned char *buf, size_t size, - uint timeout); DBUG_ENTER("vio_write"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, (uint) size)); @@ -394,8 +390,6 @@ void vio_in_addr(Vio *vio, struct in_addr *in) my_bool vio_poll_read(Vio *vio,uint timeout) { - extern my_bool my_poll_read_async(struct mysql_async_context *b, - uint timeout); #ifndef HAVE_POLL #if __WIN__ int res; diff --git a/vio/viossl.c b/vio/viossl.c index 58e4089fcd8..efc41ee5f67 100644 --- a/vio/viossl.c +++ b/vio/viossl.c @@ -22,6 +22,7 @@ #include "vio_priv.h" #include "my_context.h" +#include #ifdef HAVE_OPENSSL @@ -91,8 +92,6 @@ report_errors(SSL* ssl) size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size) { size_t r; - extern int my_ssl_read_async(struct mysql_async_context *b, SSL *ssl, - void *buf, int size); DBUG_ENTER("vio_ssl_read"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u ssl: 0x%lx", vio->sd, (long) buf, (uint) size, (long) vio->ssl_arg)); @@ -113,8 +112,6 @@ size_t vio_ssl_read(Vio *vio, uchar* buf, size_t size) size_t vio_ssl_write(Vio *vio, const uchar* buf, size_t size) { size_t r; - extern int my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, - const void *buf, int size); DBUG_ENTER("vio_ssl_write"); DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf, (uint) size)); From 6ef4f89deb525d08381f426d5f4644475ad953c6 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 7 Jan 2012 23:20:08 +0100 Subject: [PATCH 04/45] fix typo. --- mysys/my_context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysys/my_context.c b/mysys/my_context.c index e3f35f0c7e6..de2af969448 100644 --- a/mysys/my_context.c +++ b/mysys/my_context.c @@ -130,7 +130,7 @@ my_context_init(struct my_context *c, size_t stack_size) #if SIZEOF_CHARP > SIZEOF_INT*2 #error Error: Unable to store pointer in 2 ints on this architecture #endif - bzero(c, sizeof(*c)) + bzero(c, sizeof(*c)); if (!(c->stack= malloc(stack_size))) return -1; /* Out of memory */ c->stack_size= stack_size; From d5678e1778d684610b50ab8f2b8f11289d075c02 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 8 Jan 2012 10:13:39 +0100 Subject: [PATCH 05/45] Fix non-ssl build. --- include/mysql_async.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/mysql_async.h b/include/mysql_async.h index a8a79b541e9..2c84d5bc1b6 100644 --- a/include/mysql_async.h +++ b/include/mysql_async.h @@ -28,9 +28,11 @@ extern ssize_t my_send_async(struct mysql_async_context *b, int fd, uint timeout); extern my_bool my_poll_read_async(struct mysql_async_context *b, uint timeout); +#ifdef HAVE_OPENSSL extern int my_ssl_read_async(struct mysql_async_context *b, SSL *ssl, void *buf, int size); extern int my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, const void *buf, int size); +#endif #endif /* MYSQL_ASYNC_H */ From dacaaf22a3f132df5573fe8e58c0617c30c5e9fc Mon Sep 17 00:00:00 2001 From: Karen Langford Date: Wed, 11 Jan 2012 18:40:29 +0100 Subject: [PATCH 06/45] Fixes required to build on AIX --- cmd-line-utils/libedit/chartype.h | 6 +++--- cmd-line-utils/libedit/eln.c | 2 +- cmd-line-utils/libedit/readline.c | 2 +- unittest/mysys/bitmap-t.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd-line-utils/libedit/chartype.h b/cmd-line-utils/libedit/chartype.h index 678d13683be..40012afb47d 100644 --- a/cmd-line-utils/libedit/chartype.h +++ b/cmd-line-utils/libedit/chartype.h @@ -45,11 +45,11 @@ * seems to actually advertise this properly, despite Unicode 3.1 having * been around since 2001... */ -/* XXXMYSQL : Added FreeBSD to bypass this check. - TODO : Verify if FreeBSD stores ISO 10646 in wchar_t. */ +/* XXXMYSQL : Added FreeBSD & AIX to bypass this check. + TODO : Verify if FreeBSD & AIX stores ISO 10646 in wchar_t. */ #if !defined(__NetBSD__) && !defined(__sun) \ && !(defined(__APPLE__) && defined(__MACH__)) \ - && !defined(__FreeBSD__) + && !defined(__FreeBSD__) && !defined(_AIX) #ifndef __STDC_ISO_10646__ /* In many places it is assumed that the first 127 code points are ASCII * compatible, so ensure wchar_t indeed does ISO 10646 and not some other diff --git a/cmd-line-utils/libedit/eln.c b/cmd-line-utils/libedit/eln.c index 4b9f16c38f3..f996367115a 100644 --- a/cmd-line-utils/libedit/eln.c +++ b/cmd-line-utils/libedit/eln.c @@ -200,7 +200,7 @@ el_set(EditLine *el, int op, ...) ret = -1; goto out; } - // XXX: The two strdup's leak + /* XXX: The two strdups leak. */ ret = map_addfunc(el, Strdup(wargv[0]), Strdup(wargv[1]), func); ct_free_argv(wargv); diff --git a/cmd-line-utils/libedit/readline.c b/cmd-line-utils/libedit/readline.c index eaf26d4c497..a2a92edc1b4 100644 --- a/cmd-line-utils/libedit/readline.c +++ b/cmd-line-utils/libedit/readline.c @@ -1978,7 +1978,7 @@ rl_callback_read_char() } else wbuf = NULL; (*(void (*)(const char *))rl_linefunc)(wbuf); - //el_set(e, EL_UNBUFFERED, 1); + /*el_set(e, EL_UNBUFFERED, 1);*/ } } diff --git a/unittest/mysys/bitmap-t.c b/unittest/mysys/bitmap-t.c index 0127b7b86f4..9a5337c79b5 100644 --- a/unittest/mysys/bitmap-t.c +++ b/unittest/mysys/bitmap-t.c @@ -429,7 +429,7 @@ my_bool test_intersect(MY_BITMAP *map, uint bitsize) { uint bitsize2 = 1 + get_rand_bit(MAX_TESTED_BITMAP_SIZE - 1); MY_BITMAP map2; - uint32 map2buf[bitsize2]; + uint32 map2buf[MAX_TESTED_BITMAP_SIZE]; uint i, test_bit1, test_bit2, test_bit3; if (bitmap_init(&map2, map2buf, bitsize2, FALSE)) { From 8fedf8ac75dc64eea281df27baa064c00078580a Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 25 Jan 2012 11:34:43 +0100 Subject: [PATCH 07/45] mtr runs only "big" tests, if --big-test is repeated twice --- mysql-test/lib/mtr_cases.pm | 7 +++++++ mysql-test/mysql-test-run.pl | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm index 727e56ac77a..8b87ad367e3 100644 --- a/mysql-test/lib/mtr_cases.pm +++ b/mysql-test/lib/mtr_cases.pm @@ -925,6 +925,13 @@ sub collect_one_test_case { return $tinfo } + if ( ! $tinfo->{'big_test'} and $::opt_big_test > 1 ) + { + $tinfo->{'skip'}= 1; + $tinfo->{'comment'}= "Small test"; + return $tinfo + } + if ( $tinfo->{'need_debug'} && ! $::debug_compiled_binaries ) { $tinfo->{'skip'}= 1; diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index b2c7ee2fc37..cb6f7b4a486 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -986,7 +986,7 @@ sub command_line_setup { 'skip-test=s' => \&collect_option, 'do-test=s' => \&collect_option, 'start-from=s' => \&collect_option, - 'big-test' => \$opt_big_test, + 'big-test+' => \$opt_big_test, 'combination=s' => \@opt_combinations, 'skip-combinations' => \&collect_option, 'experimental=s' => \@opt_experimentals, @@ -5984,7 +5984,8 @@ Options to control what test suites or cases to run list of suite names. The default is: "$DEFAULT_SUITES" skip-rpl Skip the replication test cases. - big-test Also run tests marked as "big" + big-test Also run tests marked as "big". Repeat this option + twice to run only "big" tests. staging-run Run a limited number of tests (no slow tests). Used for running staging trees with valgrind. enable-disabled Run also tests marked as disabled From 7c8ebb532eef543a9b98107c164a12a49e28d0ca Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Jan 2012 13:45:58 +0100 Subject: [PATCH 08/45] MWL#192: Fix problem when we first enable MYSQL_OPT_NONBLOCK, then connect in normal blocking style, then later do a non-blocking operation. In this case, the vio->async_context was not set up correctly, so that non-blocking operation was not properly handled. --- sql-common/client.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql-common/client.c b/sql-common/client.c index ad407136b92..b047d177830 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -2841,8 +2841,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, goto error; } - if (mysql->options.extension && mysql->options.extension->async_context && - mysql->options.extension->async_context->active) + if (mysql->options.extension && mysql->options.extension->async_context) net->vio->async_context= mysql->options.extension->async_context; if (my_net_init(net, net->vio)) From 607aab9c1d68a3b80bdb52a6c73fd6be1aa52764 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 16 Feb 2012 08:49:10 +0200 Subject: [PATCH 09/45] Counters for Index Condition Pushdown added (MDEV-130). --- mysql-test/include/icp_tests.inc | 22 ++++++++++++++++++++++ mysql-test/r/innodb_icp.result | 27 +++++++++++++++++++++++++++ mysql-test/r/join_cache.result | 17 +++++++++++++++++ mysql-test/r/maria_icp.result | 27 +++++++++++++++++++++++++++ mysql-test/r/myisam_icp.result | 27 +++++++++++++++++++++++++++ mysql-test/r/status.result | 6 +++++- mysql-test/r/status_user.result | 2 ++ mysql-test/t/join_cache.test | 5 +++++ sql/mysqld.cc | 2 ++ sql/sql_class.h | 2 ++ sql/sql_join_cache.cc | 22 ++++++++++++++++++++-- sql/sql_join_cache.h | 2 ++ storage/maria/ha_maria.cc | 8 +++++++- storage/myisam/ha_myisam.cc | 8 +++++++- storage/xtradb/handler/ha_innodb.cc | 8 +++++++- storage/xtradb/handler/ha_innodb.h | 2 ++ 16 files changed, 181 insertions(+), 6 deletions(-) diff --git a/mysql-test/include/icp_tests.inc b/mysql-test/include/icp_tests.inc index e77cb220375..f412843ded0 100644 --- a/mysql-test/include/icp_tests.inc +++ b/mysql-test/include/icp_tests.inc @@ -852,3 +852,25 @@ SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2; +--echo # check "Handler_pushed" status varuiables +CREATE TABLE t1 ( + c1 CHAR(1), + c2 CHAR(1), + KEY (c1) +); + +INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); + +flush status; +show status like "Handler_pushed%"; + +SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; + +show status like "Handler_pushed%"; + +SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; + +show status like "Handler_pushed%"; + +DROP TABLE t1; + diff --git a/mysql-test/r/innodb_icp.result b/mysql-test/r/innodb_icp.result index 08238289330..ccbae98d137 100644 --- a/mysql-test/r/innodb_icp.result +++ b/mysql-test/r/innodb_icp.result @@ -808,5 +808,32 @@ COUNT(*) 1478 SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2; +# check "Handler_pushed" status varuiables +CREATE TABLE t1 ( +c1 CHAR(1), +c2 CHAR(1), +KEY (c1) +); +INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); +flush status; +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 0 +Handler_pushed_index_cond_filtered 0 +SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; +c1 c2 +4 4 +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 2 +Handler_pushed_index_cond_filtered 1 +SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; +c1 c2 +4 4 +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 2 +Handler_pushed_index_cond_filtered 1 +DROP TABLE t1; set optimizer_switch=@innodb_icp_tmp; set storage_engine= @save_storage_engine; diff --git a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result index dda0f4c8f66..6908f40e854 100644 --- a/mysql-test/r/join_cache.result +++ b/mysql-test/r/join_cache.result @@ -3506,6 +3506,7 @@ insert into t2 values (2,1, 'qwerty'),(2,2, 'qwerty'),(2,3, 'qwerty'), insert into t2 values (3,1, 'qwerty'),(3,4, 'qwerty'); insert into t2 values (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'), (4,4, 'qwerty'); +flush status; set join_cache_level=5; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3519,6 +3520,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; 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 t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 20 +Handler_pushed_index_cond_filtered 16 set join_cache_level=6; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3532,6 +3537,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; 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 t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 40 +Handler_pushed_index_cond_filtered 32 set join_cache_level=7; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3545,6 +3554,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; 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 t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 60 +Handler_pushed_index_cond_filtered 48 set join_cache_level=8; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3558,6 +3571,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; 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 t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 80 +Handler_pushed_index_cond_filtered 64 drop table t1,t2; set join_cache_level=default; # diff --git a/mysql-test/r/maria_icp.result b/mysql-test/r/maria_icp.result index 2d2b4d0c1f7..b9d3ca6c7c0 100644 --- a/mysql-test/r/maria_icp.result +++ b/mysql-test/r/maria_icp.result @@ -814,5 +814,32 @@ COUNT(*) 1478 SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2; +# check "Handler_pushed" status varuiables +CREATE TABLE t1 ( +c1 CHAR(1), +c2 CHAR(1), +KEY (c1) +); +INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); +flush status; +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 0 +Handler_pushed_index_cond_filtered 0 +SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; +c1 c2 +4 4 +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 2 +Handler_pushed_index_cond_filtered 1 +SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; +c1 c2 +4 4 +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 2 +Handler_pushed_index_cond_filtered 1 +DROP TABLE t1; set storage_engine= @save_storage_engine; set optimizer_switch=@maria_icp_tmp; diff --git a/mysql-test/r/myisam_icp.result b/mysql-test/r/myisam_icp.result index c480e35df42..3171753adb4 100644 --- a/mysql-test/r/myisam_icp.result +++ b/mysql-test/r/myisam_icp.result @@ -812,6 +812,33 @@ COUNT(*) 1478 SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2; +# check "Handler_pushed" status varuiables +CREATE TABLE t1 ( +c1 CHAR(1), +c2 CHAR(1), +KEY (c1) +); +INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); +flush status; +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 0 +Handler_pushed_index_cond_filtered 0 +SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; +c1 c2 +4 4 +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 2 +Handler_pushed_index_cond_filtered 1 +SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; +c1 c2 +4 4 +show status like "Handler_pushed%"; +Variable_name Value +Handler_pushed_index_cond_checks 2 +Handler_pushed_index_cond_filtered 1 +DROP TABLE t1; drop table if exists t0, t1, t1i, t1m; # # BUG#826935 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result index b0744726390..e75cabe0e58 100644 --- a/mysql-test/r/status.result +++ b/mysql-test/r/status.result @@ -276,6 +276,8 @@ Handler_commit 0 Handler_delete 0 Handler_discover 0 Handler_prepare 0 +Handler_pushed_index_cond_checks 0 +Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 4 Handler_read_next 0 @@ -297,7 +299,7 @@ Created_tmp_files 0 Created_tmp_tables 2 Handler_tmp_update 2 Handler_tmp_write 7 -Rows_tmp_read 35 +Rows_tmp_read 37 drop table t1; CREATE TABLE t1 (i int(11) DEFAULT NULL, KEY i (i) ) ENGINE=MyISAM; insert into t1 values (1),(2),(3),(4),(5); @@ -311,6 +313,8 @@ Handler_commit 0 Handler_delete 0 Handler_discover 0 Handler_prepare 0 +Handler_pushed_index_cond_checks 0 +Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 2 Handler_read_next 2 diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result index 17c44df1d3c..175839b2098 100644 --- a/mysql-test/r/status_user.result +++ b/mysql-test/r/status_user.result @@ -101,6 +101,8 @@ Handler_commit 19 Handler_delete 1 Handler_discover 0 Handler_prepare 18 +Handler_pushed_index_cond_checks 0 +Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 3 Handler_read_next 0 diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test index 9d7b07f6b9e..6cb8f48bd70 100644 --- a/mysql-test/t/join_cache.test +++ b/mysql-test/t/join_cache.test @@ -1526,12 +1526,14 @@ insert into t2 values (3,1, 'qwerty'),(3,4, 'qwerty'); insert into t2 values (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'), (4,4, 'qwerty'); +flush status; set join_cache_level=5; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; +show status like "Handler_pushed%"; set join_cache_level=6; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1539,6 +1541,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; +show status like "Handler_pushed%"; set join_cache_level=7; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1546,6 +1549,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; +show status like "Handler_pushed%"; set join_cache_level=8; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1553,6 +1557,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; +show status like "Handler_pushed%"; drop table t1,t2; set join_cache_level=default; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 109d0220a4a..4e2fa473b8d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8291,6 +8291,8 @@ SHOW_VAR status_vars[]= { {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_multi_range_read_init_count), SHOW_LONG_STATUS}, #endif {"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS}, + {"Handler_pushed_index_cond_checks",(char*) offsetof(STATUS_VAR, ha_pushed_index_cond_checks), SHOW_LONG_STATUS}, + {"Handler_pushed_index_cond_filtered",(char*) offsetof(STATUS_VAR, ha_pushed_index_cond_filtered), SHOW_LONG_STATUS}, {"Handler_read_first", (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS}, {"Handler_read_key", (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS}, {"Handler_read_next", (char*) offsetof(STATUS_VAR, ha_read_next_count), SHOW_LONG_STATUS}, diff --git a/sql/sql_class.h b/sql/sql_class.h index 58af7888385..c04af55a127 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -588,6 +588,8 @@ typedef struct system_status_var ulong ha_tmp_update_count; ulong ha_tmp_write_count; ulong ha_prepare_count; + ulong ha_pushed_index_cond_checks; + ulong ha_pushed_index_cond_filtered; ulong ha_discover_count; ulong ha_savepoint_count; ulong ha_savepoint_rollback_count; diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 78f95a7ac7e..15b5efbfacb 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -2576,6 +2576,15 @@ void JOIN_CACHE::print_explain_comment(String *str) str->append(STRING_WITH_LEN(")")); } +/** + get thread handle. +*/ + +THD *JOIN_CACHE::thd() +{ + return join->thd; +} + static void add_mrr_explain_info(String *str, uint mrr_mode, handler *file) { @@ -4015,7 +4024,11 @@ bool bka_skip_index_tuple(range_seq_t rseq, range_id_t range_info) { DBUG_ENTER("bka_skip_index_tuple"); JOIN_CACHE_BKA *cache= (JOIN_CACHE_BKA *) rseq; - bool res= cache->skip_index_tuple(range_info); + THD *thd= cache->thd(); + bool res; + status_var_increment(thd->status_var.ha_pushed_index_cond_checks); + if ((res= cache->skip_index_tuple(range_info))) + status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); DBUG_RETURN(res); } @@ -4490,7 +4503,12 @@ bool bkah_skip_index_tuple(range_seq_t rseq, range_id_t range_info) { DBUG_ENTER("bka_unique_skip_index_tuple"); JOIN_CACHE_BKAH *cache= (JOIN_CACHE_BKAH *) rseq; - DBUG_RETURN(cache->skip_index_tuple(range_info)); + THD *thd= cache->thd(); + bool res; + status_var_increment(thd->status_var.ha_pushed_index_cond_checks); + if ((res= cache->skip_index_tuple(range_info))) + status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); + DBUG_RETURN(res); } diff --git a/sql/sql_join_cache.h b/sql/sql_join_cache.h index f5d64d5530a..ba8e4ba8e4a 100644 --- a/sql/sql_join_cache.h +++ b/sql/sql_join_cache.h @@ -643,6 +643,8 @@ public: /* Add a comment on the join algorithm employed by the join cache */ virtual void print_explain_comment(String *str); + THD *thd(); + virtual ~JOIN_CACHE() {} void reset_join(JOIN *j) { join= j; } void free() diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index 92b2a965706..bee7888eb5d 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -2248,12 +2248,18 @@ C_MODE_START ICP_RESULT index_cond_func_maria(void *arg) { ha_maria *h= (ha_maria*)arg; + THD *thd= ((TABLE*) h->file->external_ref)->in_use; + ICP_RESULT res; if (h->end_range) { if (h->compare_key2(h->end_range) > 0) return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */ } - return h->pushed_idx_cond->val_int() ? ICP_MATCH : ICP_NO_MATCH; + status_var_increment(thd->status_var.ha_pushed_index_cond_checks); + if ((res= h->pushed_idx_cond->val_int() ? ICP_MATCH : ICP_NO_MATCH) == + ICP_NO_MATCH) + status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); + return res; } C_MODE_END diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 5f1caa31b74..1f6e1fd6838 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1770,12 +1770,18 @@ C_MODE_START ICP_RESULT index_cond_func_myisam(void *arg) { ha_myisam *h= (ha_myisam*)arg; + THD *thd= ((TABLE*) h->file->external_ref)->in_use; + ICP_RESULT res; if (h->end_range) { if (h->compare_key2(h->end_range) > 0) return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */ } - return (ICP_RESULT) test(h->pushed_idx_cond->val_int()); + status_var_increment(thd->status_var.ha_pushed_index_cond_checks); + if ((res= (ICP_RESULT) test(h->pushed_idx_cond->val_int())) == + ICP_NO_MATCH) + status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); + return res; } C_MODE_END diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 972a4407eea..9db7e9a715b 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -12583,6 +12583,8 @@ innobase_index_cond( void* file) /*!< in/out: pointer to ha_innobase */ { ha_innobase *h= (ha_innobase*) file; + THD *thd= h->thd(); + enum icp_result res; if (h->is_thd_killed()) return ICP_ABORTED_BY_USER; @@ -12592,7 +12594,11 @@ innobase_index_cond( if (h->compare_key2(h->end_range) > 0) return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */ } - return h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH; + status_var_increment(thd->status_var.ha_pushed_index_cond_checks); + if ((res= h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH) == + ICP_NO_MATCH) + status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); + return res; } /** Attempt to push down an index condition. diff --git a/storage/xtradb/handler/ha_innodb.h b/storage/xtradb/handler/ha_innodb.h index 749438e0c89..6ec036eb8cc 100644 --- a/storage/xtradb/handler/ha_innodb.h +++ b/storage/xtradb/handler/ha_innodb.h @@ -223,6 +223,8 @@ class ha_innobase: public handler bool check_if_incompatible_data(HA_CREATE_INFO *info, uint table_changes); bool check_if_supported_virtual_columns(void) { return TRUE; } + + THD *thd() { return user_thd; } private: /** Builds a 'template' to the prebuilt struct. From e98e05da7a0f817849529dfaf89e9b8010b16f4e Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Thu, 16 Feb 2012 18:56:10 +0400 Subject: [PATCH 10/45] Added comments --- sql/sql_list.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/sql_list.h b/sql/sql_list.h index 873a8656ebe..adedd9a3a4d 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -257,7 +257,12 @@ public: last= &first; return tmp->info; } - inline void disjoin(base_list *list) + /* + Remove from this list elements that are contained in the passed list. + We assume that the passed list is a tail of this list (that is, the whole + list_node* elements are shared). + */ + inline void disjoin(const base_list *list) { list_node **prev= &first; list_node *node= first; From 541334c5ac11efae4918116b152d9085bd82caee Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Thu, 16 Feb 2012 20:15:57 +0400 Subject: [PATCH 11/45] Backport of: timestamp: Thu 2011-12-01 15:12:10 +0100 Fix for Bug#13430436 PERFORMANCE DEGRADATION IN SYSBENCH ON INNODB DUE TO ICP When running sysbench on InnoDB there is a performance degradation due to index condition pushdown (ICP). Several of the queries in sysbench have a WHERE condition that the optimizer uses for executing these queries as range scans. The upper and lower limit of the range scan will ensure that the WHERE condition is fulfilled. Still, the WHERE condition is part of the queries' condition and if ICP is enabled the condition will be pushed down to InnoDB as an index condition. Due to the range scan's upper and lower limits ensure that the WHERE condition is fulfilled, the pushed index condition will not filter out any records. As a result the use of ICP for these queries results in a performance overhead for sysbench. This overhead comes from using resources for determining the part of the condition that can be pushed down to InnoDB and overhead in InnoDB for executing the pushed index condition. With the default configuration for sysbench the range scans will use the primary key. This is a clustered index in InnoDB. Using ICP on a clustered index provides the lowest performance benefit since the entire record is part of the clustered index and in InnoDB it has the highest relative overhead for executing the pushed index condition. The fix for removing the overhead ICP introduces when running sysbench is to disable use of ICP when the index used by the query is a clustered index. When WL#6061 is implemented this change should be re-evaluated. --- mysql-test/r/index_merge_innodb.result | 2 +- mysql-test/r/innodb.result | 2 +- mysql-test/r/innodb_icp.result | 14 +++++----- mysql-test/r/innodb_mrr_cpk.result | 6 ++-- .../r/range_vs_index_merge_innodb.result | 28 +++++++++---------- mysql-test/suite/innodb/r/innodb.result | 2 +- .../r/innodb_lock_wait_timeout_1.result | 4 +-- mysql-test/suite/innodb/r/innodb_mysql.result | 2 +- .../suite/vcol/r/vcol_select_innodb.result | 6 ++-- sql/opt_index_cond_pushdown.cc | 14 ++++++++-- 10 files changed, 45 insertions(+), 35 deletions(-) diff --git a/mysql-test/r/index_merge_innodb.result b/mysql-test/r/index_merge_innodb.result index 0f9da2ea3b6..50b0147b6ad 100644 --- a/mysql-test/r/index_merge_innodb.result +++ b/mysql-test/r/index_merge_innodb.result @@ -549,7 +549,7 @@ primary key (pk1, pk2) ); explain select * from t1 where pk1 = 1 and pk2 < 80 and key1=0; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY,key1 PRIMARY 8 NULL 9 Using index condition; Using where +1 SIMPLE t1 range PRIMARY,key1 PRIMARY 8 NULL 9 Using where select * from t1 where pk1 = 1 and pk2 < 80 and key1=0; pk1 pk2 key1 key2 pktail1ok pktail2ok pktail3bad pktail4bad pktail5bad pk2copy badkey filler1 filler2 1 10 0 0 0 0 0 0 0 10 0 filler-data-10 filler2 diff --git a/mysql-test/r/innodb.result b/mysql-test/r/innodb.result index 3b69791d373..9ab7ed4eec7 100644 --- a/mysql-test/r/innodb.result +++ b/mysql-test/r/innodb.result @@ -783,7 +783,7 @@ create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); explain select * from t1 where a > 0 and a < 50; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using index condition +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where drop table t1; create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb; insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL'); diff --git a/mysql-test/r/innodb_icp.result b/mysql-test/r/innodb_icp.result index ccbae98d137..d8e41113f63 100644 --- a/mysql-test/r/innodb_icp.result +++ b/mysql-test/r/innodb_icp.result @@ -167,7 +167,7 @@ WHERE ts BETWEEN '0000-00-00' AND '2010-00-01 00:00:00' ORDER BY ts DESC LIMIT 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using index condition +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where DROP TABLE t1; # @@ -431,7 +431,7 @@ SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where -2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using index condition +2 DEPENDENT SUBQUERY it eq_ref PRIMARY PRIMARY 4 func 1 Using where 2 DEPENDENT SUBQUERY t2 index NULL PRIMARY 4 NULL 3 Using where; Using index; Using join buffer (flat, BNL join) SELECT * FROM t1 WHERE pk IN (SELECT it.pk FROM t2 JOIN t2 AS it ON it.i=it.i WHERE it.pk-t1.i<10); @@ -452,7 +452,7 @@ PRIMARY KEY (pk) INSERT INTO t1 VALUES (1,9),(2,7),(3,6),(4,3),(5,1); EXPLAIN SELECT pk, c1 FROM t1 WHERE pk <> 3; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using index condition +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where SET SESSION optimizer_switch='index_condition_pushdown=off'; SELECT pk, c1 FROM t1 WHERE pk <> 3; pk c1 @@ -507,8 +507,8 @@ SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Using where -1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Using join buffer (flat, BNL join) +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 1 Using where +1 SIMPLE t2 range PRIMARY PRIMARY 4 NULL 2 Using where; Using join buffer (flat, BNL join) SELECT c2 FROM t1 JOIN t2 ON t1.c1 = t2.c1 WHERE (t2.pk <= 4 AND t1.pk IN (2,1)) OR (t1.pk > 1 AND t2.pk BETWEEN 6 AND 6); @@ -680,7 +680,7 @@ EXPLAIN SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0 HAVING t1.c != 5 ORDER BY t1.c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using where; Using filesort +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 2 Using where; Using filesort 1 SIMPLE t2 ref a a 515 test.t1.a 1 Using where SELECT t1.b, t1.c FROM t1, t2 WHERE t1.a = t2.a AND t1.b != 0 HAVING t1.c != 5 ORDER BY t1.c; @@ -793,7 +793,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 PRIMARY t ALL PRIMARY,c NULL NULL NULL 64 Using where 1 PRIMARY t2 ref g g 5 test.t.c 9 Using where 2 DEPENDENT SUBQUERY t1 index PRIMARY d 3 NULL 64 Using where; Using index -2 DEPENDENT SUBQUERY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index condition; Using where +2 DEPENDENT SUBQUERY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where SELECT COUNT(*) FROM t1 AS t, t2 WHERE c = g AND (EXISTS (SELECT * FROM t1, t2 WHERE a = f AND h <= t.e AND a > t.b) diff --git a/mysql-test/r/innodb_mrr_cpk.result b/mysql-test/r/innodb_mrr_cpk.result index 81536f2a43b..90f59b96e61 100644 --- a/mysql-test/r/innodb_mrr_cpk.result +++ b/mysql-test/r/innodb_mrr_cpk.result @@ -82,7 +82,7 @@ insert into t2 values ('a-1010=A', 1010), ('a-1030=A', 1030), ('a-1020=A', 1020) explain select * from t1, t2 where t1.a=t2.a and t1.b=t2.b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where -1 SIMPLE t1 eq_ref PRIMARY PRIMARY 30 test.t2.a,test.t2.b 1 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered scan +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 30 test.t2.a,test.t2.b 1 Using where; Using join buffer (flat, BKA join); Key-ordered scan select * from t1, t2 where t1.a=t2.a and t1.b=t2.b; a b filler a b a-1010=A 1010 filler a-1010=A 1010 @@ -91,7 +91,7 @@ a-1030=A 1030 filler a-1030=A 1030 explain select * from t1, t2 where t1.a=t2.a; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where -1 SIMPLE t1 ref PRIMARY PRIMARY 26 test.t2.a 1 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered scan +1 SIMPLE t1 ref PRIMARY PRIMARY 26 test.t2.a 1 Using where; Using join buffer (flat, BKA join); Key-ordered scan select * from t1, t2 where t1.a=t2.a; a b filler a b a-1010=A 1010 filler a-1010=A 1010 @@ -133,7 +133,7 @@ set join_cache_level=6; explain select * from t1, t2 where t1.a=t2.a and t2.b + t1.b > 100; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ALL NULL NULL NULL NULL 3 Using where -1 SIMPLE t1 ref PRIMARY PRIMARY 4 test.t2.a 1 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered scan +1 SIMPLE t1 ref PRIMARY PRIMARY 4 test.t2.a 1 Using where; Using join buffer (flat, BKA join); Key-ordered scan select * from t1, t2 where t1.a=t2.a and t2.b + t1.b > 100; a b c filler a b set optimizer_switch='index_condition_pushdown=off'; diff --git a/mysql-test/r/range_vs_index_merge_innodb.result b/mysql-test/r/range_vs_index_merge_innodb.result index 57862ded4f2..c42f80f0e85 100644 --- a/mysql-test/r/range_vs_index_merge_innodb.result +++ b/mysql-test/r/range_vs_index_merge_innodb.result @@ -328,15 +328,15 @@ ID Name Country Population EXPLAIN SELECT * FROM City WHERE (ID < 10) OR (ID BETWEEN 100 AND 110); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 20 Using index condition; Using where +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 20 Using where EXPLAIN SELECT * FROM City WHERE (ID < 200) OR (ID BETWEEN 100 AND 200); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 200 Using index condition; Using where +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 200 Using where EXPLAIN SELECT * FROM City WHERE (ID < 600) OR (ID BETWEEN 900 AND 1500); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 1198 Using index condition; Using where +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 1198 Using where EXPLAIN SELECT * FROM City WHERE Country > 'A' AND Country < 'ARG'; id select_type table type possible_keys key key_len ref rows Extra @@ -355,7 +355,7 @@ WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG'))) OR ((ID BETWEEN 100 AND 110) AND (Name LIKE 'P%' OR (Population > 103000 AND Population < 104000))); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 20 Using index condition; Using where +1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 20 Using where EXPLAIN SELECT * FROM City WHERE ((ID < 800) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) @@ -369,7 +369,7 @@ WHERE ((ID < 200) AND (Name LIKE 'Ha%' OR (Country > 'A' AND Country < 'ARG'))) OR ((ID BETWEEN 100 AND 200) AND (Name LIKE 'Pa%' OR (Population > 103000 AND Population < 104000))); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 200 Using index condition; Using where +1 SIMPLE City range PRIMARY,Population,Country,Name PRIMARY 4 NULL 200 Using where SELECT * FROM City USE INDEX () WHERE ((ID < 10) AND (Name LIKE 'H%' OR (Country > 'A' AND Country < 'ARG'))) OR ((ID BETWEEN 100 AND 110) AND @@ -601,11 +601,11 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3400 AND 3800; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 400 Using index condition +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 400 Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3790 AND 3800; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using index condition +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using where EXPLAIN SELECT * FROM City WHERE Name LIKE 'P%'; id select_type table type possible_keys key key_len ref rows Extra @@ -765,27 +765,27 @@ id select_type table type possible_keys key key_len ref rows Extra EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3790 AND 3800; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using index condition +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 4025 AND 4035; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using index condition +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 4028 AND 4032; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 5 Using index condition +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 5 Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 3500 AND 3800; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 300 Using index condition +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 300 Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 4000 AND 4300; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 80 Using index condition +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 80 Using where EXPLAIN SELECT * FROM City WHERE ID BETWEEN 250 and 260 ; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using index condition +1 SIMPLE City range PRIMARY PRIMARY 4 NULL 11 Using where EXPLAIN SELECT * FROM City WHERE (Population > 101000 AND Population < 102000); id select_type table type possible_keys key key_len ref rows Extra @@ -1422,7 +1422,7 @@ SELECT * FROM t1 WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND (t1.c=0 OR t1.a=500); id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY,idx PRIMARY 4 NULL 1 Using index condition; Using where +1 SIMPLE t1 range PRIMARY,idx PRIMARY 4 NULL 1 Using where SELECT * FROM t1 WHERE t1.a>300 AND t1.c!=0 AND t1.b>=350 AND t1.b<=400 AND (t1.c=0 OR t1.a=500); diff --git a/mysql-test/suite/innodb/r/innodb.result b/mysql-test/suite/innodb/r/innodb.result index e98d3931020..80ff21230fb 100644 --- a/mysql-test/suite/innodb/r/innodb.result +++ b/mysql-test/suite/innodb/r/innodb.result @@ -778,7 +778,7 @@ create table t1 (a int primary key,b int, c int, d int, e int, f int, g int, h insert into t1 values (1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1); explain select * from t1 where a > 0 and a < 50; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using index condition +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL # Using where drop table t1; create table t1 (id int NOT NULL,id2 int NOT NULL,id3 int NOT NULL,dummy1 char(30),primary key (id,id2),index index_id3 (id3)) engine=innodb; insert into t1 values (0,0,0,'ABCDEFGHIJ'),(2,2,2,'BCDEFGHIJK'),(1,1,1,'CDEFGHIJKL'); diff --git a/mysql-test/suite/innodb/r/innodb_lock_wait_timeout_1.result b/mysql-test/suite/innodb/r/innodb_lock_wait_timeout_1.result index 30e58aacff5..2cb761c6ea1 100644 --- a/mysql-test/suite/innodb/r/innodb_lock_wait_timeout_1.result +++ b/mysql-test/suite/innodb/r/innodb_lock_wait_timeout_1.result @@ -121,7 +121,7 @@ key PRIMARY key_len 4 ref t2.a rows 1 -Extra Using index condition; Using where +Extra Using where id 2 select_type DERIVED table NULL @@ -328,7 +328,7 @@ key PRIMARY key_len 4 ref t2.a rows 1 -Extra Using index condition; Using where +Extra Using where id 2 select_type DERIVED table NULL diff --git a/mysql-test/suite/innodb/r/innodb_mysql.result b/mysql-test/suite/innodb/r/innodb_mysql.result index 4dcce4d0373..62dbc849241 100644 --- a/mysql-test/suite/innodb/r/innodb_mysql.result +++ b/mysql-test/suite/innodb/r/innodb_mysql.result @@ -2839,7 +2839,7 @@ SELECT t1.a FROM t1 LEFT JOIN t2 ON t1.pk = t2.a WHERE t1.pk >= 6 HAVING t1.a<> 0 AND t1.a <> 11 ORDER BY t1.a; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using index condition; Using filesort +1 SIMPLE t1 range PRIMARY PRIMARY 4 NULL 4 Using where; Using filesort 1 SIMPLE t2 ref a a 5 test.t1.pk 1 Using index SELECT t1.a FROM t1 LEFT JOIN t2 ON t1.pk = t2.a WHERE t1.pk >= 6 HAVING t1.a<> 0 AND t1.a <> 11 diff --git a/mysql-test/suite/vcol/r/vcol_select_innodb.result b/mysql-test/suite/vcol/r/vcol_select_innodb.result index be84fa74c2e..14cf325feb1 100644 --- a/mysql-test/suite/vcol/r/vcol_select_innodb.result +++ b/mysql-test/suite/vcol/r/vcol_select_innodb.result @@ -152,7 +152,7 @@ a b c 2 -2 -2 explain select * from t3 where a between 1 and 2; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using index condition +1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where # SELECT * FROM tbl_name WHERE select * from t3 where b between -2 and -1; a b c @@ -176,7 +176,7 @@ a b c 1 -1 -1 explain select * from t3 where a between 1 and 2 order by b; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using filesort +1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where; Using filesort # SELECT * FROM tbl_name WHERE ORDER BY select * from t3 where a between 1 and 2 order by c; a b c @@ -184,7 +184,7 @@ a b c 1 -1 -1 explain select * from t3 where a between 1 and 2 order by c; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using index condition; Using filesort +1 SIMPLE t3 range PRIMARY PRIMARY 4 NULL 2 Using where; Using filesort # SELECT * FROM tbl_name WHERE ORDER BY select * from t3 where b between -2 and -1 order by a; a b c diff --git a/sql/opt_index_cond_pushdown.cc b/sql/opt_index_cond_pushdown.cc index 5240267b4ac..c2b49d863a1 100644 --- a/sql/opt_index_cond_pushdown.cc +++ b/sql/opt_index_cond_pushdown.cc @@ -329,13 +329,23 @@ void push_index_cond(JOIN_TAB *tab, uint keyno) { DBUG_ENTER("push_index_cond"); Item *idx_cond; - + + /* + Backported the following from MySQL 5.6: + 6. The index is not a clustered index. The performance improvement + of pushing an index condition on a clustered key is much lower + than on a non-clustered key. This restriction should be + re-evaluated when WL#6061 is implemented. + */ if ((tab->table->file->index_flags(keyno, 0, 1) & HA_DO_INDEX_COND_PUSHDOWN) && optimizer_flag(tab->join->thd, OPTIMIZER_SWITCH_INDEX_COND_PUSHDOWN) && tab->join->thd->lex->sql_command != SQLCOM_UPDATE_MULTI && tab->join->thd->lex->sql_command != SQLCOM_DELETE_MULTI && - tab->type != JT_CONST && tab->type != JT_SYSTEM) + tab->type != JT_CONST && tab->type != JT_SYSTEM && + !(keyno == tab->table->s->primary_key && // (6) + tab->table->file->primary_key_is_clustered())) // (6) + { DBUG_EXECUTE("where", print_where(tab->select_cond, "full cond", QT_ORDINARY);); From c563ea0717f3de43b7331dd4368e9f9cf4559be0 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 16 Feb 2012 16:06:49 -0800 Subject: [PATCH 12/45] Fixed LP bug #933117. The bug was fixed with the code back-ported from the patch for LP bug 800184 pushed into mariadb-5.3. --- mysql-test/r/range.result | 15 +++++++++++++++ mysql-test/t/range.test | 14 ++++++++++++++ sql/opt_range.cc | 9 +++++++-- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/range.result b/mysql-test/r/range.result index ae63edf87b9..13ae77c13e3 100644 --- a/mysql-test/r/range.result +++ b/mysql-test/r/range.result @@ -1768,3 +1768,18 @@ SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk; pk i4 pk i4 DROP TABLE t1; End of 5.1 tests +# +# LP Bug #533117: Wrong use_count in SEL_ARG trees +# (Bug #58731) +# +create table t1 (a int, b int, c int, key idx (a,b,c)); +insert into t1 values (0,0,0), (2,2,0), (1,1,1), (2,2,1); +explain +select * from t1 force index (idx) where a >=1 and c <= 1 and a=b and b > 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range idx idx 5 NULL 3 Using where; Using index +select * from t1 force index (idx) where a >=1 and c <= 1 and a=b and b > 1; +a b c +2 2 0 +2 2 1 +drop table t1; diff --git a/mysql-test/t/range.test b/mysql-test/t/range.test index 6c9320b708a..a5ab6905b74 100644 --- a/mysql-test/t/range.test +++ b/mysql-test/t/range.test @@ -1393,3 +1393,17 @@ SELECT * FROM t1, t1 as t2 WHERE t1.i4 BETWEEN t2.pk AND t2.pk; DROP TABLE t1; --echo End of 5.1 tests + +--echo # +--echo # LP Bug #533117: Wrong use_count in SEL_ARG trees +--echo # (Bug #58731) +--echo # + +create table t1 (a int, b int, c int, key idx (a,b,c)); +insert into t1 values (0,0,0), (2,2,0), (1,1,1), (2,2,1); + +explain +select * from t1 force index (idx) where a >=1 and c <= 1 and a=b and b > 1; +select * from t1 force index (idx) where a >=1 and c <= 1 and a=b and b > 1; + +drop table t1; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index bc434e2edc1..185f3eecd3c 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -498,6 +498,11 @@ public: pos->increment_use_count(count); } } + void incr_refs() + { + increment_use_count(1); + use_count++; + } void free_tree() { for (SEL_ARG *pos=first(); pos ; pos=pos->next) @@ -6475,8 +6480,8 @@ key_and(RANGE_OPT_PARAM *param, SEL_ARG *key1, SEL_ARG *key2, uint clone_flag) continue; SEL_ARG *next=key_and(param, e1->next_key_part, e2->next_key_part, clone_flag); - e1->increment_use_count(1); - e2->increment_use_count(1); + e1->incr_refs(); + e2->incr_refs(); if (!next || next->type != SEL_ARG::IMPOSSIBLE) { SEL_ARG *new_arg= e1->clone_and(e2); From 2d19b077d5816dcd3a8c84bb682cf2d83fa055f5 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 16 Feb 2012 20:13:28 -0800 Subject: [PATCH 13/45] Fixed LP bug #928352. This bug led to wrong values of the use_count fields in some SEL_ARG trees that triggered complains on the server side when executing the test case for LP bug 800184 if a debug build of the server was used. This was the result of the incomplete fix for bug 800184. To complete it the following corrections had to be made: - the copy constructor for SEL_TREE must call the new function incr_refs_all() instead of the function incr_refs(), because references to next key parts from any SEL_ARG tree belonging to the list of the first key part has to be adjusted. - the method and_sel_tree of the class SEL_IMERGE must use the copy constructor of the SEL_TREE class to make a copy of its second argument before it ANDs it with any SEL_TREE tree from the processed SEL_IMERGE object. --- sql/opt_range.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 8d4b2e971ad..e0841d3a696 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -552,6 +552,14 @@ public: increment_use_count(1); use_count++; } + void incr_refs_all() + { + for (SEL_ARG *pos=first(); pos ; pos=pos->next) + { + pos->increment_use_count(1); + } + use_count++; + } void free_tree() { for (SEL_ARG *pos=first(); pos ; pos=pos->next) @@ -1090,9 +1098,11 @@ int SEL_IMERGE::and_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree, for (SEL_TREE** or_tree= trees; or_tree != trees_next; or_tree++) { SEL_TREE *res_or_tree= 0; - if (!(res_or_tree= new SEL_TREE())) + SEL_TREE *and_tree= 0; + if (!(res_or_tree= new SEL_TREE()) || + !(and_tree= new SEL_TREE(tree, TRUE, param))) return (-1); - if (!and_range_trees(param, *or_tree, tree, res_or_tree)) + if (!and_range_trees(param, *or_tree, and_tree, res_or_tree)) { if (new_imerge->or_sel_tree(param, res_or_tree)) return (-1); @@ -1305,7 +1315,7 @@ SEL_TREE::SEL_TREE(SEL_TREE *arg, bool without_merges, for (uint idx= 0; idx < param->keys; idx++) { if ((keys[idx]= arg->keys[idx])) - keys[idx]->incr_refs(); + keys[idx]->incr_refs_all(); } if (without_merges) From 5bf311e1e853457c31dbadd3d130b2569a867d80 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 17 Feb 2012 12:19:38 +0100 Subject: [PATCH 14/45] fix the include guards and add missing gplv2 headers --- include/wqueue.h | 20 ++++++++++++++++++-- mysys/my_init.c | 1 + mysys/wqueue.c | 16 ++++++++++++++++ plugin/auth_pam/auth_pam.c | 16 ++++++++++++++++ plugin/auth_pam/testing/pam_mariadb_mtr.c | 2 ++ sql/multi_range_read.h | 16 ++++++++++++++++ sql/opt_index_cond_pushdown.cc | 16 ++++++++++++++++ sql/opt_range_mrr.cc | 15 +++++++++++++++ sql/opt_subselect.cc | 16 ++++++++++++++++ sql/opt_subselect.h | 16 ++++++++++++++++ sql/opt_table_elimination.cc | 16 ++++++++++++++++ sql/sql_expression_cache.h | 16 ++++++++++++++++ sql/sql_join_cache.h | 16 ++++++++++++++++ sql/sql_lifo_buffer.h | 16 ++++++++++++++++ sql/winservice.c | 16 ++++++++++++++++ sql/winservice.h | 16 ++++++++++++++++ storage/maria/ma_servicethread.c | 16 ++++++++++++++++ storage/maria/ma_servicethread.h | 16 ++++++++++++++++ 18 files changed, 260 insertions(+), 2 deletions(-) diff --git a/include/wqueue.h b/include/wqueue.h index b3fe3dc8602..e568ab8e91e 100644 --- a/include/wqueue.h +++ b/include/wqueue.h @@ -1,6 +1,22 @@ +/* + Copyright (c) 2007, 2008, Sun Microsystems, Inc, + Copyright (c) 2011, 2012, Monty Program Ab -#ifndef _wqueue_h -#define _wqueue_h + 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; version 2 of the License. + + 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 */ + +#ifndef WQUEUE_INCLUDED +#define WQUEUE_INCLUDED #include #include diff --git a/mysys/my_init.c b/mysys/my_init.c index abb0c0d7824..bb72d0e0426 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -1,5 +1,6 @@ /* Copyright (c) 2000, 2011, Oracle and/or its affiliates + Copyright (c) 2009, 2011, Monty Program 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 diff --git a/mysys/wqueue.c b/mysys/wqueue.c index b6f52ba5c31..2fcced14f77 100644 --- a/mysys/wqueue.c +++ b/mysys/wqueue.c @@ -1,3 +1,19 @@ +/* + Copyright (c) 2007, 2008, Sun Microsystems, Inc, + Copyright (c) 2011, 2012, Monty Program 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; version 2 of the License. + + 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 diff --git a/plugin/auth_pam/auth_pam.c b/plugin/auth_pam/auth_pam.c index ee13b37f793..fbe2edff449 100644 --- a/plugin/auth_pam/auth_pam.c +++ b/plugin/auth_pam/auth_pam.c @@ -1,3 +1,19 @@ +/* + Copyright (c) 2011, 2012, Monty Program 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; version 2 of the License. + + 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 #include #include diff --git a/plugin/auth_pam/testing/pam_mariadb_mtr.c b/plugin/auth_pam/testing/pam_mariadb_mtr.c index 73defe30112..8ad1e18e696 100644 --- a/plugin/auth_pam/testing/pam_mariadb_mtr.c +++ b/plugin/auth_pam/testing/pam_mariadb_mtr.c @@ -1,4 +1,6 @@ /* + This code is in the public domain and has no copyright. + Pam module to test pam authentication plugin. Used in pam.test. Linux only. diff --git a/sql/multi_range_read.h b/sql/multi_range_read.h index 1b72e71944d..dcba92aab16 100644 --- a/sql/multi_range_read.h +++ b/sql/multi_range_read.h @@ -1,3 +1,19 @@ +/* + Copyright (c) 2009, 2011, Monty Program 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; version 2 of the License. + + 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 */ + /** @defgroup DS-MRR declarations @{ diff --git a/sql/opt_index_cond_pushdown.cc b/sql/opt_index_cond_pushdown.cc index bec3bf6dab6..ba6aece7377 100644 --- a/sql/opt_index_cond_pushdown.cc +++ b/sql/opt_index_cond_pushdown.cc @@ -1,3 +1,19 @@ +/* + Copyright (c) 2009, 2012, Monty Program 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; version 2 of the License. + + 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 "sql_select.h" #include "sql_test.h" diff --git a/sql/opt_range_mrr.cc b/sql/opt_range_mrr.cc index 160b783715c..a4345059f85 100644 --- a/sql/opt_range_mrr.cc +++ b/sql/opt_range_mrr.cc @@ -1,3 +1,18 @@ +/* + Copyright (c) 2009, 2011, Monty Program 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; version 2 of the License. + + 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 */ /**************************************************************************** MRR Range Sequence Interface implementation that walks a SEL_ARG* tree. diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc index 6376b1ac33f..72c2f0442cf 100644 --- a/sql/opt_subselect.cc +++ b/sql/opt_subselect.cc @@ -1,3 +1,19 @@ +/* + Copyright (c) 2010, 2012, Monty Program 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; version 2 of the License. + + 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 */ + /** @file diff --git a/sql/opt_subselect.h b/sql/opt_subselect.h index 7db346f68c1..a12e0c11620 100644 --- a/sql/opt_subselect.h +++ b/sql/opt_subselect.h @@ -1,3 +1,19 @@ +/* + Copyright (c) 2010, 2012, Monty Program 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; version 2 of the License. + + 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 */ + /* Semi-join subquery optimization code definitions */ diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc index 3de73c3d4cc..33164c1ed12 100644 --- a/sql/opt_table_elimination.cc +++ b/sql/opt_table_elimination.cc @@ -1,3 +1,19 @@ +/* + Copyright (c) 2009, 2011, Monty Program 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; version 2 of the License. + + 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 */ + /** @file diff --git a/sql/sql_expression_cache.h b/sql/sql_expression_cache.h index 32aecc61dc9..48a8e33a787 100644 --- a/sql/sql_expression_cache.h +++ b/sql/sql_expression_cache.h @@ -1,3 +1,19 @@ +/* + Copyright (c) 2010, 2011, Monty Program 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; version 2 of the License. + + 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 */ + #ifndef SQL_EXPRESSION_CACHE_INCLUDED #define SQL_EXPRESSION_CACHE_INCLUDED diff --git a/sql/sql_join_cache.h b/sql/sql_join_cache.h index 155dd64d7e0..84c9d52c558 100644 --- a/sql/sql_join_cache.h +++ b/sql/sql_join_cache.h @@ -1,3 +1,19 @@ +/* + Copyright (c) 2011, 2012, Monty Program 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; version 2 of the License. + + 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 */ + /* This file contains declarations for implementations of block based join algorithms diff --git a/sql/sql_lifo_buffer.h b/sql/sql_lifo_buffer.h index 34f9624436d..5b7ddf35474 100644 --- a/sql/sql_lifo_buffer.h +++ b/sql/sql_lifo_buffer.h @@ -1,3 +1,19 @@ +/* + Copyright (c) 2010, 2011, Monty Program 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; version 2 of the License. + + 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 */ + /** @defgroup Bi-directional LIFO buffers used by DS-MRR implementation @{ diff --git a/sql/winservice.c b/sql/winservice.c index e4e0a3bd596..1f41cf61ea4 100644 --- a/sql/winservice.c +++ b/sql/winservice.c @@ -1,3 +1,19 @@ +/* + Copyright (c) 2011, 2012, Monty Program 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; version 2 of the License. + + 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 */ + /* Get Properties of an existing mysqld Windows service */ diff --git a/sql/winservice.h b/sql/winservice.h index 8957413783f..fca7b129de5 100644 --- a/sql/winservice.h +++ b/sql/winservice.h @@ -1,3 +1,19 @@ +/* + Copyright (c) 2011, 2012, Monty Program 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; version 2 of the License. + + 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 */ + /* Extract properties of a windows service binary path */ diff --git a/storage/maria/ma_servicethread.c b/storage/maria/ma_servicethread.c index 06abaa88ea1..e5c949a7571 100644 --- a/storage/maria/ma_servicethread.c +++ b/storage/maria/ma_servicethread.c @@ -1,3 +1,19 @@ +/* + Copyright (c) 2009, 2011, Monty Program 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; version 2 of the License. + + 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 "maria_def.h" #include "ma_servicethread.h" diff --git a/storage/maria/ma_servicethread.h b/storage/maria/ma_servicethread.h index 246e2302d0f..ed578d93c24 100644 --- a/storage/maria/ma_servicethread.h +++ b/storage/maria/ma_servicethread.h @@ -1,3 +1,19 @@ +/* + Copyright (c) 2009, 2011, Monty Program 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; version 2 of the License. + + 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 enum ma_service_thread_state {THREAD_RUNNING, THREAD_DYING, THREAD_DEAD}; From bbb3527635627a404ab4a16be7598339e8e41139 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Fri, 17 Feb 2012 13:27:41 +0100 Subject: [PATCH 15/45] Remove engine-specific (but identical) icp callbacks. create one reusable common icp callback in the handler.cc. It can also increment status counters, without making the engine dependent on the exact THD layout (that is different in embedded). --- sql/handler.cc | 21 +++++++++++++++++++ sql/handler.h | 4 ++++ storage/maria/ha_maria.cc | 27 +++---------------------- storage/myisam/ha_myisam.cc | 28 +++----------------------- storage/xtradb/handler/ha_innodb.cc | 28 -------------------------- storage/xtradb/handler/ha_innodb.h | 1 - storage/xtradb/include/ha_prototypes.h | 2 +- storage/xtradb/row/row0sel.c | 2 +- 8 files changed, 33 insertions(+), 80 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index e165a16b544..4a8cd77ebc3 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -4555,6 +4555,27 @@ int handler::compare_key2(key_range *range) } +/** + ICP callback - to be called by an engine to check the pushed condition +*/ +extern "C" enum icp_result handler_index_cond_check(void* h_arg) +{ + handler *h= (handler*)h_arg; + THD *thd= h->table->in_use; + enum icp_result res; + + if (thd_killed(thd)) + return ICP_ABORTED_BY_USER; + + if (h->end_range && h->compare_key2(h->end_range) > 0) + return ICP_OUT_OF_RANGE; + h->increment_statistics(&SSV::ha_pushed_index_cond_checks); + if ((res= h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH) == + ICP_NO_MATCH) + h->increment_statistics(&SSV::ha_pushed_index_cond_filtered); + return res; +} + int handler::index_read_idx_map(uchar * buf, uint index, const uchar * key, key_part_map keypart_map, enum ha_rkey_function find_flag) diff --git a/sql/handler.h b/sql/handler.h index 87ac1ab9ef3..28d8a96a895 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1553,6 +1553,8 @@ public: {} }; +extern "C" enum icp_result handler_index_cond_check(void* h_arg); + uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map); /* bitmap with first N+1 bits set @@ -2632,6 +2634,8 @@ public: { return ht; } inline int ha_write_tmp_row(uchar *buf); inline int ha_update_tmp_row(const uchar * old_data, uchar * new_data); + + friend enum icp_result handler_index_cond_check(void* h_arg); }; #include "multi_range_read.h" diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index bee7888eb5d..407350900bf 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -2243,27 +2243,6 @@ int ha_maria::delete_row(const uchar * buf) return maria_delete(file, buf); } -C_MODE_START - -ICP_RESULT index_cond_func_maria(void *arg) -{ - ha_maria *h= (ha_maria*)arg; - THD *thd= ((TABLE*) h->file->external_ref)->in_use; - ICP_RESULT res; - if (h->end_range) - { - if (h->compare_key2(h->end_range) > 0) - return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */ - } - status_var_increment(thd->status_var.ha_pushed_index_cond_checks); - if ((res= h->pushed_idx_cond->val_int() ? ICP_MATCH : ICP_NO_MATCH) == - ICP_NO_MATCH) - status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); - return res; -} - -C_MODE_END - int ha_maria::index_read_map(uchar * buf, const uchar * key, key_part_map keypart_map, enum ha_rkey_function find_flag) @@ -2283,7 +2262,7 @@ int ha_maria::index_read_idx_map(uchar * buf, uint index, const uchar * key, /* Use the pushed index condition if it matches the index we're scanning */ end_range= NULL; if (index == pushed_idx_cond_keyno) - ma_set_index_cond_func(file, index_cond_func_maria, this); + ma_set_index_cond_func(file, handler_index_cond_check, this); error= maria_rkey(file, buf, index, key, keypart_map, find_flag); @@ -2364,7 +2343,7 @@ int ha_maria::index_init(uint idx, bool sorted) { active_index=idx; if (pushed_idx_cond_keyno == idx) - ma_set_index_cond_func(file, index_cond_func_maria, this); + ma_set_index_cond_func(file, handler_index_cond_check, this); return 0; } @@ -3797,7 +3776,7 @@ Item *ha_maria::idx_cond_push(uint keyno_arg, Item* idx_cond_arg) pushed_idx_cond= idx_cond_arg; in_range_check_pushed_down= TRUE; if (active_index == pushed_idx_cond_keyno) - ma_set_index_cond_func(file, index_cond_func_maria, this); + ma_set_index_cond_func(file, handler_index_cond_check, this); return NULL; } diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 1f6e1fd6838..a6ece45734a 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1765,33 +1765,11 @@ int ha_myisam::delete_row(const uchar *buf) } -C_MODE_START - -ICP_RESULT index_cond_func_myisam(void *arg) -{ - ha_myisam *h= (ha_myisam*)arg; - THD *thd= ((TABLE*) h->file->external_ref)->in_use; - ICP_RESULT res; - if (h->end_range) - { - if (h->compare_key2(h->end_range) > 0) - return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */ - } - status_var_increment(thd->status_var.ha_pushed_index_cond_checks); - if ((res= (ICP_RESULT) test(h->pushed_idx_cond->val_int())) == - ICP_NO_MATCH) - status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); - return res; -} - -C_MODE_END - - int ha_myisam::index_init(uint idx, bool sorted) { active_index=idx; if (pushed_idx_cond_keyno == idx) - mi_set_index_cond_func(file, index_cond_func_myisam, this); + mi_set_index_cond_func(file, handler_index_cond_check, this); return 0; } @@ -1827,7 +1805,7 @@ int ha_myisam::index_read_idx_map(uchar *buf, uint index, const uchar *key, /* Use the pushed index condition if it matches the index we're scanning */ end_range= NULL; if (index == pushed_idx_cond_keyno) - mi_set_index_cond_func(file, index_cond_func_myisam, this); + mi_set_index_cond_func(file, handler_index_cond_check, this); res= mi_rkey(file, buf, index, key, keypart_map, find_flag); mi_set_index_cond_func(file, NULL, 0); return res; @@ -2346,7 +2324,7 @@ Item *ha_myisam::idx_cond_push(uint keyno_arg, Item* idx_cond_arg) pushed_idx_cond= idx_cond_arg; in_range_check_pushed_down= TRUE; if (active_index == pushed_idx_cond_keyno) - mi_set_index_cond_func(file, index_cond_func_myisam, this); + mi_set_index_cond_func(file, handler_index_cond_check, this); return NULL; } diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc index 9db7e9a715b..0d64a3f8b14 100644 --- a/storage/xtradb/handler/ha_innodb.cc +++ b/storage/xtradb/handler/ha_innodb.cc @@ -12573,34 +12573,6 @@ bool ha_innobase::is_thd_killed() * Index Condition Pushdown interface implementation */ -/*************************************************************//** -InnoDB index push-down condition check -@return ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */ -extern "C" UNIV_INTERN -enum icp_result -innobase_index_cond( -/*================*/ - void* file) /*!< in/out: pointer to ha_innobase */ -{ - ha_innobase *h= (ha_innobase*) file; - THD *thd= h->thd(); - enum icp_result res; - - if (h->is_thd_killed()) - return ICP_ABORTED_BY_USER; - - if (h->end_range) - { - if (h->compare_key2(h->end_range) > 0) - return ICP_OUT_OF_RANGE; /* caller should return HA_ERR_END_OF_FILE already */ - } - status_var_increment(thd->status_var.ha_pushed_index_cond_checks); - if ((res= h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH) == - ICP_NO_MATCH) - status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); - return res; -} - /** Attempt to push down an index condition. * @param[in] keyno MySQL key number * @param[in] idx_cond Index condition to be checked diff --git a/storage/xtradb/handler/ha_innodb.h b/storage/xtradb/handler/ha_innodb.h index 6ec036eb8cc..d234a7236e3 100644 --- a/storage/xtradb/handler/ha_innodb.h +++ b/storage/xtradb/handler/ha_innodb.h @@ -224,7 +224,6 @@ class ha_innobase: public handler uint table_changes); bool check_if_supported_virtual_columns(void) { return TRUE; } - THD *thd() { return user_thd; } private: /** Builds a 'template' to the prebuilt struct. diff --git a/storage/xtradb/include/ha_prototypes.h b/storage/xtradb/include/ha_prototypes.h index db71c37afc3..28c28838400 100644 --- a/storage/xtradb/include/ha_prototypes.h +++ b/storage/xtradb/include/ha_prototypes.h @@ -252,7 +252,7 @@ InnoDB index push-down condition check @return ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */ UNIV_INTERN enum icp_result -innobase_index_cond( +handler_index_cond_check( /*================*/ void* file) /*!< in/out: pointer to ha_innobase */ __attribute__((nonnull, warn_unused_result)); diff --git a/storage/xtradb/row/row0sel.c b/storage/xtradb/row/row0sel.c index fca3c90109f..52a6263efe5 100644 --- a/storage/xtradb/row/row0sel.c +++ b/storage/xtradb/row/row0sel.c @@ -3443,7 +3443,7 @@ row_search_idx_cond_check( index, if the case of the column has been updated in the past, or a record has been deleted and a record inserted in a different case. */ - result = innobase_index_cond(prebuilt->idx_cond); + result = handler_index_cond_check(prebuilt->idx_cond); switch (result) { case ICP_MATCH: /* Convert the remaining fields to MySQL format. From cd81f5783071d76d14a7aeb804e874345b1f3254 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 18 Feb 2012 16:06:38 -0800 Subject: [PATCH 16/45] Fixed LP bug #934342. An outer join query with a semi-join subquery could return a wrong result if the optimizer chose to materialize the subquery. It happened because when substituting for the best field into a ref item used to build access keys not all COND_EQUAL objects that could be employed at substitution were checked. Also refined some code in the function check_join_cache_usage to make it safer. --- mysql-test/r/subselect_sj_jcl6.result | 80 +++++++++++++++++++++++++++ mysql-test/t/subselect_sj_jcl6.test | 54 ++++++++++++++++++ sql/sql_select.cc | 21 +++++-- 3 files changed, 150 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result index dd358ced14a..4ac15ea654f 100644 --- a/mysql-test/r/subselect_sj_jcl6.result +++ b/mysql-test/r/subselect_sj_jcl6.result @@ -2753,6 +2753,86 @@ DROP table t1, t2; set @@optimizer_switch= @os_912513; set @@join_cache_level= @jcl_912513; # End +# +# BUG#934342: outer join + semijoin materialization +# + join_cache_level > 2 +# +CREATE TABLE t1 (a varchar(1), b varchar(1), INDEX idx_a(a) ); +INSERT INTO t1 VALUES ('v','v'), ('w','w'), ('t','t'); +CREATE TABLE t2 (c varchar(1), INDEX idx_c(c) ); +INSERT INTO t2 VALUES ('v'), ('v'), ('s'), ('j'); +CREATE TABLE t3 (c varchar(1), d varchar(1), INDEX idx_c(c) ); +INSERT INTO t3 VALUES ('v','v'), ('v','v'), ('s','s'), ('j','j'); +INSERT INTO t3 VALUES ('m','m'), ('d','d'), ('k','k'), ('m','m'); +set @tmp_otimizer_switch= @@optimizer_switch; +set @tmp_join_cache_level=@@join_cache_level; +set optimizer_switch = 'materialization=on,semijoin=on,join_cache_hashed=on'; +set join_cache_level=0; +EXPLAIN +SELECT * FROM t1 LEFT JOIN t2 ON (c = b) +WHERE (a, b) IN (SELECT a, b FROM t1 t); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL idx_a NULL NULL NULL 3 +1 PRIMARY eq_ref distinct_key distinct_key 10 func,func 1 +1 PRIMARY t2 ref idx_c idx_c 4 test.t1.b 2 Using where; Using index +2 MATERIALIZED t ALL idx_a NULL NULL NULL 3 +SELECT * FROM t1 LEFT JOIN t2 ON (c = b) +WHERE (a, b) IN (SELECT a, b FROM t1 t); +a b c +v v v +v v v +w w NULL +t t NULL +EXPLAIN +SELECT * FROM t1 LEFT JOIN t3 ON (c = b) +WHERE (a, b) IN (SELECT a, b FROM t1 t); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL idx_a NULL NULL NULL 3 +1 PRIMARY eq_ref distinct_key distinct_key 10 func,func 1 +1 PRIMARY t3 ref idx_c idx_c 4 test.t1.b 2 Using where +2 MATERIALIZED t ALL idx_a NULL NULL NULL 3 +SELECT * FROM t1 LEFT JOIN t3 ON (c = b) +WHERE (a, b) IN (SELECT a, b FROM t1 t); +a b c d +v v v v +v v v v +w w NULL NULL +t t NULL NULL +set join_cache_level=6; +EXPLAIN +SELECT * FROM t1 LEFT JOIN t2 ON (c = b) +WHERE (a, b) IN (SELECT a, b FROM t1 t); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL idx_a NULL NULL NULL 3 +1 PRIMARY eq_ref distinct_key distinct_key 10 func,func 1 +1 PRIMARY t2 ref idx_c idx_c 4 test.t1.b 2 Using where; Using index +2 MATERIALIZED t ALL idx_a NULL NULL NULL 3 +SELECT * FROM t1 LEFT JOIN t2 ON (c = b) +WHERE (a, b) IN (SELECT a, b FROM t1 t); +a b c +v v v +v v v +w w NULL +t t NULL +EXPLAIN +SELECT * FROM t1 LEFT JOIN t3 ON (c = b) +WHERE (a, b) IN (SELECT a, b FROM t1 t); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL idx_a NULL NULL NULL 3 +1 PRIMARY eq_ref distinct_key distinct_key 10 func,func 1 +1 PRIMARY t3 ref idx_c idx_c 4 test.t1.b 2 Using where; Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan +2 MATERIALIZED t ALL idx_a NULL NULL NULL 3 +SELECT * FROM t1 LEFT JOIN t3 ON (c = b) +WHERE (a, b) IN (SELECT a, b FROM t1 t); +a b c d +v v v v +v v v v +w w NULL NULL +t t NULL NULL +set optimizer_switch=@tmp_optimizer_switch; +set join_cache_level=@tmp_join_cache_level; +DROP TABLE t1,t2,t3; +# End set join_cache_level=default; show variables like 'join_cache_level'; Variable_name Value diff --git a/mysql-test/t/subselect_sj_jcl6.test b/mysql-test/t/subselect_sj_jcl6.test index 6d563cab3d3..9fe60cdd3d9 100644 --- a/mysql-test/t/subselect_sj_jcl6.test +++ b/mysql-test/t/subselect_sj_jcl6.test @@ -116,6 +116,60 @@ set @@join_cache_level= @jcl_912513; --echo # End +--echo # +--echo # BUG#934342: outer join + semijoin materialization +--echo # + join_cache_level > 2 +--echo # + +CREATE TABLE t1 (a varchar(1), b varchar(1), INDEX idx_a(a) ); +INSERT INTO t1 VALUES ('v','v'), ('w','w'), ('t','t'); + +CREATE TABLE t2 (c varchar(1), INDEX idx_c(c) ); +INSERT INTO t2 VALUES ('v'), ('v'), ('s'), ('j'); + +CREATE TABLE t3 (c varchar(1), d varchar(1), INDEX idx_c(c) ); +INSERT INTO t3 VALUES ('v','v'), ('v','v'), ('s','s'), ('j','j'); +INSERT INTO t3 VALUES ('m','m'), ('d','d'), ('k','k'), ('m','m'); + +set @tmp_otimizer_switch= @@optimizer_switch; +set @tmp_join_cache_level=@@join_cache_level; +set optimizer_switch = 'materialization=on,semijoin=on,join_cache_hashed=on'; + +set join_cache_level=0; + +EXPLAIN +SELECT * FROM t1 LEFT JOIN t2 ON (c = b) + WHERE (a, b) IN (SELECT a, b FROM t1 t); +SELECT * FROM t1 LEFT JOIN t2 ON (c = b) + WHERE (a, b) IN (SELECT a, b FROM t1 t); + +EXPLAIN +SELECT * FROM t1 LEFT JOIN t3 ON (c = b) + WHERE (a, b) IN (SELECT a, b FROM t1 t); +SELECT * FROM t1 LEFT JOIN t3 ON (c = b) + WHERE (a, b) IN (SELECT a, b FROM t1 t); + +set join_cache_level=6; + +EXPLAIN +SELECT * FROM t1 LEFT JOIN t2 ON (c = b) + WHERE (a, b) IN (SELECT a, b FROM t1 t); +SELECT * FROM t1 LEFT JOIN t2 ON (c = b) + WHERE (a, b) IN (SELECT a, b FROM t1 t); + +EXPLAIN +SELECT * FROM t1 LEFT JOIN t3 ON (c = b) + WHERE (a, b) IN (SELECT a, b FROM t1 t); +SELECT * FROM t1 LEFT JOIN t3 ON (c = b) + WHERE (a, b) IN (SELECT a, b FROM t1 t); + +set optimizer_switch=@tmp_optimizer_switch; +set join_cache_level=@tmp_join_cache_level; + +DROP TABLE t1,t2,t3; + +--echo # End + set join_cache_level=default; show variables like 'join_cache_level'; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 8eb29853e8d..d8c4ebddc29 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1266,9 +1266,20 @@ JOIN::optimize() Item *ref_item= *ref_item_ptr; if (!ref_item->used_tables() && !(select_options & SELECT_DESCRIBE)) continue; - COND_EQUAL *equals= tab->first_inner ? tab->first_inner->cond_equal : - cond_equal; - ref_item= substitute_for_best_equal_field(tab, ref_item, equals, map2table); + COND_EQUAL *equals= cond_equal; + JOIN_TAB *first_inner= tab->first_inner; + while (equals) + { + ref_item= substitute_for_best_equal_field(tab, ref_item, + equals, map2table); + if (first_inner) + { + equals= first_inner->cond_equal; + first_inner= first_inner->first_upper; + } + else + equals= 0; + } ref_item->update_used_tables(); if (*ref_item_ptr != ref_item) { @@ -9213,7 +9224,7 @@ uint check_join_cache_usage(JOIN_TAB *tab, Check whether table tab and the previous one belong to the same nest of inner tables and if so do not use join buffer when joining table tab. */ - if (tab->first_inner) + if (tab->first_inner && tab != tab->first_inner) { for (JOIN_TAB *first_inner= tab[-1].first_inner; first_inner; @@ -9223,7 +9234,7 @@ uint check_join_cache_usage(JOIN_TAB *tab, goto no_join_cache; } } - else if (tab->first_sj_inner_tab && + else if (tab->first_sj_inner_tab && tab != tab->first_sj_inner_tab && tab->first_sj_inner_tab == tab[-1].first_sj_inner_tab) goto no_join_cache; } From 3ef46370e9719f12e0f8542ab69063eca3922205 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Sat, 18 Feb 2012 19:11:57 -0800 Subject: [PATCH 17/45] Fixed bug #934348. This bug is the result of an incomplete/inconsistent change introduced into 5.3 code when the cond_equal parameter were added to the function optimize_cond. The change was made during a merge from 5.2 in October 2010. The bug could affect only queries with HAVING. --- mysql-test/r/subselect_sj_jcl6.result | 43 +++++++++++++++++++++++++++ mysql-test/t/subselect_sj_jcl6.test | 38 +++++++++++++++++++++++ sql/sql_select.cc | 5 ++-- 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/subselect_sj_jcl6.result b/mysql-test/r/subselect_sj_jcl6.result index 4ac15ea654f..769373429da 100644 --- a/mysql-test/r/subselect_sj_jcl6.result +++ b/mysql-test/r/subselect_sj_jcl6.result @@ -2833,6 +2833,49 @@ set optimizer_switch=@tmp_optimizer_switch; set join_cache_level=@tmp_join_cache_level; DROP TABLE t1,t2,t3; # End +# +# BUG#934348: GROUP BY with HAVING + semijoin materialization +# + join_cache_level > 2 +# +CREATE TABLE t1 (a varchar(1), INDEX idx_a(a)); +INSERT INTO t1 VALUES ('c'), ('v'), ('c'); +CREATE TABLE t2 (b varchar(1)); +INSERT INTO t2 VALUES ('v'), ('c'); +set @tmp_otimizer_switch= @@optimizer_switch; +set @tmp_join_cache_level=@@join_cache_level; +set optimizer_switch = 'materialization=on,semijoin=on,join_cache_hashed=on'; +set join_cache_level=0; +EXPLAIN +SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) +GROUP BY a HAVING a != 'z'; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL distinct_key NULL NULL NULL 2 Using temporary; Using filesort +1 PRIMARY t ref idx_a idx_a 4 test.t2.b 2 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t1 ref idx_a idx_a 4 test.t2.b 2 Using index +SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) +GROUP BY a HAVING a != 'z'; +a +c +v +set join_cache_level=6; +EXPLAIN +SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) +GROUP BY a HAVING a != 'z'; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY ALL distinct_key NULL NULL NULL 2 Using temporary; Using filesort +1 PRIMARY t ref idx_a idx_a 4 test.t2.b 2 Using index +2 MATERIALIZED t2 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t1 ref idx_a idx_a 4 test.t2.b 2 Using index +SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) +GROUP BY a HAVING a != 'z'; +a +c +v +set optimizer_switch=@tmp_optimizer_switch; +set join_cache_level=@tmp_join_cache_level; +DROP TABLE t1,t2; +# End set join_cache_level=default; show variables like 'join_cache_level'; Variable_name Value diff --git a/mysql-test/t/subselect_sj_jcl6.test b/mysql-test/t/subselect_sj_jcl6.test index 9fe60cdd3d9..e86ed017951 100644 --- a/mysql-test/t/subselect_sj_jcl6.test +++ b/mysql-test/t/subselect_sj_jcl6.test @@ -170,6 +170,44 @@ DROP TABLE t1,t2,t3; --echo # End +--echo # +--echo # BUG#934348: GROUP BY with HAVING + semijoin materialization +--echo # + join_cache_level > 2 +--echo # + +CREATE TABLE t1 (a varchar(1), INDEX idx_a(a)); +INSERT INTO t1 VALUES ('c'), ('v'), ('c'); + +CREATE TABLE t2 (b varchar(1)); +INSERT INTO t2 VALUES ('v'), ('c'); + +set @tmp_otimizer_switch= @@optimizer_switch; +set @tmp_join_cache_level=@@join_cache_level; +set optimizer_switch = 'materialization=on,semijoin=on,join_cache_hashed=on'; + +set join_cache_level=0; + +EXPLAIN +SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) + GROUP BY a HAVING a != 'z'; +SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) + GROUP BY a HAVING a != 'z'; + +set join_cache_level=6; + +EXPLAIN +SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) + GROUP BY a HAVING a != 'z'; +SELECT a FROM t1 t WHERE a IN (SELECT b FROM t1, t2 WHERE b = a) + GROUP BY a HAVING a != 'z'; + +set optimizer_switch=@tmp_optimizer_switch; +set join_cache_level=@tmp_join_cache_level; + +DROP TABLE t1,t2; + +--echo # End + set join_cache_level=default; show variables like 'join_cache_level'; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d8c4ebddc29..eb4c7f7faad 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12695,9 +12695,8 @@ optimize_cond(JOIN *join, COND *conds, List *join_list, multiple equality contains a constant. */ DBUG_EXECUTE("where", print_where(conds, "original", QT_ORDINARY);); - conds= build_equal_items(join->thd, conds, NULL, join_list, - &join->cond_equal); - DBUG_EXECUTE("where",print_where(conds,"after equal_items", QT_ORDINARY);); + conds= build_equal_items(join->thd, conds, NULL, join_list, cond_equal); + DBUG_EXECUTE("where",print_where(conds,"after equal_items", QT_ORDINARY);); /* change field = field to field = const for each found field = const */ propagate_cond_constants(thd, (I_List *) 0, conds, conds); From fecad7c945f26a3677b17ae6f831ee222d6fc98a Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Mon, 20 Feb 2012 15:30:54 +0400 Subject: [PATCH 18/45] BUG#933407: Valgrind warnings in mark_as_null_row with materialization+semijoin, STRAIGHT_JOIN, impossible WHERE - In return_zero_rows(), don't call mark_as_null_row() for semi-join materialized tables, because 1) they may have been already freed, and 2)there is no real need to call mark_as_null_row() for them. --- mysql-test/r/subselect_mat.result | 13 +++++++++++++ mysql-test/r/subselect_sj_mat.result | 13 +++++++++++++ mysql-test/t/subselect_sj_mat.test | 13 +++++++++++++ sql/sql_select.cc | 14 +++++++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/subselect_mat.result b/mysql-test/r/subselect_mat.result index 6f90cc868a6..4d02e5012e2 100644 --- a/mysql-test/r/subselect_mat.result +++ b/mysql-test/r/subselect_mat.result @@ -1848,6 +1848,19 @@ a b 7 5 3 3 drop table t1,t2; +# +# BUG#933407: Valgrind warnings in mark_as_null_row with materialization+semijoin, STRAIGHT_JOIN, impossible WHERE +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +SELECT STRAIGHT_JOIN MIN(a) FROM t1 +WHERE a IN ( +SELECT a FROM t1 +WHERE 'condition'='impossible' + ); +MIN(a) +NULL +DROP TABLE t1; # This must be at the end: set optimizer_switch=@subselect_sj_mat_tmp; set join_cache_level=@save_join_cache_level; diff --git a/mysql-test/r/subselect_sj_mat.result b/mysql-test/r/subselect_sj_mat.result index 964df6735f8..b21236de7b9 100644 --- a/mysql-test/r/subselect_sj_mat.result +++ b/mysql-test/r/subselect_sj_mat.result @@ -1885,6 +1885,19 @@ a b 7 5 3 3 drop table t1,t2; +# +# BUG#933407: Valgrind warnings in mark_as_null_row with materialization+semijoin, STRAIGHT_JOIN, impossible WHERE +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); +SELECT STRAIGHT_JOIN MIN(a) FROM t1 +WHERE a IN ( +SELECT a FROM t1 +WHERE 'condition'='impossible' + ); +MIN(a) +NULL +DROP TABLE t1; # This must be at the end: set optimizer_switch=@subselect_sj_mat_tmp; set join_cache_level=@save_join_cache_level; diff --git a/mysql-test/t/subselect_sj_mat.test b/mysql-test/t/subselect_sj_mat.test index 0840029c5e0..0d04b3f984a 100644 --- a/mysql-test/t/subselect_sj_mat.test +++ b/mysql-test/t/subselect_sj_mat.test @@ -1545,6 +1545,19 @@ select * from t1 where t1.a in (select a from t2 where t2.a=7 or t2.b<=1); drop table t1,t2; +--echo # +--echo # BUG#933407: Valgrind warnings in mark_as_null_row with materialization+semijoin, STRAIGHT_JOIN, impossible WHERE +--echo # +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (0),(8); + +SELECT STRAIGHT_JOIN MIN(a) FROM t1 +WHERE a IN ( + SELECT a FROM t1 + WHERE 'condition'='impossible' + ); + +DROP TABLE t1; --echo # This must be at the end: set optimizer_switch=@subselect_sj_mat_tmp; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 8eb29853e8d..547b0b256b3 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -10431,10 +10431,22 @@ return_zero_rows(JOIN *join, select_result *result, List &tables, if (send_row) { + /* + Set all tables to have NULL row. This is needed as we will be evaluating + HAVING condition. + */ List_iterator ti(tables); TABLE_LIST *table; while ((table= ti++)) - mark_as_null_row(table->table); // All fields are NULL + { + /* + Don't touch semi-join materialization tables, as the above join_free() + call has freed them (and HAVING clause can't have references to them + anyway). + */ + if (!table->is_jtbm()) + mark_as_null_row(table->table); // All fields are NULL + } if (having && !having->walk(&Item::clear_sum_processor, FALSE, NULL) && having->val_int() == 0) From 3c07d04580fe5f28ff8bdabd1249b8123d7da76b Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 20 Feb 2012 14:03:44 +0200 Subject: [PATCH 19/45] Fixed lp:902654 "MariaDB consistently crashes in collect_tables on Aria checkpoint execution" This happend when you have more than 1024 open Aria tables during checkpoint. mysql-test/mysql-test-run.pl: Fixed that variable names are consistent between external and internal server. mysql-test/suite/maria/suite.pm: Test for aria-block-size instead of 'aria' as 'aria' is not set for embedded server. This should be ok for aria tests, as aria is never disabled for these. storage/maria/ma_checkpoint.c: Fixed bug when there are more than 1024 open Aria tables during checkpoint. --- mysql-test/mysql-test-run.pl | 14 ++++++++++---- mysql-test/suite/maria/suite.pm | 2 +- storage/maria/ma_checkpoint.c | 7 +++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index dc03a6bf5b5..9ccfe5df054 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1758,8 +1758,11 @@ sub collect_mysqld_features { # Put variables into hash if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ ) { - # print "$1=\"$2\"\n"; - $mysqld_variables{$1}= $2; + my $name= $1; + my $value=$2; + $name =~ s/_/-/g; + # print "$name=\"$value\"\n"; + $mysqld_variables{$name}= $value; } else { @@ -1813,8 +1816,11 @@ sub collect_mysqld_features_from_running_server () # Put variables into hash if ( $line =~ /^([\S]+)[ \t]+(.*?)\r?$/ ) { - # print "$1=\"$2\"\n"; - $mysqld_variables{$1}= $2; + my $name= $1; + my $value=$2; + $name =~ s/_/-/g; + # print "$name=\"$value\"\n"; + $mysqld_variables{$name}= $value; } } diff --git a/mysql-test/suite/maria/suite.pm b/mysql-test/suite/maria/suite.pm index e6efcdca829..3176782404b 100644 --- a/mysql-test/suite/maria/suite.pm +++ b/mysql-test/suite/maria/suite.pm @@ -2,7 +2,7 @@ package My::Suite::Maria; @ISA = qw(My::Suite); -return "Need Aria engine" unless $::mysqld_variables{'aria'} eq "ON"; +return "Need Aria engine" unless $::mysqld_variables{'aria-block-size'} > 0; bless { }; diff --git a/storage/maria/ma_checkpoint.c b/storage/maria/ma_checkpoint.c index 6576c365a47..002f2999e6c 100644 --- a/storage/maria/ma_checkpoint.c +++ b/storage/maria/ma_checkpoint.c @@ -908,6 +908,9 @@ static int collect_tables(LEX_STRING *str, LSN checkpoint_start_log_horizon) */ } translog_unlock(); + if (state_copy == state_copies) + break; /* Nothing to do */ + /** We are going to flush these states. Before, all records describing how to undo such state must be @@ -932,13 +935,13 @@ static int collect_tables(LEX_STRING *str, LSN checkpoint_start_log_horizon) if (translog_flush(state_copies_horizon)) goto err; /* now we have cached states and they are WAL-safe*/ - state_copies_end= state_copy; + state_copies_end= state_copy-1; state_copy= state_copies; } /* locate our state among these cached ones */ for ( ; state_copy->index != i; state_copy++) - DBUG_ASSERT(state_copy < state_copies_end); + DBUG_ASSERT(state_copy <= state_copies_end); /* OS file descriptors are ints which we stored in 4 bytes */ compile_time_assert(sizeof(int) <= 4); From 54cad2aae3142e8a123f0d62fc0c2bd67a1dc64a Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 20 Feb 2012 17:56:47 +0200 Subject: [PATCH 20/45] Fixed compiler warnings --- mysys/stacktrace.c | 2 +- sql/mysqld.cc | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mysys/stacktrace.c b/mysys/stacktrace.c index dce01a0c3b9..847cc746a76 100644 --- a/mysys/stacktrace.c +++ b/mysys/stacktrace.c @@ -173,7 +173,7 @@ void my_print_stacktrace(uchar* stack_bottom __attribute__((unused)), my_safe_printf_stderr("%s", "Error when traversing the stack, stack appears corrupt.\n"); else - my_safe_printf_stderr("%s" + my_safe_printf_stderr("%s", "Please read " "http://dev.mysql.com/doc/refman/5.1/en/resolve-stack-dump.html\n" "and follow instructions on how to resolve the stack trace.\n" diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 9ca0080e976..63495021841 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -741,7 +741,6 @@ char *opt_logname, *opt_slow_logname; static volatile sig_atomic_t kill_in_progress; #ifdef HAVE_STACKTRACE -static my_bool opt_do_pstack; my_bool opt_stack_trace; #endif /* HAVE_STACKTRACE */ my_bool opt_expect_abort= 0; From 84a3767c1912c34e79cde72a51e4cf69d235587e Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Mon, 20 Feb 2012 17:59:42 +0200 Subject: [PATCH 21/45] Fixed issue found by buildbot mysql-test/suite/innodb/t/innodb_bug51920.test: Add another possible connect error --- mysql-test/suite/innodb/t/innodb_bug51920.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/innodb/t/innodb_bug51920.test b/mysql-test/suite/innodb/t/innodb_bug51920.test index bc3bb006c1c..3c386980ed4 100644 --- a/mysql-test/suite/innodb/t/innodb_bug51920.test +++ b/mysql-test/suite/innodb/t/innodb_bug51920.test @@ -36,7 +36,7 @@ let $wait_condition = # depending on platform. # connection con1; --- error 1317, 2006, 2013 +-- error 1317, 2006, 2013, 1927 reap; connection default; DROP TABLE bug51920; From c381e44050303cf12592ae13f401175fa7171a6f Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Mon, 20 Feb 2012 20:38:05 +0400 Subject: [PATCH 22/45] BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN - In mi_rkey(), do correct handling of case where mi_yield_and_check_if_killed() detects that the thread was killed (all other similar functions in MyISAM/Aria have slightly different code and do not have this problem). - Also fixed assignment in DBUG_ASSERT - this is 2nd variant of the fix: = make .result file smaller = run KILLable statements in a separate connection, otherwise we could end up trying to KILL the final "DROP TABLE" statement --- mysql-test/r/myisam_icp.result | 15 ++++ mysql-test/t/myisam_icp.test | 129 +++++++++++++++++++++++++++++++++ storage/myisam/mi_rkey.c | 6 +- 3 files changed, 149 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/myisam_icp.result b/mysql-test/r/myisam_icp.result index 3171753adb4..d7442608b59 100644 --- a/mysql-test/r/myisam_icp.result +++ b/mysql-test/r/myisam_icp.result @@ -909,4 +909,19 @@ c NULL NULL c NULL NULL SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2,t3,t4; +# +# BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN +# +CREATE TABLE t1 ( +b INT, +c VARCHAR(1) NOT NULL, +d DATETIME, +KEY (c, b) +) ENGINE=MyISAM; +# INSERT some data +CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES +(7),(3),(7),(3); +# Now run a number of ICP queries while trying to kill them +DROP TABLE t1,t2; set optimizer_switch=@myisam_icp_tmp; diff --git a/mysql-test/t/myisam_icp.test b/mysql-test/t/myisam_icp.test index 0e306a850c5..39a22d00a1a 100644 --- a/mysql-test/t/myisam_icp.test +++ b/mysql-test/t/myisam_icp.test @@ -262,4 +262,133 @@ SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2,t3,t4; +--echo # +--echo # BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN +--echo # +CREATE TABLE t1 ( + b INT, + c VARCHAR(1) NOT NULL, + d DATETIME, + KEY (c, b) +) ENGINE=MyISAM; +--echo # INSERT some data +--disable_query_log +INSERT INTO t1 ( b, d, c ) VALUES +(4,'2005-01-08 00:00:00','f'), +(1,'2004-05-20 10:45:51','c'),(2,'2006-08-11 21:33:49','e'), +(5,'2003-05-19 00:20:40','a'),(3,'2005-01-03 06:18:39','a'), +(7,'2008-11-25 18:18:14','b'),(6,'2008-11-09 15:53:46','b'), +(9,'2003-03-01 03:40:36','c'),(8,'2003-09-25 23:14:09','d'), +(0,'2007-01-17 09:18:31','f'),(9,'2008-09-08 09:52:24','c'), +(2,'2008-03-10 00:00:00','a'),(0,'2003-03-14 09:31:07','c'), +(4,'2005-04-25 00:00:00','h'),(6,'2001-08-01 05:55:55','e'), +(3,'2005-04-09 01:22:48','f'),(7,'2009-11-12 13:27:22','r'), +(0,'2009-03-28 05:05:28','h'),(15,'2005-05-16 04:35:41','f'), +(7,'2006-03-26 05:19:58','c'),(9,'2002-10-06 02:17:00','g'), +(4,'2007-01-28 03:28:20','b'),(1,'2009-04-22 10:16:40','c'), +(2,'2003-01-01 19:39:00','f'),(0,'2008-05-03 19:16:29','t'), +(2,'2005-01-28 00:00:00','j'),(8,'2004-01-10 00:00:00','w'), +(8,'2000-06-13 21:56:37','a'),(5,'2001-03-21 19:24:49','o'), +(99,'2003-12-20 21:29:06','f'),(0,'1900-01-01 00:00:00','w'), +(7,'2000-12-19 00:00:00','c'),(0,'2000-03-03 06:10:19','l'), +(3,'2000-08-11 00:00:00','q'),(0,'2007-05-25 03:46:41','e'), +(241,'2005-05-17 00:00:00','j'),(4,'2005-11-02 00:44:06','r'), +(43,'2001-07-11 00:00:00','a'),(1,'2008-12-01 18:30:27','z'), +(4,'2004-10-25 00:00:00','i'),(5,'2000-04-08 12:12:01','c'), +(0,'1900-01-01 00:00:00','f'),(9,'2002-05-13 22:47:02','p'), +(1,'2008-10-09 15:39:40','d'),(3,'2004-06-24 00:00:00','d'), +(0,'2008-03-06 00:00:00','r'),(9,'2007-04-16 18:40:03','i'), +(3,'2008-03-16 19:49:37','t'),(7,'2003-07-15 08:11:21','d'), +(8,'2005-02-11 00:04:53','r'),(0,'2002-09-21 00:00:00','y'), +(3,'2004-11-03 00:37:21','z'),(6,'2007-10-18 00:00:00','e'), +(6,'2007-01-21 10:42:56','o'),(5,'2000-03-26 21:21:04','b'), +(9,'2001-03-15 08:08:21','e'),(1,'2001-10-16 12:56:59','a'), +(6,'2004-05-01 23:45:55','o'),(4,'2000-03-04 00:00:00','f'), +(9,'2002-12-03 16:48:28','e'),(8,'2003-01-09 00:36:07','m'), +(1,'2006-06-22 04:32:41','s'),(8,'2008-09-20 05:01:48','q'), +(4,'2006-06-02 22:15:31','g'),(2,'2002-05-14 07:07:42','e'), +(7,'2005-06-05 01:30:42','r'),(127,'2004-05-11 01:56:48','a'), +(210,'2003-11-05 00:41:34','z'),(5,'1900-01-01 00:00:00','h'), +(1,'2006-04-16 00:00:00','f'),(7,'2000-12-17 00:00:00','x'), +(8,'2009-05-09 20:43:07','b'),(175,'2008-11-26 16:33:09','p'), +(0,'2002-05-09 21:18:44','v'),(8,'2002-06-01 11:32:25','k'), +(1,'2008-11-09 23:56:00','a'),(0,'2008-01-08 10:18:46','c'), +(2,'2005-04-16 00:00:00','o'),(5,'2002-08-25 00:00:00','b'), +(64,'2005-12-05 21:51:52','b'),(4,'2005-08-10 00:00:00','i'), +(6,'2006-03-23 00:00:00','d'),(9,'2007-01-27 00:00:00','i'), +(8,'2008-08-16 00:00:00','a'),(7,'2003-01-16 12:13:18','k'), +(0,'2003-06-22 00:00:00','v'),(5,'2008-06-20 05:43:56','u'), +(8,'2004-09-23 18:57:17','e'),(1,'2000-12-26 00:00:00','y'), +(4,'2009-06-01 13:00:28','e'),(1,'2009-11-18 06:28:48','m'), +(0,'2004-06-12 10:01:10','e'),(2,'2005-10-16 01:48:55','e'), +(5,'2001-12-23 09:50:21','l'),(6,'1900-01-01 00:00:00','a'), +(1,'2001-10-28 00:00:00','d'),(1,'2008-07-12 23:30:19','s'), +(0,'2002-10-11 16:51:16','r'),(4,'2007-09-18 06:27:10','x'), +(1,'2007-02-21 12:28:14','e'),(6,'2001-09-16 00:00:00','f'), +(0,'2007-09-20 02:25:45','c'),(0,'2006-08-07 03:25:56','j'), +(8,'2006-12-04 20:20:32','t'),(7,'2007-09-05 10:13:10','i'), +(9,'2006-04-12 17:59:57','t'),(2,'2009-04-28 00:06:09','b'), +(8,'2000-01-07 00:00:00','b'),(7,'2000-03-25 10:04:41','k'), +(4,'2000-07-10 00:44:55','w'),(9,'2007-09-22 14:26:26','j'), +(9,'2003-09-11 22:41:17','a'),(0,'2004-06-07 13:52:32','c'), +(8,'2008-10-09 00:00:00','p'),(1,'2007-04-01 00:00:00','c'), +(9,'2000-12-05 00:00:00','i'),(3,'1900-01-01 00:00:00','a'), +(3,'2005-12-24 21:50:54','e'),(8,'2009-07-21 19:34:55','n'), +(9,'2005-11-13 17:57:56','d'),(7,'2004-10-07 06:41:39','l'), +(1,'2004-11-20 08:05:08','u'),(3,'2005-05-25 00:00:00','r'), +(1,'2006-09-02 14:16:41','u'),(8,'2006-01-07 00:00:00','a'), +(9,'2003-04-05 00:54:20','w'),(2,'2003-12-22 00:00:00','a'), +(9,'2006-04-16 17:31:40','e'),(6,'2005-02-10 14:22:46','e'), +(7,'2004-04-27 05:54:52','p'),(1,'2005-12-07 00:00:00','t'), +(5,'2004-04-03 20:56:28','d'),(4,'2000-09-07 05:17:16','h'), +(2,'2004-08-04 16:10:42','i'),(1,'2007-03-04 00:00:00','b'), +(9,'1900-01-01 00:00:00','d'),(1,'2000-05-12 23:02:50','m'), +(2,'1900-01-01 00:00:00','l'),(1,'1900-01-01 00:00:00','k'), +(4,'2000-07-14 01:25:18','d'),(5,'2009-08-21 00:00:00','w'), +(6,'2009-05-25 13:33:54','f'),(7,'2006-06-13 00:00:00','e'), +(8,'1900-01-01 00:00:00','a'),(6,'2004-02-24 00:00:00','j'), +(0,'2003-05-21 07:03:46','k'),(9,'1900-01-01 00:00:00','e'), +(2,'1900-01-01 00:00:00','y'),(2,'2000-12-22 00:00:00','e'), +(3,'2003-09-26 00:00:00','f'),(2,'2001-01-13 08:20:19','h'), +(9,'2008-09-23 20:03:28','n'),(5,'2007-03-20 02:41:38','s'), +(1,'2009-02-14 10:27:18','a'),(0,'2001-08-10 17:44:05','s'), +(3,'2008-01-20 12:49:54','v'),(1,'2001-05-05 09:09:59','r'); +--enable_query_log +CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES + (7),(3),(7),(3); + +# 'con2' will be the connection that will run all the KILLable statements +--connect (con2,127.0.0.1,root,,test) + +--let $run = 300 +--let $con_id = `SELECT CONNECTION_ID()` + +--echo # Now run a number of ICP queries while trying to kill them +--disable_query_log +--disable_result_log +while ($run) +{ + --send + SELECT * FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2 + ON alias2.c = alias1.c + WHERE alias2.b >= 9; + + --connect (con1,127.0.0.1,root,,test) + --eval KILL QUERY $con_id + --disconnect con1 + + --dec $run + + --connection con2 + --error 0,ER_QUERY_INTERRUPTED + --reap +} +--enable_result_log +--enable_query_log +--disconnect con2 +--connection default +DROP TABLE t1,t2; + set optimizer_switch=@myisam_icp_tmp; + diff --git a/storage/myisam/mi_rkey.c b/storage/myisam/mi_rkey.c index dbe4d59ee90..d2af9a3e5ed 100644 --- a/storage/myisam/mi_rkey.c +++ b/storage/myisam/mi_rkey.c @@ -157,7 +157,11 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key, mi_yield_and_check_if_killed(info, inx)) { /* Aborted by user */ + DBUG_ASSERT(info->lastpos == HA_OFFSET_ERROR && + my_errno == HA_ERR_ABORTED_BY_USER); + res= ICP_ERROR; buf= 0; /* Fast abort */ + break; } } if (res == ICP_OUT_OF_RANGE) @@ -179,7 +183,7 @@ int mi_rkey(MI_INFO *info, uchar *buf, int inx, const uchar *key, } else { - DBUG_ASSERT(info->lastpos= HA_OFFSET_ERROR); + DBUG_ASSERT(info->lastpos == HA_OFFSET_ERROR); } } if (share->concurrent_insert) From e7fef1df58559f29c16a4571d4218ff291a8050e Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 20 Feb 2012 18:07:38 +0100 Subject: [PATCH 23/45] Fix compilation on Windows, and various Windows related mistakes introduced by "safe exception patch". Remove misleading comments suggesting about signal() Windows, the routine here is part of a exception handler, and sig parameter is an exception code. --- sql/signal_handler.cc | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 23d898fdb5e..6406cd3bae0 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -28,7 +28,7 @@ #endif /* - We are handling signals in this file. + We are handling signals/exceptions in this file. Any global variables we read should be 'volatile sig_atomic_t' to guarantee that we read some consistent value. */ @@ -40,20 +40,18 @@ extern volatile sig_atomic_t ld_assume_kernel_is_set; #endif /** - * Handler for fatal signals + * Handler for fatal signals on POSIX, exception handler on Windows. * * Fatal events (seg.fault, bus error etc.) will trigger * this signal handler. The handler will try to dump relevant * debugging information to stderr and dump a core image. * - * Signal handlers can only use a set of 'safe' system calls - * and library functions. A list of safe calls in POSIX systems + * POSIX : Signal handlers should, if possible, only use a set of 'safe' system + * calls and library functions. A list of safe calls in POSIX systems * are available at: * http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html - * For MS Windows, guidelines are available at: - * http://msdn.microsoft.com/en-us/library/xdkz3x12(v=vs.71).aspx * - * @param sig Signal number + * @param sig Signal number /Exception code */ extern "C" sig_handler handle_fatal_signal(int sig) { @@ -77,7 +75,13 @@ extern "C" sig_handler handle_fatal_signal(int sig) my_safe_printf_stderr("%02d%02d%02d %2d:%02d:%02d ", tm.tm_year % 100, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec); - if (opt_expect_abort && sig == SIGABRT) + if (opt_expect_abort +#ifdef _WIN32 + && sig == EXCEPTION_BREAKPOINT /* __debugbreak in my_sigabrt_hander() */ +#else + && sig == SIGABRT +#endif + ) { fprintf(stderr,"[Note] mysqld did an expected abort\n"); goto end; @@ -252,5 +256,7 @@ end: On Windows, do not terminate, but pass control to exception filter. */ _exit(1); // Using _exit(), since exit() is not async signal safe +#else + return; #endif } From 446554a15bd84f39ec4a8163e9f4456fa9be8fb2 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 20 Feb 2012 21:30:23 +0100 Subject: [PATCH 24/45] fix for "relocation R_X86_64_PC32 against `handler_index_cond_check' can not be used when making a shared object; recompile with -fPIC" don't use visibility=hidden for external functions --- storage/xtradb/include/ha_prototypes.h | 1 - 1 file changed, 1 deletion(-) diff --git a/storage/xtradb/include/ha_prototypes.h b/storage/xtradb/include/ha_prototypes.h index 28c28838400..df7d71af6cf 100644 --- a/storage/xtradb/include/ha_prototypes.h +++ b/storage/xtradb/include/ha_prototypes.h @@ -250,7 +250,6 @@ innobase_get_at_most_n_mbchars( /*************************************************************//** InnoDB index push-down condition check @return ICP_NO_MATCH, ICP_MATCH, or ICP_OUT_OF_RANGE */ -UNIV_INTERN enum icp_result handler_index_cond_check( /*================*/ From 150f2385381082af6c7ea1dcad08ecc9f3417b7d Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 20 Feb 2012 22:25:44 +0100 Subject: [PATCH 25/45] Workaround buggy Linux dtrace - it fails on fedora if CC is set to 'ccache gcc' --- cmake/dtrace.cmake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmake/dtrace.cmake b/cmake/dtrace.cmake index 882ea0de6aa..0e7c71c7f09 100644 --- a/cmake/dtrace.cmake +++ b/cmake/dtrace.cmake @@ -34,9 +34,15 @@ MACRO(CHECK_DTRACE) FIND_PROGRAM(DTRACE dtrace) MARK_AS_ADVANCED(DTRACE) + IF(CMAKE_C_COMPILER MATCHES "ccache" AND CMAKE_SYSTEM_NAME MATCHES "Linux") + # dtrace fails on fedora if CC='ccache gcc' is used + SET(BUGGY_LINUX_DTRACE 1) + ENDIF() + # On FreeBSD, dtrace does not handle userland tracing yet IF(DTRACE AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD" - AND NOT BUGGY_GCC_NO_DTRACE_MODULES) + AND NOT BUGGY_GCC_NO_DTRACE_MODULES + AND NOT BUGGY_LINUX_DTRACE) SET(ENABLE_DTRACE ON CACHE BOOL "Enable dtrace") ENDIF() SET(HAVE_DTRACE ${ENABLE_DTRACE}) From 00995935628c9e865ee545422871363be75812b8 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 21 Feb 2012 01:08:22 +0400 Subject: [PATCH 26/45] BUG#919878: Assertion `!eliminated_tables... - In MySQL 5.5, print_join() was re-worked to print "FROM dual" when all tables are constant. This change didn't work together with table elimination. --- mysql-test/r/table_elim.result | 19 +++++++++++++++++++ mysql-test/t/table_elim.test | 18 ++++++++++++++++++ sql/sql_select.cc | 27 +++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/table_elim.result b/mysql-test/r/table_elim.result index 9b2656c17e4..69cd9792299 100644 --- a/mysql-test/r/table_elim.result +++ b/mysql-test/r/table_elim.result @@ -588,4 +588,23 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where; Using index drop view v1; DROP TABLE t1,t2,t3; +# +# BUG#919878: Assertion `!eliminated_tables... +# +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 +( b INT, UNIQUE INDEX(b) ); +INSERT INTO t2 VALUES (1),(2); +EXPLAIN EXTENDED +SELECT * FROM t2 +WHERE b IN ( +SELECT SUM(a) FROM t1 LEFT JOIN t2 ON b=a +); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 PRIMARY t2 index NULL b 5 NULL 2 100.00 Using where; Using index +2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1 100.00 +Warnings: +Note 1003 select `test`.`t2`.`b` AS `b` from `test`.`t2` where <`test`.`t2`.`b`>((`test`.`t2`.`b`,(select sum(1) from dual where 1 having ((`test`.`t2`.`b`) = (sum(1)))))) +DROP TABLE t1,t2; SET optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/t/table_elim.test b/mysql-test/t/table_elim.test index dc32618eb8c..26b98c9023b 100644 --- a/mysql-test/t/table_elim.test +++ b/mysql-test/t/table_elim.test @@ -521,4 +521,22 @@ EXPLAIN SELECT alias1.* FROM t3 LEFT JOIN v1 as alias1 ON ( t3.a = alias1.b ); drop view v1; DROP TABLE t1,t2,t3; +--echo # +--echo # BUG#919878: Assertion `!eliminated_tables... +--echo # +CREATE TABLE t1 ( a INT ); +INSERT INTO t1 VALUES (1); + +CREATE TABLE t2 + ( b INT, UNIQUE INDEX(b) ); +INSERT INTO t2 VALUES (1),(2); + +EXPLAIN EXTENDED + SELECT * FROM t2 + WHERE b IN ( + SELECT SUM(a) FROM t1 LEFT JOIN t2 ON b=a + ); + +DROP TABLE t1,t2; + SET optimizer_switch=@save_optimizer_switch; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5e483c2d359..9a085ec6314 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -21442,6 +21442,8 @@ static void print_table_array(THD *thd, (curr->nested_join && !(curr->nested_join->used_tables & ~eliminated_tables)))) { + /* as of 5.5, print_join doesnt put eliminated elements into array */ + DBUG_ASSERT(0); continue; } @@ -21467,6 +21469,21 @@ static void print_table_array(THD *thd, } +/* + Check if the passed table is + - a base table which was eliminated, or + - a join nest which only contained eliminated tables (and so was eliminated, + too) +*/ + +static bool is_eliminated_table(table_map eliminated_tables, TABLE_LIST *tbl) +{ + return eliminated_tables && + ((tbl->table && (tbl->table->map & eliminated_tables)) || + (tbl->nested_join && !(tbl->nested_join->used_tables & + ~eliminated_tables))); +} + /** Print joins from the FROM clause. @@ -21488,8 +21505,14 @@ static void print_join(THD *thd, uint non_const_tables= 0; for (TABLE_LIST *t= ti++; t ; t= ti++) - if (!t->optimized_away) + { + /* + See comment in print_table_array() about the second part of the + condition + */ + if (!t->optimized_away && !is_eliminated_table(eliminated_tables, t)) non_const_tables++; + } if (!non_const_tables) { str->append(STRING_WITH_LEN("dual")); @@ -21504,7 +21527,7 @@ static void print_join(THD *thd, TABLE_LIST *tmp, **t= table + (non_const_tables - 1); while ((tmp= ti++)) { - if (tmp->optimized_away) + if (tmp->optimized_away || is_eliminated_table(eliminated_tables, tmp)) continue; *t--= tmp; } From 352e848f214ab401d013604701341487a4fe2520 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 21 Feb 2012 01:50:50 +0400 Subject: [PATCH 27/45] BUG#920132: Assert trx->n_active_thrs == 1 failed at que0que.c line 1050 - MySQL 5.5 introduced caching of constant items by means of wrapping them in Item_cache_XXX objects. If a subquery was wrapped in this cache, it could end up being pushed down by ICP. - The fix is to add Item_cache::walk() which lets ICP to see that the cache item has a subquery inside it, and disable pushdown for this case. --- mysql-test/r/innodb_icp.result | 29 +++++++++++++++++++++++++++++ mysql-test/t/innodb_icp.test | 33 +++++++++++++++++++++++++++++++++ sql/item.h | 6 ++++++ 3 files changed, 68 insertions(+) diff --git a/mysql-test/r/innodb_icp.result b/mysql-test/r/innodb_icp.result index 08238289330..c2def708662 100644 --- a/mysql-test/r/innodb_icp.result +++ b/mysql-test/r/innodb_icp.result @@ -808,5 +808,34 @@ COUNT(*) 1478 SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2; +# +# BUG#920132: Assert trx->n_active_thrs == 1 failed at que0que.c line 1050 +# +CREATE TABLE t1 ( a INT ) +ENGINE=InnoDB; +INSERT INTO t1 VALUES (7),(7); +CREATE TABLE t2 ( b VARCHAR(1) ); +INSERT INTO t2 VALUES ('j'),('v'); +CREATE TABLE t3 ( +c INT, d VARCHAR(1), e VARCHAR(1), +KEY (d,c) +) ENGINE=InnoDB; +INSERT INTO t3 +VALUES (6,'w','w'), +(1,'v','v'),(7,'s','s'),(4,'l','l'), +(7,'y','y'),(0,'c','c'),(2,'i','i'), +(9,'h','h'),(4,'q','q'),(0,'a','a'), +(9,'v','v'),(1,'u','u'),(3,'s','s'), +(8,'z','z'),(1,'h','h'),(8,'p','p'), +(6,'e','e'),(3,'i','i'),(6,'y','y'); +SELECT * +FROM t1 INNER JOIN t2 INNER JOIN t3 +ON d = b +WHERE +NOT EXISTS ( SELECT * FROM t3 ) +OR a = c +ORDER BY e; +a b c d e +DROP TABLE t1,t2,t3; set optimizer_switch=@innodb_icp_tmp; set storage_engine= @save_storage_engine; diff --git a/mysql-test/t/innodb_icp.test b/mysql-test/t/innodb_icp.test index 0fb42355f96..d6caa36a88e 100644 --- a/mysql-test/t/innodb_icp.test +++ b/mysql-test/t/innodb_icp.test @@ -12,6 +12,39 @@ set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; --source include/icp_tests.inc +--echo # +--echo # BUG#920132: Assert trx->n_active_thrs == 1 failed at que0que.c line 1050 +--echo # +CREATE TABLE t1 ( a INT ) + ENGINE=InnoDB; +INSERT INTO t1 VALUES (7),(7); + +CREATE TABLE t2 ( b VARCHAR(1) ); +INSERT INTO t2 VALUES ('j'),('v'); + +CREATE TABLE t3 ( + c INT, d VARCHAR(1), e VARCHAR(1), + KEY (d,c) +) ENGINE=InnoDB; +INSERT INTO t3 + VALUES (6,'w','w'), + (1,'v','v'),(7,'s','s'),(4,'l','l'), + (7,'y','y'),(0,'c','c'),(2,'i','i'), + (9,'h','h'),(4,'q','q'),(0,'a','a'), + (9,'v','v'),(1,'u','u'),(3,'s','s'), + (8,'z','z'),(1,'h','h'),(8,'p','p'), + (6,'e','e'),(3,'i','i'),(6,'y','y'); + +SELECT * +FROM t1 INNER JOIN t2 INNER JOIN t3 + ON d = b +WHERE + NOT EXISTS ( SELECT * FROM t3 ) + OR a = c +ORDER BY e; + +DROP TABLE t1,t2,t3; + set optimizer_switch=@innodb_icp_tmp; set storage_engine= @save_storage_engine; diff --git a/sql/item.h b/sql/item.h index 6c0d3138b62..4af2038aa55 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3901,6 +3901,12 @@ public: return example->is_expensive_processor(arg); } virtual void set_null(); + bool walk(Item_processor processor, bool walk_subquery, uchar *arg) + { + if (example && example->walk(processor, walk_subquery, arg)) + return TRUE; + return (this->*processor)(arg); + } }; From 7ed4806b1181c1f003d2d31f997a4ca6609ee794 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 21 Feb 2012 01:44:50 +0200 Subject: [PATCH 28/45] More general handling of memory loss in dlclose (backported from 5.2) Fixed supression in mysql-test-run so it also works on windows. mysql-test/mysql-test-run.pl: Fixed supression so it also works on windows. mysql-test/valgrind.supp: More general handling of memory loss in dlclose (backported from 5.2) sql/signal_handler.cc: Added newlines around link to how to do bug reports --- mysql-test/mysql-test-run.pl | 4 +- mysql-test/valgrind.supp | 130 ++--------------------------------- sql/signal_handler.cc | 4 +- 3 files changed, 11 insertions(+), 127 deletions(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index cb6f7b4a486..3e1be3ab077 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -4443,9 +4443,9 @@ sub extract_warning_lines ($) { qr/Failed on request_dump/, qr/Slave: Can't drop database.* database doesn't exist/, qr/Slave: Operation DROP USER failed for 'create_rout_db'/, - qr|Checking table: '\./mtr/test_suppressions'|, + qr|Checking table: '\..mtr.test_suppressions'|, qr|Table \./test/bug53592 has a primary key in InnoDB data dictionary, but not in MySQL|, - qr|mysqld: Table '\./mtr/test_suppressions' is marked as crashed and should be repaired|, + qr|mysqld: Table '\..mtr.test_suppressions' is marked as crashed and should be repaired|, qr|InnoDB: Error: table 'test/bug39438'|, qr|table.*is full|, ); diff --git a/mysql-test/valgrind.supp b/mysql-test/valgrind.supp index ff649db144a..e7f5a7880d2 100644 --- a/mysql-test/valgrind.supp +++ b/mysql-test/valgrind.supp @@ -386,134 +386,18 @@ fun:__libc_start_main } +# +# dlclose can allocate memory for error message, the memory will be +# freed by dlerror or other dl* function. +# { - dlclose memory loss from udf_free + memory "loss" from dlclose error messages Memcheck:Leak - fun:calloc - fun:_dlerror_run + fun:*alloc + ... fun:dlclose - fun:_Z8udf_freev } -{ - dlsym memory loss from udf_free on SuSE 11.1 x64 variant 2 - Memcheck:Leak - fun:calloc - obj:/lib*/ld-*.so - fun:dlclose - fun:udf_free -} - -{ - dlclose memory loss from plugin variant 1 - Memcheck:Leak - fun:calloc - fun:_dlerror_run - fun:dlclose - fun:plugin_dl_del(st_mysql_lex_string const*) -} - -{ - dlclose memory loss from plugin variant 2 - Memcheck:Leak - fun:malloc - fun:_dl_close_worker - fun:_dl_close - fun:_dl_catch_error - fun:_dlerror_run - fun:dlclose - fun:_Z15free_plugin_memP12st_plugin_dl - fun:_Z13plugin_dl_delPK19st_mysql_lex_string -} - -{ - dlclose memory loss from plugin variant 3 - Memcheck:Leak - fun:malloc - fun:_dl_scope_free - fun:_dl_close_worker - fun:_dl_close - fun:_dl_catch_error - fun:_dlerror_run - fun:dlclose - fun:_Z15free_plugin_memP12st_plugin_dl - fun:_Z13plugin_dl_delPK19st_mysql_lex_string -} - -{ - dlclose memory loss from plugin variant 4 - Memcheck:Leak - fun:malloc - obj:/lib*/ld-*.so - obj:/lib*/ld-*.so - obj:/lib*/ld-*.so - obj:/lib*/libdl-*.so - fun:dlclose - fun:_ZL15free_plugin_memP12st_plugin_dl - fun:_ZL13plugin_dl_delPK19st_mysql_lex_string -} - -{ - dlclose memory loss from plugin variant 5 - Memcheck:Leak - fun:malloc - obj:/lib*/ld-*.so - obj:/lib*/ld-*.so - obj:/lib*/ld-*.so - obj:/lib*/ld-*.so - obj:/lib*/libdl-*.so - fun:dlclose - fun:_ZL15free_plugin_memP12st_plugin_dl -} - -{ - dlclose memory loss from plugin variant 6, seen on Ubuntu Jaunty i686 - Memcheck:Leak - fun:malloc - fun:_dl_scope_free - fun:_dl_close_worker - fun:_dl_close - fun:dlclose_doit - fun:_dl_catch_error - fun:_dlerror_run - fun:dlclose - fun:_ZL15free_plugin_memP12st_plugin_dl - fun:_ZL13plugin_dl_delPK19st_mysql_lex_string -} - -{ - dlclose memory loss from plugin variant 7, seen on Ubuntu Jaunty i686 - Memcheck:Leak - fun:malloc - fun:_dl_close_worker - fun:_dl_close - fun:dlclose_doit - fun:_dl_catch_error - fun:_dlerror_run - fun:dlclose - fun:_ZL15free_plugin_memP12st_plugin_dl - fun:_ZL13plugin_dl_delPK19st_mysql_lex_string -} - -{ - dlclose memory loss from plugin variant 8 - Memcheck:Leak - fun:calloc - fun:_dlerror_run - fun:dlclose - fun:_Z15free_plugin_memP12st_plugin_dl - fun:_Z13plugin_dl_delPK19st_mysql_lex_string -} - -{ - dlclose memory loss from plugin variant 9 - Memcheck:Leak - fun:calloc - fun:_dlerror_run - fun:dlclose - fun:_ZL15free_plugin_memP12st_plugin_dl - fun:_ZL13plugin_dl_delPK19st_mysql_lex_string -} { dlsym memory loss from plugin on SuSE 11.1 x64 diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 23d898fdb5e..289670ec830 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -88,10 +88,10 @@ extern "C" sig_handler handle_fatal_signal(int sig) my_safe_printf_stderr("%s", "This could be because you hit a bug. It is also possible that this binary\n" "or one of the libraries it was linked against is corrupt, improperly built,\n" - "or misconfigured. This error can also be caused by malfunctioning hardware.\n"); + "or misconfigured. This error can also be caused by malfunctioning hardware.\n\n"); my_safe_printf_stderr("%s", - "To report this bug, see http://kb.askmonty.org/en/reporting-bugs\n"); + "To report this bug, see http://kb.askmonty.org/en/reporting-bugs\n\n"); my_safe_printf_stderr("%s", "We will try our best to scrape up some info that will hopefully help\n" From f4885c092e3414cb4274e055310f27eae1d28819 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 21 Feb 2012 01:46:51 +0200 Subject: [PATCH 29/45] Added missing signal values to signal_handler.cc sql/signal_handler.cc: Added missing signal values. --- sql/signal_handler.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 23d898fdb5e..13396551e7d 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -173,6 +173,12 @@ extern "C" sig_handler handle_fatal_signal(int sig) case THD::KILL_QUERY: kreason= "KILL_QUERY"; break; + case THD::KILL_SYSTEM_THREAD: + kreason= "KILL_SYSTEM_THREAD"; + break; + case THD::KILL_SERVER: + kreason= "KILL_SERVER"; + break; case THD::KILLED_NO_VALUE: kreason= "KILLED_NO_VALUE"; break; From 3608ec3036fba4921c11e3d2caa3584c41975187 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 21 Feb 2012 09:35:46 +0200 Subject: [PATCH 30/45] Fixed wrong test case mysql-test/suite/innodb_plugin/t/innodb_gis.test: Don't run test if innodb_plugin isn't used. --- mysql-test/suite/innodb_plugin/t/innodb_gis.test | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/innodb_plugin/t/innodb_gis.test b/mysql-test/suite/innodb_plugin/t/innodb_gis.test index dec0c8bf725..ad1d081f29c 100644 --- a/mysql-test/suite/innodb_plugin/t/innodb_gis.test +++ b/mysql-test/suite/innodb_plugin/t/innodb_gis.test @@ -1,3 +1,4 @@ +--source include/have_innodb_plugin.inc SET storage_engine=innodb; --source include/gis_generic.inc --source include/gis_keys.inc From 70e6f0d854cb7a47bd24e09f1a1723f106afd53f Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 21 Feb 2012 14:17:33 +0200 Subject: [PATCH 31/45] Fixed suppression expression. --- mysql-test/mysql-test-run.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 3e1be3ab077..34b018bcc47 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -4445,7 +4445,7 @@ sub extract_warning_lines ($) { qr/Slave: Operation DROP USER failed for 'create_rout_db'/, qr|Checking table: '\..mtr.test_suppressions'|, qr|Table \./test/bug53592 has a primary key in InnoDB data dictionary, but not in MySQL|, - qr|mysqld: Table '\..mtr.test_suppressions' is marked as crashed and should be repaired|, + qr|Table '\..mtr.test_suppressions' is marked as crashed and should be repaired|, qr|InnoDB: Error: table 'test/bug39438'|, qr|table.*is full|, ); From 6fbeed067b25a07542dd989b7a816969615d7df6 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 21 Feb 2012 17:58:43 +0200 Subject: [PATCH 32/45] Fixed that 'make distcheck' works with automake 1.11.11 Fixed compiler warnings found by buildbot Makefile.am: Removed extra empty line cmd-line-utils/libedit/sys.h: Fixed that strndup() doesn't give compiler warnings mysql-test/Makefile.am: Fixes for 'make distcheck' plugin/auth_pam/auth_pam.c: Ensure that prototype for strndup() is included on linux sql/share/Makefile.am: Fixes for 'make distcheck' storage/innodb_plugin/btr/btr0sea.c: Fixed compiler warning support-files/Makefile.am: Fixes for 'make distcheck' --- Makefile.am | 1 - cmd-line-utils/libedit/sys.h | 22 +++++++++++----------- mysql-test/Makefile.am | 2 ++ plugin/auth_pam/auth_pam.c | 4 ++++ sql/share/Makefile.am | 1 + storage/innodb_plugin/btr/btr0sea.c | 4 ++-- support-files/Makefile.am | 3 +++ 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index cc1156fce5a..f0b617fcb66 100644 --- a/Makefile.am +++ b/Makefile.am @@ -277,7 +277,6 @@ API_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql.h \ TEST_PREPROCESSOR_HEADER = $(API_PREPROCESSOR_HEADER) \ $(top_srcdir)/sql/mysql_priv.h - # # Rules for checking that the abi/api has not changed. diff --git a/cmd-line-utils/libedit/sys.h b/cmd-line-utils/libedit/sys.h index 33638d1565b..af55bcd7202 100644 --- a/cmd-line-utils/libedit/sys.h +++ b/cmd-line-utils/libedit/sys.h @@ -40,6 +40,17 @@ #ifndef _h_sys #define _h_sys +#ifdef __linux__ +/* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#endif + +#ifndef __USE_XOPEN +#define __USE_XOPEN +#endif + #ifdef HAVE_SYS_CDEFS_H #include #endif @@ -92,17 +103,6 @@ size_t strlcpy(char *dst, const char *src, size_t size); char *fgetln(FILE *fp, size_t *len); #endif -#ifdef __linux__ -/* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#endif - -#ifndef __USE_XOPEN -#define __USE_XOPEN -#endif - #include #include diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index 6a1e677fd79..e1780982b8c 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -144,6 +144,8 @@ install-data-local: uninstall-local: @RM@ -f -r $(DESTDIR)$(testdir) +uninstall-am: uninstall-local + # mtr - a shortcut for executing mysql-test-run.pl mtr: $(RM) -f mtr diff --git a/plugin/auth_pam/auth_pam.c b/plugin/auth_pam/auth_pam.c index ee13b37f793..de62ebf8dbd 100644 --- a/plugin/auth_pam/auth_pam.c +++ b/plugin/auth_pam/auth_pam.c @@ -1,3 +1,7 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE /* For strndup() */ +#endif + #include #include #include diff --git a/sql/share/Makefile.am b/sql/share/Makefile.am index 892a720900e..8b7792481e6 100644 --- a/sql/share/Makefile.am +++ b/sql/share/Makefile.am @@ -49,6 +49,7 @@ install-data-local: $(INSTALL_DATA) $(srcdir)/charsets/*.xml $(DESTDIR)$(pkgdatadir)/charsets # FIXME maybe shouldn't remove, could be needed by other installation? +# Note that this removes the directory that support-files are using! uninstall-local: @RM@ -f -r $(DESTDIR)$(pkgdatadir) diff --git a/storage/innodb_plugin/btr/btr0sea.c b/storage/innodb_plugin/btr/btr0sea.c index 3dd30cbc0f3..04c273344f3 100644 --- a/storage/innodb_plugin/btr/btr0sea.c +++ b/storage/innodb_plugin/btr/btr0sea.c @@ -827,7 +827,7 @@ btr_search_guess_on_hash( mtr_t* mtr) /*!< in: mtr */ { buf_block_t* block; - const rec_t* rec; + rec_t* rec; ulint fold; dulint index_id; #ifdef notdefined @@ -913,7 +913,7 @@ btr_search_guess_on_hash( ut_ad(page_rec_is_user_rec(rec)); - btr_cur_position(index, (rec_t*) rec, block, cursor); + btr_cur_position(index, rec, block, cursor); /* Check the validity of the guess within the page */ diff --git a/support-files/Makefile.am b/support-files/Makefile.am index 6b5dfbd7d8d..821ba7ffac9 100644 --- a/support-files/Makefile.am +++ b/support-files/Makefile.am @@ -85,6 +85,9 @@ mysql-@VERSION@.spec: mysql.spec rm -f $@ cp mysql.spec $@ +# We don't need to uninstall as sql/share/Makefile.am is doing that for us +uninstall-am: + SUFFIXES = .sh .sh: From c9fc9f73170a8eb16ea968a2ea51b298eb5cdcfc Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 21 Feb 2012 21:18:41 +0100 Subject: [PATCH 33/45] lp:923429 Crash in decimal_cmp on using UNIX_TIMESTAMP with a wrongly formatted timestamp UNIX_TIMESTAMP() can be null, and returns null for invalid values --- mysql-test/r/type_timestamp.result | 13 +++++++++++++ mysql-test/t/type_timestamp.test | 7 +++++++ sql/item_timefunc.cc | 8 -------- sql/item_timefunc.h | 5 ----- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result index cfe229d2d15..5c3c3226bf8 100644 --- a/mysql-test/r/type_timestamp.result +++ b/mysql-test/r/type_timestamp.result @@ -587,3 +587,16 @@ Variable_name Value Handler_read_next 1 DROP TABLE t1, t2; End of 5.1 tests +# +# lp:923429 Crash in decimal_cmp on using UNIX_TIMESTAMP with a wrongly formatted timestamp +# +SELECT UNIX_TIMESTAMP('abc') > 0; +UNIX_TIMESTAMP('abc') > 0 +NULL +Warnings: +Warning 1292 Incorrect datetime value: 'abc' +SELECT UNIX_TIMESTAMP('abc'); +UNIX_TIMESTAMP('abc') +NULL +Warnings: +Warning 1292 Incorrect datetime value: 'abc' diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test index 533a45ba7fe..674f22cd1c2 100644 --- a/mysql-test/t/type_timestamp.test +++ b/mysql-test/t/type_timestamp.test @@ -410,3 +410,10 @@ SHOW STATUS LIKE 'Handler_read_next'; DROP TABLE t1, t2; --echo End of 5.1 tests + +--echo # +--echo # lp:923429 Crash in decimal_cmp on using UNIX_TIMESTAMP with a wrongly formatted timestamp +--echo # +SELECT UNIX_TIMESTAMP('abc') > 0; +SELECT UNIX_TIMESTAMP('abc'); + diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index e01a4399cbe..1002cf9fea8 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1134,15 +1134,7 @@ bool Item_func_unix_timestamp::get_timestamp_value(my_time_t *seconds, MYSQL_TIME ltime; if (get_arg0_date(<ime, 0)) - { - /* - We have to set null_value again because get_arg0_date will also set it - to true if we have wrong datetime parameter (and we should return 0 in - this case). - */ - null_value= args[0]->null_value; return 1; - } uint error_code; *seconds= TIME_to_timestamp(current_thd, <ime, &error_code); diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index e1bf53a5baf..8d19e59ddfb 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -385,11 +385,6 @@ public: Item_func_unix_timestamp(Item *a) :Item_func_seconds_hybrid(a) {} const char *func_name() const { return "unix_timestamp"; } bool check_partition_func_processor(uchar *int_arg) {return FALSE;} - void fix_num_length_and_dec() - { - maybe_null= false; - Item_func_seconds_hybrid::fix_num_length_and_dec(); - } /* UNIX_TIMESTAMP() depends on the current timezone (and thus may not be used as a partitioning function) From c299e027eeddc35e0197ebc70805e0a303a4b135 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Feb 2012 10:38:28 +0200 Subject: [PATCH 34/45] Changed names of statistic variables and counting matches instaed of rejected rows. --- mysql-test/include/icp_tests.inc | 6 +++--- mysql-test/r/innodb_icp.result | 18 +++++++++--------- mysql-test/r/join_cache.result | 24 ++++++++++++------------ mysql-test/r/maria_icp.result | 18 +++++++++--------- mysql-test/r/myisam_icp.result | 18 +++++++++--------- mysql-test/r/status.result | 8 ++++---- mysql-test/r/status_user.result | 4 ++-- mysql-test/t/join_cache.test | 8 ++++---- sql/handler.cc | 6 +++--- sql/mysqld.cc | 4 ++-- sql/sql_class.h | 4 ++-- sql/sql_join_cache.cc | 12 ++++++------ 12 files changed, 65 insertions(+), 65 deletions(-) diff --git a/mysql-test/include/icp_tests.inc b/mysql-test/include/icp_tests.inc index f412843ded0..e84b8622cdb 100644 --- a/mysql-test/include/icp_tests.inc +++ b/mysql-test/include/icp_tests.inc @@ -862,15 +862,15 @@ CREATE TABLE t1 ( INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); flush status; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; DROP TABLE t1; diff --git a/mysql-test/r/innodb_icp.result b/mysql-test/r/innodb_icp.result index d8e41113f63..2817f83bed5 100644 --- a/mysql-test/r/innodb_icp.result +++ b/mysql-test/r/innodb_icp.result @@ -816,24 +816,24 @@ KEY (c1) ); INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); flush status; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 +Handler_icp_attempts 0 +Handler_icp_match 0 SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 DROP TABLE t1; set optimizer_switch=@innodb_icp_tmp; set storage_engine= @save_storage_engine; diff --git a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result index 6908f40e854..9918ad2380d 100644 --- a/mysql-test/r/join_cache.result +++ b/mysql-test/r/join_cache.result @@ -3520,10 +3520,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; 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 t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 20 -Handler_pushed_index_cond_filtered 16 +Handler_icp_attempts 20 +Handler_icp_match 4 set join_cache_level=6; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3537,10 +3537,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; 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 t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 40 -Handler_pushed_index_cond_filtered 32 +Handler_icp_attempts 40 +Handler_icp_match 8 set join_cache_level=7; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3554,10 +3554,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; 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 t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 60 -Handler_pushed_index_cond_filtered 48 +Handler_icp_attempts 60 +Handler_icp_match 12 set join_cache_level=8; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3571,10 +3571,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; 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 t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 80 -Handler_pushed_index_cond_filtered 64 +Handler_icp_attempts 80 +Handler_icp_match 16 drop table t1,t2; set join_cache_level=default; # diff --git a/mysql-test/r/maria_icp.result b/mysql-test/r/maria_icp.result index b9d3ca6c7c0..97b10fe496c 100644 --- a/mysql-test/r/maria_icp.result +++ b/mysql-test/r/maria_icp.result @@ -822,24 +822,24 @@ KEY (c1) ); INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); flush status; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 +Handler_icp_attempts 0 +Handler_icp_match 0 SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 DROP TABLE t1; set storage_engine= @save_storage_engine; set optimizer_switch=@maria_icp_tmp; diff --git a/mysql-test/r/myisam_icp.result b/mysql-test/r/myisam_icp.result index d7442608b59..85a2ad921c6 100644 --- a/mysql-test/r/myisam_icp.result +++ b/mysql-test/r/myisam_icp.result @@ -820,24 +820,24 @@ KEY (c1) ); INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); flush status; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 +Handler_icp_attempts 0 +Handler_icp_match 0 SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 DROP TABLE t1; drop table if exists t0, t1, t1i, t1m; # diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result index e75cabe0e58..b5bae659eed 100644 --- a/mysql-test/r/status.result +++ b/mysql-test/r/status.result @@ -275,9 +275,9 @@ Variable_name Value Handler_commit 0 Handler_delete 0 Handler_discover 0 +Handler_icp_attempts 0 +Handler_icp_match 0 Handler_prepare 0 -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 4 Handler_read_next 0 @@ -312,9 +312,9 @@ Variable_name Value Handler_commit 0 Handler_delete 0 Handler_discover 0 +Handler_icp_attempts 0 +Handler_icp_match 0 Handler_prepare 0 -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 2 Handler_read_next 2 diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result index 175839b2098..be0cfef79dc 100644 --- a/mysql-test/r/status_user.result +++ b/mysql-test/r/status_user.result @@ -100,9 +100,9 @@ Variable_name Value Handler_commit 19 Handler_delete 1 Handler_discover 0 +Handler_icp_attempts 0 +Handler_icp_match 0 Handler_prepare 18 -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 3 Handler_read_next 0 diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test index 6cb8f48bd70..0962f1bf766 100644 --- a/mysql-test/t/join_cache.test +++ b/mysql-test/t/join_cache.test @@ -1533,7 +1533,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; set join_cache_level=6; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1541,7 +1541,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; set join_cache_level=7; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1549,7 +1549,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; set join_cache_level=8; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1557,7 +1557,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; drop table t1,t2; set join_cache_level=default; diff --git a/sql/handler.cc b/sql/handler.cc index 4a8cd77ebc3..04f10586484 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -4569,10 +4569,10 @@ extern "C" enum icp_result handler_index_cond_check(void* h_arg) if (h->end_range && h->compare_key2(h->end_range) > 0) return ICP_OUT_OF_RANGE; - h->increment_statistics(&SSV::ha_pushed_index_cond_checks); + h->increment_statistics(&SSV::ha_icp_attempts); if ((res= h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH) == - ICP_NO_MATCH) - h->increment_statistics(&SSV::ha_pushed_index_cond_filtered); + ICP_MATCH) + h->increment_statistics(&SSV::ha_icp_match); return res; } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 70dba70eb15..147c2e80be3 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8107,9 +8107,9 @@ SHOW_VAR status_vars[]= { {"Handler_mrr_extra_rowid_sorts", (char*) offsetof(STATUS_VAR, ha_mrr_extra_rowid_sorts), SHOW_LONG_STATUS}, {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_multi_range_read_init_count), SHOW_LONG_STATUS}, #endif + {"Handler_icp_attempts ", (char*) offsetof(STATUS_VAR, ha_icp_attempts), SHOW_LONG_STATUS}, + {"Handler_icp_match", (char*) offsetof(STATUS_VAR, ha_icp_match), SHOW_LONG_STATUS}, {"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS}, - {"Handler_pushed_index_cond_checks",(char*) offsetof(STATUS_VAR, ha_pushed_index_cond_checks), SHOW_LONG_STATUS}, - {"Handler_pushed_index_cond_filtered",(char*) offsetof(STATUS_VAR, ha_pushed_index_cond_filtered), SHOW_LONG_STATUS}, {"Handler_read_first", (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS}, {"Handler_read_key", (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS}, {"Handler_read_next", (char*) offsetof(STATUS_VAR, ha_read_next_count), SHOW_LONG_STATUS}, diff --git a/sql/sql_class.h b/sql/sql_class.h index c04af55a127..3b94270ae08 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -588,8 +588,8 @@ typedef struct system_status_var ulong ha_tmp_update_count; ulong ha_tmp_write_count; ulong ha_prepare_count; - ulong ha_pushed_index_cond_checks; - ulong ha_pushed_index_cond_filtered; + ulong ha_icp_attempts; + ulong ha_icp_match; ulong ha_discover_count; ulong ha_savepoint_count; ulong ha_savepoint_rollback_count; diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 15b5efbfacb..a960c63e782 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -4026,9 +4026,9 @@ bool bka_skip_index_tuple(range_seq_t rseq, range_id_t range_info) JOIN_CACHE_BKA *cache= (JOIN_CACHE_BKA *) rseq; THD *thd= cache->thd(); bool res; - status_var_increment(thd->status_var.ha_pushed_index_cond_checks); - if ((res= cache->skip_index_tuple(range_info))) - status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); + status_var_increment(thd->status_var.ha_icp_attempts); + if (!(res= cache->skip_index_tuple(range_info))) + status_var_increment(thd->status_var.ha_icp_match); DBUG_RETURN(res); } @@ -4505,9 +4505,9 @@ bool bkah_skip_index_tuple(range_seq_t rseq, range_id_t range_info) JOIN_CACHE_BKAH *cache= (JOIN_CACHE_BKAH *) rseq; THD *thd= cache->thd(); bool res; - status_var_increment(thd->status_var.ha_pushed_index_cond_checks); - if ((res= cache->skip_index_tuple(range_info))) - status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); + status_var_increment(thd->status_var.ha_icp_attempts); + if (!(res= cache->skip_index_tuple(range_info))) + status_var_increment(thd->status_var.ha_icp_match); DBUG_RETURN(res); } From f2db5ef4ba128c86d02e6571f9aba907b8ea64c3 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Feb 2012 11:44:53 +0100 Subject: [PATCH 35/45] Fix MWL#192 build error: Remove SSL special case for embedded server. VIO has SSL in embedded server anyway, so we do not win anything by excluding it. This was actually already done in this changeset: revision-id: kostja@sun.com-20100413150445-8x23keoxdiufgq76 "... Also, he removed the (probable) bug of embedded server never using SSL-dependent functions..." But was apparenly lost by a mis-merge of WL#5030. --- include/my_global.h | 1 - include/violite.h | 2 -- sql-common/client.c | 4 ++-- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index 26cba5b4ed7..22b4f822ab9 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -1532,7 +1532,6 @@ static inline double rint(double x) /* Things we don't need in the embedded version of MySQL */ /* TODO HF add #undef HAVE_VIO if we don't want client in embedded library */ -#undef HAVE_OPENSSL #undef HAVE_SMEM /* No shared memory */ #endif /* EMBEDDED_LIBRARY */ diff --git a/include/violite.h b/include/violite.h index f177bcd4f82..19c9d8bfe54 100644 --- a/include/violite.h +++ b/include/violite.h @@ -120,7 +120,6 @@ typedef my_socket YASSL_SOCKET_T; #include #include -#ifndef EMBEDDED_LIBRARY enum enum_ssl_init_error { SSL_INITERR_NOERROR= 0, SSL_INITERR_CERT, SSL_INITERR_KEY, @@ -146,7 +145,6 @@ struct st_VioSSLFd const char *ca_file,const char *ca_path, const char *cipher, enum enum_ssl_init_error* error); void free_vio_ssl_acceptor_fd(struct st_VioSSLFd *fd); -#endif /* ! EMBEDDED_LIBRARY */ #endif /* HAVE_OPENSSL */ void vio_end(void); diff --git a/sql-common/client.c b/sql-common/client.c index 2904ffa7b64..f79d7de0c73 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1864,7 +1864,7 @@ mysql_get_ssl_cipher(MYSQL *mysql __attribute__((unused))) */ -#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) +#if defined(HAVE_OPENSSL) static int ssl_verify_server_cert(Vio *vio, const char* server_hostname, const char **errptr) { @@ -1922,7 +1922,7 @@ static int ssl_verify_server_cert(Vio *vio, const char* server_hostname, const c DBUG_RETURN(1); } -#endif /* HAVE_OPENSSL && !EMBEDDED_LIBRARY */ +#endif /* HAVE_OPENSSL */ /* From 59b2bb9aca0fb037ab4c770a8fd684a3d4a40587 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 22 Feb 2012 16:48:29 +0400 Subject: [PATCH 36/45] Added back MRR counters. The new names are: Handler_mrr_init, Handler_mrr_key_refills, Handler_mrr_rowid_refills. --- mysql-test/r/myisam_mrr.result | 15 +++++++++++++++ mysql-test/r/status.result | 8 +++++++- mysql-test/r/status_user.result | 3 +++ sql/multi_range_read.cc | 12 ++++++++---- sql/mysqld.cc | 11 +++++------ sql/sql_class.h | 6 +++--- 6 files changed, 41 insertions(+), 14 deletions(-) diff --git a/mysql-test/r/myisam_mrr.result b/mysql-test/r/myisam_mrr.result index c2f382eb9e6..0ea75c8aebb 100644 --- a/mysql-test/r/myisam_mrr.result +++ b/mysql-test/r/myisam_mrr.result @@ -563,6 +563,9 @@ drop table t1; flush status; show status like 'Handler_mrr%'; Variable_name Value +Handler_mrr_init 0 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 create table t0 (a int); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t1 (a int, b int, filler char(200), key(a)); @@ -578,6 +581,9 @@ sum(b) 1230 show status like 'handler_mrr%'; Variable_name Value +Handler_mrr_init 1 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 set @mrr_buffer_size_save= @@mrr_buffer_size; set mrr_buffer_size=128; explain select sum(b) from t1 where a < 1600; @@ -590,6 +596,9 @@ sum(b) 196800 show status like 'handler_mrr%'; Variable_name Value +Handler_mrr_init 1 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 1 set @@mrr_buffer_size= @mrr_buffer_size_save; #Now, let's check BKA: set @join_cache_level_save= @@join_cache_level; @@ -605,6 +614,9 @@ sum(t1.b) 1230 show status like 'handler_mrr%'; Variable_name Value +Handler_mrr_init 1 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 set join_buffer_size=10; explain select sum(t1.b) from t0,t1 where t0.a=t1.a; id select_type table type possible_keys key key_len ref rows Extra @@ -616,6 +628,9 @@ sum(t1.b) 1230 show status like 'handler_mrr%'; Variable_name Value +Handler_mrr_init 1or2 +Handler_mrr_key_refills 1or2 +Handler_mrr_rowid_refills 1or2 set join_cache_level= @join_cache_level_save; set join_buffer_size= @join_buffer_size_save; drop table t0, t1; diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result index b5bae659eed..d3e1d26cbbd 100644 --- a/mysql-test/r/status.result +++ b/mysql-test/r/status.result @@ -277,6 +277,9 @@ Handler_delete 0 Handler_discover 0 Handler_icp_attempts 0 Handler_icp_match 0 +Handler_mrr_init 0 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 Handler_prepare 0 Handler_read_first 0 Handler_read_key 4 @@ -299,7 +302,7 @@ Created_tmp_files 0 Created_tmp_tables 2 Handler_tmp_update 2 Handler_tmp_write 7 -Rows_tmp_read 37 +Rows_tmp_read 40 drop table t1; CREATE TABLE t1 (i int(11) DEFAULT NULL, KEY i (i) ) ENGINE=MyISAM; insert into t1 values (1),(2),(3),(4),(5); @@ -314,6 +317,9 @@ Handler_delete 0 Handler_discover 0 Handler_icp_attempts 0 Handler_icp_match 0 +Handler_mrr_init 0 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 Handler_prepare 0 Handler_read_first 0 Handler_read_key 2 diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result index be0cfef79dc..b2d4b6f761f 100644 --- a/mysql-test/r/status_user.result +++ b/mysql-test/r/status_user.result @@ -102,6 +102,9 @@ Handler_delete 1 Handler_discover 0 Handler_icp_attempts 0 Handler_icp_match 0 +Handler_mrr_init 0 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 Handler_prepare 18 Handler_read_first 0 Handler_read_key 3 diff --git a/sql/multi_range_read.cc b/sql/multi_range_read.cc index 6ecc64207de..e86c9ca251c 100644 --- a/sql/multi_range_read.cc +++ b/sql/multi_range_read.cc @@ -510,7 +510,7 @@ int Mrr_ordered_index_reader::refill_buffer(bool initial) { /* This is a non-initial buffer fill and we've got a non-empty buffer */ THD *thd= current_thd; - status_var_increment(thd->status_var.ha_mrr_extra_key_sorts); + status_var_increment(thd->status_var.ha_mrr_key_refills_count); } key_buffer->sort((key_buffer->type() == Lifo_buffer::FORWARD)? @@ -610,7 +610,7 @@ int Mrr_ordered_rndpos_reader::refill_buffer(bool initial) { /* Ok, this was a successful buffer refill operation */ THD *thd= current_thd; - status_var_increment(thd->status_var.ha_mrr_extra_rowid_sorts); + status_var_increment(thd->status_var.ha_mrr_rowid_refills_count); } DBUG_RETURN(res); @@ -845,8 +845,6 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, strategy= disk_strategy= &reader_factory.ordered_rndpos_reader; } - status_var_increment(thd->status_var.ha_multi_range_read_init_count); - full_buf= buf->buffer; full_buf_end= buf->buffer_end; @@ -936,6 +934,12 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, goto error; } } + + /* + At this point, we're sure that we're running a native MRR scan (i.e. we + didnt fall back to default implementation for some reason). + */ + status_var_increment(thd->status_var.ha_mrr_init_count); res= strategy->refill_buffer(TRUE); if (res) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 147c2e80be3..484bfd168c7 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8101,12 +8101,11 @@ SHOW_VAR status_vars[]= { {"Handler_commit", (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS}, {"Handler_delete", (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS}, {"Handler_discover", (char*) offsetof(STATUS_VAR, ha_discover_count), SHOW_LONG_STATUS}, -#if 0 - /* Made 3 counters below temporarily invisible until we agree upon their names */ - {"Handler_mrr_extra_key_sorts", (char*) offsetof(STATUS_VAR, ha_mrr_extra_key_sorts), SHOW_LONG_STATUS}, - {"Handler_mrr_extra_rowid_sorts", (char*) offsetof(STATUS_VAR, ha_mrr_extra_rowid_sorts), SHOW_LONG_STATUS}, - {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_multi_range_read_init_count), SHOW_LONG_STATUS}, -#endif + + {"Handler_mrr_key_refills", (char*) offsetof(STATUS_VAR, ha_mrr_key_refills_count), SHOW_LONG_STATUS}, + {"Handler_mrr_rowid_refills", (char*) offsetof(STATUS_VAR, ha_mrr_rowid_refills_count), SHOW_LONG_STATUS}, + {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_mrr_init_count), SHOW_LONG_STATUS}, + {"Handler_icp_attempts ", (char*) offsetof(STATUS_VAR, ha_icp_attempts), SHOW_LONG_STATUS}, {"Handler_icp_match", (char*) offsetof(STATUS_VAR, ha_icp_match), SHOW_LONG_STATUS}, {"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS}, diff --git a/sql/sql_class.h b/sql/sql_class.h index 3b94270ae08..c5f500a6b18 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -577,9 +577,9 @@ typedef struct system_status_var calls made by range access. The intent is to count only calls made by BatchedKeyAccess. */ - ulong ha_multi_range_read_init_count; - ulong ha_mrr_extra_key_sorts; - ulong ha_mrr_extra_rowid_sorts; + ulong ha_mrr_init_count; + ulong ha_mrr_key_refills_count; + ulong ha_mrr_rowid_refills_count; ulong ha_rollback_count; ulong ha_update_count; From 917455911f1ec995e40ac8b47f3c78ad503e7a95 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 22 Feb 2012 17:11:33 +0400 Subject: [PATCH 37/45] Sort counters by their names (otherwise, the order of SHOW STATUS output is sometimes sorted and sometimes not) --- sql/mysqld.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 484bfd168c7..aa3942521ed 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8102,12 +8102,13 @@ SHOW_VAR status_vars[]= { {"Handler_delete", (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS}, {"Handler_discover", (char*) offsetof(STATUS_VAR, ha_discover_count), SHOW_LONG_STATUS}, - {"Handler_mrr_key_refills", (char*) offsetof(STATUS_VAR, ha_mrr_key_refills_count), SHOW_LONG_STATUS}, - {"Handler_mrr_rowid_refills", (char*) offsetof(STATUS_VAR, ha_mrr_rowid_refills_count), SHOW_LONG_STATUS}, - {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_mrr_init_count), SHOW_LONG_STATUS}, - {"Handler_icp_attempts ", (char*) offsetof(STATUS_VAR, ha_icp_attempts), SHOW_LONG_STATUS}, {"Handler_icp_match", (char*) offsetof(STATUS_VAR, ha_icp_match), SHOW_LONG_STATUS}, + + {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_mrr_init_count), SHOW_LONG_STATUS}, + {"Handler_mrr_key_refills", (char*) offsetof(STATUS_VAR, ha_mrr_key_refills_count), SHOW_LONG_STATUS}, + {"Handler_mrr_rowid_refills", (char*) offsetof(STATUS_VAR, ha_mrr_rowid_refills_count), SHOW_LONG_STATUS}, + {"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS}, {"Handler_read_first", (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS}, {"Handler_read_key", (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS}, From 567d871ff0c9cbdcaa4f9daa6810760edc901e14 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 22 Feb 2012 17:38:24 +0400 Subject: [PATCH 38/45] Don't run test for BUG#933412 with embedded server, as it requires concurrent query execution which mtr --embedded does not support --- mysql-test/r/myisam_icp.result | 15 --- mysql-test/r/myisam_icp_notembedded.result | 19 +++ mysql-test/t/myisam_icp.test | 128 ------------------- mysql-test/t/myisam_icp_notembedded.test | 139 +++++++++++++++++++++ 4 files changed, 158 insertions(+), 143 deletions(-) create mode 100644 mysql-test/r/myisam_icp_notembedded.result create mode 100644 mysql-test/t/myisam_icp_notembedded.test diff --git a/mysql-test/r/myisam_icp.result b/mysql-test/r/myisam_icp.result index 85a2ad921c6..188347c3324 100644 --- a/mysql-test/r/myisam_icp.result +++ b/mysql-test/r/myisam_icp.result @@ -909,19 +909,4 @@ c NULL NULL c NULL NULL SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2,t3,t4; -# -# BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN -# -CREATE TABLE t1 ( -b INT, -c VARCHAR(1) NOT NULL, -d DATETIME, -KEY (c, b) -) ENGINE=MyISAM; -# INSERT some data -CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; -INSERT INTO t2 VALUES -(7),(3),(7),(3); -# Now run a number of ICP queries while trying to kill them -DROP TABLE t1,t2; set optimizer_switch=@myisam_icp_tmp; diff --git a/mysql-test/r/myisam_icp_notembedded.result b/mysql-test/r/myisam_icp_notembedded.result new file mode 100644 index 00000000000..d965cbd980d --- /dev/null +++ b/mysql-test/r/myisam_icp_notembedded.result @@ -0,0 +1,19 @@ +drop table if exists t1,t2; +set @myisam_icp_notembedded_tmp=@@optimizer_switch; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +# +# BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN +# +CREATE TABLE t1 ( +b INT, +c VARCHAR(1) NOT NULL, +d DATETIME, +KEY (c, b) +) ENGINE=MyISAM; +# INSERT some data +CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES +(7),(3),(7),(3); +# Now run a number of ICP queries while trying to kill them +DROP TABLE t1,t2; +set optimizer_switch=@myisam_icp_notembedded_tmp; diff --git a/mysql-test/t/myisam_icp.test b/mysql-test/t/myisam_icp.test index 39a22d00a1a..5bee6e5acaa 100644 --- a/mysql-test/t/myisam_icp.test +++ b/mysql-test/t/myisam_icp.test @@ -262,133 +262,5 @@ SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2,t3,t4; ---echo # ---echo # BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN ---echo # -CREATE TABLE t1 ( - b INT, - c VARCHAR(1) NOT NULL, - d DATETIME, - KEY (c, b) -) ENGINE=MyISAM; ---echo # INSERT some data ---disable_query_log -INSERT INTO t1 ( b, d, c ) VALUES -(4,'2005-01-08 00:00:00','f'), -(1,'2004-05-20 10:45:51','c'),(2,'2006-08-11 21:33:49','e'), -(5,'2003-05-19 00:20:40','a'),(3,'2005-01-03 06:18:39','a'), -(7,'2008-11-25 18:18:14','b'),(6,'2008-11-09 15:53:46','b'), -(9,'2003-03-01 03:40:36','c'),(8,'2003-09-25 23:14:09','d'), -(0,'2007-01-17 09:18:31','f'),(9,'2008-09-08 09:52:24','c'), -(2,'2008-03-10 00:00:00','a'),(0,'2003-03-14 09:31:07','c'), -(4,'2005-04-25 00:00:00','h'),(6,'2001-08-01 05:55:55','e'), -(3,'2005-04-09 01:22:48','f'),(7,'2009-11-12 13:27:22','r'), -(0,'2009-03-28 05:05:28','h'),(15,'2005-05-16 04:35:41','f'), -(7,'2006-03-26 05:19:58','c'),(9,'2002-10-06 02:17:00','g'), -(4,'2007-01-28 03:28:20','b'),(1,'2009-04-22 10:16:40','c'), -(2,'2003-01-01 19:39:00','f'),(0,'2008-05-03 19:16:29','t'), -(2,'2005-01-28 00:00:00','j'),(8,'2004-01-10 00:00:00','w'), -(8,'2000-06-13 21:56:37','a'),(5,'2001-03-21 19:24:49','o'), -(99,'2003-12-20 21:29:06','f'),(0,'1900-01-01 00:00:00','w'), -(7,'2000-12-19 00:00:00','c'),(0,'2000-03-03 06:10:19','l'), -(3,'2000-08-11 00:00:00','q'),(0,'2007-05-25 03:46:41','e'), -(241,'2005-05-17 00:00:00','j'),(4,'2005-11-02 00:44:06','r'), -(43,'2001-07-11 00:00:00','a'),(1,'2008-12-01 18:30:27','z'), -(4,'2004-10-25 00:00:00','i'),(5,'2000-04-08 12:12:01','c'), -(0,'1900-01-01 00:00:00','f'),(9,'2002-05-13 22:47:02','p'), -(1,'2008-10-09 15:39:40','d'),(3,'2004-06-24 00:00:00','d'), -(0,'2008-03-06 00:00:00','r'),(9,'2007-04-16 18:40:03','i'), -(3,'2008-03-16 19:49:37','t'),(7,'2003-07-15 08:11:21','d'), -(8,'2005-02-11 00:04:53','r'),(0,'2002-09-21 00:00:00','y'), -(3,'2004-11-03 00:37:21','z'),(6,'2007-10-18 00:00:00','e'), -(6,'2007-01-21 10:42:56','o'),(5,'2000-03-26 21:21:04','b'), -(9,'2001-03-15 08:08:21','e'),(1,'2001-10-16 12:56:59','a'), -(6,'2004-05-01 23:45:55','o'),(4,'2000-03-04 00:00:00','f'), -(9,'2002-12-03 16:48:28','e'),(8,'2003-01-09 00:36:07','m'), -(1,'2006-06-22 04:32:41','s'),(8,'2008-09-20 05:01:48','q'), -(4,'2006-06-02 22:15:31','g'),(2,'2002-05-14 07:07:42','e'), -(7,'2005-06-05 01:30:42','r'),(127,'2004-05-11 01:56:48','a'), -(210,'2003-11-05 00:41:34','z'),(5,'1900-01-01 00:00:00','h'), -(1,'2006-04-16 00:00:00','f'),(7,'2000-12-17 00:00:00','x'), -(8,'2009-05-09 20:43:07','b'),(175,'2008-11-26 16:33:09','p'), -(0,'2002-05-09 21:18:44','v'),(8,'2002-06-01 11:32:25','k'), -(1,'2008-11-09 23:56:00','a'),(0,'2008-01-08 10:18:46','c'), -(2,'2005-04-16 00:00:00','o'),(5,'2002-08-25 00:00:00','b'), -(64,'2005-12-05 21:51:52','b'),(4,'2005-08-10 00:00:00','i'), -(6,'2006-03-23 00:00:00','d'),(9,'2007-01-27 00:00:00','i'), -(8,'2008-08-16 00:00:00','a'),(7,'2003-01-16 12:13:18','k'), -(0,'2003-06-22 00:00:00','v'),(5,'2008-06-20 05:43:56','u'), -(8,'2004-09-23 18:57:17','e'),(1,'2000-12-26 00:00:00','y'), -(4,'2009-06-01 13:00:28','e'),(1,'2009-11-18 06:28:48','m'), -(0,'2004-06-12 10:01:10','e'),(2,'2005-10-16 01:48:55','e'), -(5,'2001-12-23 09:50:21','l'),(6,'1900-01-01 00:00:00','a'), -(1,'2001-10-28 00:00:00','d'),(1,'2008-07-12 23:30:19','s'), -(0,'2002-10-11 16:51:16','r'),(4,'2007-09-18 06:27:10','x'), -(1,'2007-02-21 12:28:14','e'),(6,'2001-09-16 00:00:00','f'), -(0,'2007-09-20 02:25:45','c'),(0,'2006-08-07 03:25:56','j'), -(8,'2006-12-04 20:20:32','t'),(7,'2007-09-05 10:13:10','i'), -(9,'2006-04-12 17:59:57','t'),(2,'2009-04-28 00:06:09','b'), -(8,'2000-01-07 00:00:00','b'),(7,'2000-03-25 10:04:41','k'), -(4,'2000-07-10 00:44:55','w'),(9,'2007-09-22 14:26:26','j'), -(9,'2003-09-11 22:41:17','a'),(0,'2004-06-07 13:52:32','c'), -(8,'2008-10-09 00:00:00','p'),(1,'2007-04-01 00:00:00','c'), -(9,'2000-12-05 00:00:00','i'),(3,'1900-01-01 00:00:00','a'), -(3,'2005-12-24 21:50:54','e'),(8,'2009-07-21 19:34:55','n'), -(9,'2005-11-13 17:57:56','d'),(7,'2004-10-07 06:41:39','l'), -(1,'2004-11-20 08:05:08','u'),(3,'2005-05-25 00:00:00','r'), -(1,'2006-09-02 14:16:41','u'),(8,'2006-01-07 00:00:00','a'), -(9,'2003-04-05 00:54:20','w'),(2,'2003-12-22 00:00:00','a'), -(9,'2006-04-16 17:31:40','e'),(6,'2005-02-10 14:22:46','e'), -(7,'2004-04-27 05:54:52','p'),(1,'2005-12-07 00:00:00','t'), -(5,'2004-04-03 20:56:28','d'),(4,'2000-09-07 05:17:16','h'), -(2,'2004-08-04 16:10:42','i'),(1,'2007-03-04 00:00:00','b'), -(9,'1900-01-01 00:00:00','d'),(1,'2000-05-12 23:02:50','m'), -(2,'1900-01-01 00:00:00','l'),(1,'1900-01-01 00:00:00','k'), -(4,'2000-07-14 01:25:18','d'),(5,'2009-08-21 00:00:00','w'), -(6,'2009-05-25 13:33:54','f'),(7,'2006-06-13 00:00:00','e'), -(8,'1900-01-01 00:00:00','a'),(6,'2004-02-24 00:00:00','j'), -(0,'2003-05-21 07:03:46','k'),(9,'1900-01-01 00:00:00','e'), -(2,'1900-01-01 00:00:00','y'),(2,'2000-12-22 00:00:00','e'), -(3,'2003-09-26 00:00:00','f'),(2,'2001-01-13 08:20:19','h'), -(9,'2008-09-23 20:03:28','n'),(5,'2007-03-20 02:41:38','s'), -(1,'2009-02-14 10:27:18','a'),(0,'2001-08-10 17:44:05','s'), -(3,'2008-01-20 12:49:54','v'),(1,'2001-05-05 09:09:59','r'); ---enable_query_log -CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; -INSERT INTO t2 VALUES - (7),(3),(7),(3); - -# 'con2' will be the connection that will run all the KILLable statements ---connect (con2,127.0.0.1,root,,test) - ---let $run = 300 ---let $con_id = `SELECT CONNECTION_ID()` - ---echo # Now run a number of ICP queries while trying to kill them ---disable_query_log ---disable_result_log -while ($run) -{ - --send - SELECT * FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2 - ON alias2.c = alias1.c - WHERE alias2.b >= 9; - - --connect (con1,127.0.0.1,root,,test) - --eval KILL QUERY $con_id - --disconnect con1 - - --dec $run - - --connection con2 - --error 0,ER_QUERY_INTERRUPTED - --reap -} ---enable_result_log ---enable_query_log ---disconnect con2 ---connection default -DROP TABLE t1,t2; - set optimizer_switch=@myisam_icp_tmp; diff --git a/mysql-test/t/myisam_icp_notembedded.test b/mysql-test/t/myisam_icp_notembedded.test new file mode 100644 index 00000000000..139a9edf648 --- /dev/null +++ b/mysql-test/t/myisam_icp_notembedded.test @@ -0,0 +1,139 @@ +-- source include/not_embedded.inc + +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + +set @myisam_icp_notembedded_tmp=@@optimizer_switch; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; + +--echo # +--echo # BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN +--echo # +CREATE TABLE t1 ( + b INT, + c VARCHAR(1) NOT NULL, + d DATETIME, + KEY (c, b) +) ENGINE=MyISAM; +--echo # INSERT some data +--disable_query_log +INSERT INTO t1 ( b, d, c ) VALUES +(4,'2005-01-08 00:00:00','f'), +(1,'2004-05-20 10:45:51','c'),(2,'2006-08-11 21:33:49','e'), +(5,'2003-05-19 00:20:40','a'),(3,'2005-01-03 06:18:39','a'), +(7,'2008-11-25 18:18:14','b'),(6,'2008-11-09 15:53:46','b'), +(9,'2003-03-01 03:40:36','c'),(8,'2003-09-25 23:14:09','d'), +(0,'2007-01-17 09:18:31','f'),(9,'2008-09-08 09:52:24','c'), +(2,'2008-03-10 00:00:00','a'),(0,'2003-03-14 09:31:07','c'), +(4,'2005-04-25 00:00:00','h'),(6,'2001-08-01 05:55:55','e'), +(3,'2005-04-09 01:22:48','f'),(7,'2009-11-12 13:27:22','r'), +(0,'2009-03-28 05:05:28','h'),(15,'2005-05-16 04:35:41','f'), +(7,'2006-03-26 05:19:58','c'),(9,'2002-10-06 02:17:00','g'), +(4,'2007-01-28 03:28:20','b'),(1,'2009-04-22 10:16:40','c'), +(2,'2003-01-01 19:39:00','f'),(0,'2008-05-03 19:16:29','t'), +(2,'2005-01-28 00:00:00','j'),(8,'2004-01-10 00:00:00','w'), +(8,'2000-06-13 21:56:37','a'),(5,'2001-03-21 19:24:49','o'), +(99,'2003-12-20 21:29:06','f'),(0,'1900-01-01 00:00:00','w'), +(7,'2000-12-19 00:00:00','c'),(0,'2000-03-03 06:10:19','l'), +(3,'2000-08-11 00:00:00','q'),(0,'2007-05-25 03:46:41','e'), +(241,'2005-05-17 00:00:00','j'),(4,'2005-11-02 00:44:06','r'), +(43,'2001-07-11 00:00:00','a'),(1,'2008-12-01 18:30:27','z'), +(4,'2004-10-25 00:00:00','i'),(5,'2000-04-08 12:12:01','c'), +(0,'1900-01-01 00:00:00','f'),(9,'2002-05-13 22:47:02','p'), +(1,'2008-10-09 15:39:40','d'),(3,'2004-06-24 00:00:00','d'), +(0,'2008-03-06 00:00:00','r'),(9,'2007-04-16 18:40:03','i'), +(3,'2008-03-16 19:49:37','t'),(7,'2003-07-15 08:11:21','d'), +(8,'2005-02-11 00:04:53','r'),(0,'2002-09-21 00:00:00','y'), +(3,'2004-11-03 00:37:21','z'),(6,'2007-10-18 00:00:00','e'), +(6,'2007-01-21 10:42:56','o'),(5,'2000-03-26 21:21:04','b'), +(9,'2001-03-15 08:08:21','e'),(1,'2001-10-16 12:56:59','a'), +(6,'2004-05-01 23:45:55','o'),(4,'2000-03-04 00:00:00','f'), +(9,'2002-12-03 16:48:28','e'),(8,'2003-01-09 00:36:07','m'), +(1,'2006-06-22 04:32:41','s'),(8,'2008-09-20 05:01:48','q'), +(4,'2006-06-02 22:15:31','g'),(2,'2002-05-14 07:07:42','e'), +(7,'2005-06-05 01:30:42','r'),(127,'2004-05-11 01:56:48','a'), +(210,'2003-11-05 00:41:34','z'),(5,'1900-01-01 00:00:00','h'), +(1,'2006-04-16 00:00:00','f'),(7,'2000-12-17 00:00:00','x'), +(8,'2009-05-09 20:43:07','b'),(175,'2008-11-26 16:33:09','p'), +(0,'2002-05-09 21:18:44','v'),(8,'2002-06-01 11:32:25','k'), +(1,'2008-11-09 23:56:00','a'),(0,'2008-01-08 10:18:46','c'), +(2,'2005-04-16 00:00:00','o'),(5,'2002-08-25 00:00:00','b'), +(64,'2005-12-05 21:51:52','b'),(4,'2005-08-10 00:00:00','i'), +(6,'2006-03-23 00:00:00','d'),(9,'2007-01-27 00:00:00','i'), +(8,'2008-08-16 00:00:00','a'),(7,'2003-01-16 12:13:18','k'), +(0,'2003-06-22 00:00:00','v'),(5,'2008-06-20 05:43:56','u'), +(8,'2004-09-23 18:57:17','e'),(1,'2000-12-26 00:00:00','y'), +(4,'2009-06-01 13:00:28','e'),(1,'2009-11-18 06:28:48','m'), +(0,'2004-06-12 10:01:10','e'),(2,'2005-10-16 01:48:55','e'), +(5,'2001-12-23 09:50:21','l'),(6,'1900-01-01 00:00:00','a'), +(1,'2001-10-28 00:00:00','d'),(1,'2008-07-12 23:30:19','s'), +(0,'2002-10-11 16:51:16','r'),(4,'2007-09-18 06:27:10','x'), +(1,'2007-02-21 12:28:14','e'),(6,'2001-09-16 00:00:00','f'), +(0,'2007-09-20 02:25:45','c'),(0,'2006-08-07 03:25:56','j'), +(8,'2006-12-04 20:20:32','t'),(7,'2007-09-05 10:13:10','i'), +(9,'2006-04-12 17:59:57','t'),(2,'2009-04-28 00:06:09','b'), +(8,'2000-01-07 00:00:00','b'),(7,'2000-03-25 10:04:41','k'), +(4,'2000-07-10 00:44:55','w'),(9,'2007-09-22 14:26:26','j'), +(9,'2003-09-11 22:41:17','a'),(0,'2004-06-07 13:52:32','c'), +(8,'2008-10-09 00:00:00','p'),(1,'2007-04-01 00:00:00','c'), +(9,'2000-12-05 00:00:00','i'),(3,'1900-01-01 00:00:00','a'), +(3,'2005-12-24 21:50:54','e'),(8,'2009-07-21 19:34:55','n'), +(9,'2005-11-13 17:57:56','d'),(7,'2004-10-07 06:41:39','l'), +(1,'2004-11-20 08:05:08','u'),(3,'2005-05-25 00:00:00','r'), +(1,'2006-09-02 14:16:41','u'),(8,'2006-01-07 00:00:00','a'), +(9,'2003-04-05 00:54:20','w'),(2,'2003-12-22 00:00:00','a'), +(9,'2006-04-16 17:31:40','e'),(6,'2005-02-10 14:22:46','e'), +(7,'2004-04-27 05:54:52','p'),(1,'2005-12-07 00:00:00','t'), +(5,'2004-04-03 20:56:28','d'),(4,'2000-09-07 05:17:16','h'), +(2,'2004-08-04 16:10:42','i'),(1,'2007-03-04 00:00:00','b'), +(9,'1900-01-01 00:00:00','d'),(1,'2000-05-12 23:02:50','m'), +(2,'1900-01-01 00:00:00','l'),(1,'1900-01-01 00:00:00','k'), +(4,'2000-07-14 01:25:18','d'),(5,'2009-08-21 00:00:00','w'), +(6,'2009-05-25 13:33:54','f'),(7,'2006-06-13 00:00:00','e'), +(8,'1900-01-01 00:00:00','a'),(6,'2004-02-24 00:00:00','j'), +(0,'2003-05-21 07:03:46','k'),(9,'1900-01-01 00:00:00','e'), +(2,'1900-01-01 00:00:00','y'),(2,'2000-12-22 00:00:00','e'), +(3,'2003-09-26 00:00:00','f'),(2,'2001-01-13 08:20:19','h'), +(9,'2008-09-23 20:03:28','n'),(5,'2007-03-20 02:41:38','s'), +(1,'2009-02-14 10:27:18','a'),(0,'2001-08-10 17:44:05','s'), +(3,'2008-01-20 12:49:54','v'),(1,'2001-05-05 09:09:59','r'); +--enable_query_log +CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES + (7),(3),(7),(3); + +# 'con2' will be the connection that will run all the KILLable statements +--connect (con2,127.0.0.1,root,,test) + +--let $run = 300 +--let $con_id = `SELECT CONNECTION_ID()` + +--echo # Now run a number of ICP queries while trying to kill them +--disable_query_log +--disable_result_log +while ($run) +{ + --send + SELECT * FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2 + ON alias2.c = alias1.c + WHERE alias2.b >= 9; + + --connect (con1,127.0.0.1,root,,test) + --eval KILL QUERY $con_id + --disconnect con1 + + --dec $run + + --connection con2 + --error 0,ER_QUERY_INTERRUPTED + --reap +} +--enable_result_log +--enable_query_log +--disconnect con2 +--connection default +DROP TABLE t1,t2; + +set optimizer_switch=@myisam_icp_notembedded_tmp; + From db39910f080534159ce8c7d55fa458365de7c3f3 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 23 Feb 2012 15:31:24 +0100 Subject: [PATCH 39/45] disable safemalloc for valgrind builds. always try to use valgrind headers in debug builds. define HAVE_valgrind for --with-valgrind fix valgrind check in my_valgrind.h --- BUILD/SETUP.sh | 1 - CMakeLists.txt | 2 +- config.h.cmake | 6 +++++- configure.cmake | 9 ++++----- include/my_global.h | 6 ------ include/my_valgrind.h | 2 +- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/BUILD/SETUP.sh b/BUILD/SETUP.sh index 6c45c23587f..c9eb1ebc03f 100755 --- a/BUILD/SETUP.sh +++ b/BUILD/SETUP.sh @@ -148,7 +148,6 @@ fi # Override -DFORCE_INIT_OF_VARS from debug_cflags. It enables the macro # LINT_INIT(), which is only useful for silencing spurious warnings # of static analysis tools. We want LINT_INIT() to be a no-op in Valgrind. -valgrind_flags="-DHAVE_valgrind -DHAVE_purify -USAFEMALLOC" valgrind_flags="$valgrind_flags -UFORCE_INIT_OF_VARS -Wno-uninitialized" valgrind_flags="$valgrind_flags -DMYSQL_SERVER_SUFFIX=-valgrind-max" valgrind_configs="--with-valgrind" diff --git a/CMakeLists.txt b/CMakeLists.txt index 27c43f1328a..4e210a8d87e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,7 +197,7 @@ ENDIF() IF(WITH_SAFEMALLOC MATCHES "ON") ADD_DEFINITIONS( -DSAFEMALLOC ${DUSE_MYSYS_NEW}) -ELSEIF(WITH_SAFEMALLOC MATCHES "AUTO" AND NOT WIN32) +ELSEIF(WITH_SAFEMALLOC MATCHES "AUTO" AND NOT WIN32 AND NOT WITH_VALGRIND) SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC") SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC ${DUSE_MYSYS_NEW}") ENDIF() diff --git a/config.h.cmake b/config.h.cmake index eae3a4ba886..529e1c7ad1d 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -313,7 +313,11 @@ #define USE_MB 1 #define USE_MB_IDENT 1 -#cmakedefine HAVE_VALGRIND +/* this means that valgrind headers and macros are available */ +#cmakedefine HAVE_VALGRIND 1 + +/* this means WITH_VALGRIND - we change some code paths for valgrind */ +#cmakedefine HAVE_valgrind 1 /* Types we may use */ #ifdef __APPLE__ diff --git a/configure.cmake b/configure.cmake index ea000ad69a0..66ee73ddc03 100644 --- a/configure.cmake +++ b/configure.cmake @@ -1024,13 +1024,12 @@ if available and 'smp' configuration otherwise.") MARK_AS_ADVANCED(WITH_ATOMIC_LOCKS MY_ATOMIC_MODE_RWLOCK MY_ATOMIC_MODE_DUMMY) IF(WITH_VALGRIND) - CHECK_INCLUDE_FILES("valgrind/memcheck.h;valgrind/valgrind.h" - HAVE_VALGRIND_HEADERS) - IF(HAVE_VALGRIND_HEADERS) - SET(HAVE_VALGRIND 1) - ENDIF() + SET(HAVE_valgrind 1) ENDIF() +CHECK_INCLUDE_FILES("valgrind/memcheck.h;valgrind/valgrind.h" + HAVE_VALGRIND) + #-------------------------------------------------------------------- # Check for IPv6 support #-------------------------------------------------------------------- diff --git a/include/my_global.h b/include/my_global.h index 26cba5b4ed7..8efd9986670 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -89,12 +89,6 @@ #define IF_WIN(A,B) B #endif -#ifdef HAVE_purify -#define IF_PURIFY(A,B) A -#else -#define IF_PURIFY(A,B) B -#endif - #ifndef EMBEDDED_LIBRARY #ifdef WITH_NDB_BINLOG #define HAVE_NDB_BINLOG 1 diff --git a/include/my_valgrind.h b/include/my_valgrind.h index f82dd35b369..5af3a14cf10 100644 --- a/include/my_valgrind.h +++ b/include/my_valgrind.h @@ -23,7 +23,7 @@ #define IF_VALGRIND(A,B) B #endif -#if defined(HAVE_VALGRIND) && defined(HAVE_VALGRIND_MEMCHECK_H) +#if defined(HAVE_VALGRIND) # include # define MEM_UNDEFINED(a,len) VALGRIND_MAKE_MEM_UNDEFINED(a,len) # define MEM_NOACCESS(a,len) VALGRIND_MAKE_MEM_NOACCESS(a,len) From b8aa31c03d5f69a35109ffae11af0b43d7b9341f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 23 Feb 2012 15:42:21 +0100 Subject: [PATCH 40/45] MWL#192 after-merge fixes. Fix memory leak in one error case in mysqldump. Fix that HAVE_VALGRIND_VALGRIND_H is now HAVE_VALGRIND in 5.5. Fix that @have_ssl should not be set in embedded (introduced when removing #undef HAVE_OPENSSL from my_global.h). --- client/mysqldump.c | 6 +++--- include/my_context.h | 6 +++--- mysys/my_context.c | 14 +++++++------- sql-common/client.c | 2 +- sql/mysqld.cc | 10 +++------- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index b8d74858925..7dc74f7ac0b 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1531,9 +1531,9 @@ static int connect_to_db(char *host, char *user,char *passwd) if (opt_default_auth && *opt_default_auth) mysql_options(&mysql_connection, MYSQL_DEFAULT_AUTH, opt_default_auth); - if (!(mysql= mysql_real_connect(&mysql_connection,host,user,passwd, - NULL,opt_mysql_port,opt_mysql_unix_port, - 0))) + mysql= &mysql_connection; /* So we can mysql_close() it properly */ + if (!mysql_real_connect(&mysql_connection,host,user,passwd, + NULL,opt_mysql_port,opt_mysql_unix_port, 0)) { DB_error(&mysql_connection, "when trying to connect"); DBUG_RETURN(1); diff --git a/include/my_context.h b/include/my_context.h index 14974412075..1e1b7e6a749 100644 --- a/include/my_context.h +++ b/include/my_context.h @@ -60,7 +60,7 @@ struct my_context { ucontext_t base_context; ucontext_t spawned_context; int active; -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND unsigned int valgrind_stack_id; #endif #ifndef DBUG_OFF @@ -77,7 +77,7 @@ struct my_context { uint64_t save[9]; void *stack_top; void *stack_bot; -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND unsigned int valgrind_stack_id; #endif #ifndef DBUG_OFF @@ -94,7 +94,7 @@ struct my_context { uint64_t save[7]; void *stack_top; void *stack_bot; -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND unsigned int valgrind_stack_id; #endif #ifndef DBUG_OFF diff --git a/mysys/my_context.c b/mysys/my_context.c index 0ab486605e0..d2374391a39 100644 --- a/mysys/my_context.c +++ b/mysys/my_context.c @@ -24,7 +24,7 @@ #include "m_string.h" #include "my_context.h" -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND #include #endif @@ -134,7 +134,7 @@ my_context_init(struct my_context *c, size_t stack_size) if (!(c->stack= malloc(stack_size))) return -1; /* Out of memory */ c->stack_size= stack_size; -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND c->valgrind_stack_id= VALGRIND_STACK_REGISTER(c->stack, ((unsigned char *)(c->stack))+stack_size); #endif @@ -146,7 +146,7 @@ my_context_destroy(struct my_context *c) { if (c->stack) { -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif free(c->stack); @@ -384,7 +384,7 @@ my_context_init(struct my_context *c, size_t stack_size) (( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16); bzero(c->stack_top, 16); -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND c->valgrind_stack_id= VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top); #endif @@ -397,7 +397,7 @@ my_context_destroy(struct my_context *c) if (c->stack_bot) { free(c->stack_bot); -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif } @@ -611,7 +611,7 @@ my_context_init(struct my_context *c, size_t stack_size) (( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16); bzero(c->stack_top, 16); -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND c->valgrind_stack_id= VALGRIND_STACK_REGISTER(c->stack_bot, c->stack_top); #endif @@ -624,7 +624,7 @@ my_context_destroy(struct my_context *c) if (c->stack_bot) { free(c->stack_bot); -#ifdef HAVE_VALGRIND_VALGRIND_H +#ifdef HAVE_VALGRIND VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif } diff --git a/sql-common/client.c b/sql-common/client.c index f79d7de0c73..f6084d061b8 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1776,7 +1776,7 @@ mysql_ssl_set(MYSQL *mysql __attribute__((unused)) , const char *cipher __attribute__((unused))) { DBUG_ENTER("mysql_ssl_set"); -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) my_free(mysql->options.ssl_key); my_free(mysql->options.ssl_cert); my_free(mysql->options.ssl_ca); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e5b9a6e6312..4031fdbf911 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3920,8 +3920,7 @@ static void openssl_lock(int mode, openssl_lock_t *lock, const char *file, static void init_ssl() { -#ifdef HAVE_OPENSSL -#ifndef EMBEDDED_LIBRARY +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) if (opt_use_ssl) { enum enum_ssl_init_error error= SSL_INITERR_NOERROR; @@ -3943,12 +3942,9 @@ static void init_ssl() { have_ssl= SHOW_OPTION_DISABLED; } -#else - have_ssl= SHOW_OPTION_DISABLED; -#endif /* ! EMBEDDED_LIBRARY */ if (des_key_file) load_des_key_file(des_key_file); -#endif /* HAVE_OPENSSL */ +#endif /* HAVE_OPENSSL && ! EMBEDDED_LIBRARY */ } @@ -7236,7 +7232,7 @@ static int mysql_init_variables(void) have_profiling = SHOW_OPTION_NO; #endif -#ifdef HAVE_OPENSSL +#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY) have_ssl=SHOW_OPTION_YES; #else have_ssl=SHOW_OPTION_NO; From 2b625ac3e0b2173df18c69df63af00dd03e8c672 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 23 Feb 2012 16:43:35 +0200 Subject: [PATCH 41/45] Fixed lp:933719, "Assertion open_tables == 0 ... " in THD::restore_backup_open_tables_state. This also fixes a (not likely) crashing bug when forcing a thread that was doing a table lock to re-open it's files, for example by creating a trigger. mysys/thr_lock.c: Added more checking to find wrong locks. Removed one, not needed, parameter to thr_lock sql/lock.cc: Fixed mysql_lock_tables() to retry with new sql_lock if lock fails. This was needed as table may be closed and reopened between retry's and then the old sql_lock will point to stale data. sql/mysql_priv.h: Updated prototype sql/sql_base.cc: Ensure that all tables are closed if opening of system table failes; This fixes the assert in THD::restore_backup_open_tables_state sql/sql_handler.cc: Updated variable type --- mysys/thr_lock.c | 41 +++++--- sql/lock.cc | 242 +++++++++++++++++++++++++-------------------- sql/mysql_priv.h | 6 +- sql/sql_base.cc | 11 +-- sql/sql_handler.cc | 2 +- 5 files changed, 176 insertions(+), 126 deletions(-) diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c index 99a498cfdd5..32b38105d1f 100644 --- a/mysys/thr_lock.c +++ b/mysys/thr_lock.c @@ -168,7 +168,8 @@ thr_lock_owner_equal(THR_LOCK_OWNER *rhs, THR_LOCK_OWNER *lhs) static uint found_errors=0; static int check_lock(struct st_lock_list *list, const char* lock_type, - const char *where, my_bool same_owner, my_bool no_cond) + const char *where, my_bool same_owner, my_bool no_cond, + my_bool read_lock) { THR_LOCK_DATA *data,**prev; uint count=0; @@ -181,6 +182,23 @@ static int check_lock(struct st_lock_list *list, const char* lock_type, for (data=list->data; data && count++ < MAX_LOCKS ; data=data->next) { + if (data->type == TL_UNLOCK) + { + fprintf(stderr, + "Warning: Found unlocked lock at %s: %s\n", + lock_type, where); + return 1; + } + if ((read_lock && data->type > TL_READ_NO_INSERT) || + (!read_lock && data->type <= TL_READ_NO_INSERT)) + { + fprintf(stderr, + "Warning: Found %s lock in %s queue at %s: %s\n", + read_lock ? "write" : "read", + read_lock ? "read" : "write", + lock_type, where); + return 1; + } if (data->type != last_lock_type) last_lock_type=TL_IGNORE; if (data->prev != prev) @@ -237,11 +255,14 @@ static void check_locks(THR_LOCK *lock, const char *where, if (found_errors < MAX_FOUND_ERRORS) { - if (check_lock(&lock->write,"write",where,1,1) | - check_lock(&lock->write_wait,"write_wait",where,0,0) | - check_lock(&lock->read,"read",where,0,1) | - check_lock(&lock->read_wait,"read_wait",where,0,0)) + if (check_lock(&lock->write,"write",where,1,1,0) | + check_lock(&lock->write_wait,"write_wait",where,0,0,0) | + check_lock(&lock->read,"read",where,0,1,1) | + check_lock(&lock->read_wait,"read_wait",where,0,0,1)) + { + DBUG_ASSERT(my_assert_on_error == 0); found_errors++; + } if (found_errors < MAX_FOUND_ERRORS) { @@ -592,18 +613,17 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data, static enum enum_thr_lock_result -thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner, - enum thr_lock_type lock_type) +thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner) { THR_LOCK *lock=data->lock; enum enum_thr_lock_result result= THR_LOCK_SUCCESS; struct st_lock_list *wait_queue; THR_LOCK_DATA *lock_owner; + enum thr_lock_type lock_type= data->type; DBUG_ENTER("thr_lock"); data->next=0; data->cond=0; /* safety */ - data->type=lock_type; data->owner= owner; /* Must be reset ! */ data->priority&= ~THR_LOCK_LATE_PRIV; VOID(pthread_mutex_lock(&lock->mutex)); @@ -912,9 +932,7 @@ void thr_unlock(THR_LOCK_DATA *data, uint unlock_flags) if (lock_type == TL_READ_NO_INSERT) lock->read_no_write_count--; data->type=TL_UNLOCK; /* Mark unlocked */ - check_locks(lock,"after releasing lock", lock_type, 1); wake_up_waiters(lock); - check_locks(lock,"end of thr_unlock", lock_type, 1); pthread_mutex_unlock(&lock->mutex); DBUG_VOID_RETURN; } @@ -934,6 +952,7 @@ static void wake_up_waiters(THR_LOCK *lock) enum thr_lock_type lock_type; DBUG_ENTER("wake_up_waiters"); + check_locks(lock, "before waking up waiters", TL_UNLOCK, 1); if (!lock->write.data) /* If no active write locks */ { data=lock->write_wait.data; @@ -1087,7 +1106,7 @@ thr_multi_lock(THR_LOCK_DATA **data, uint count, THR_LOCK_OWNER *owner) /* lock everything */ for (pos=data,end=data+count; pos < end ; pos++) { - enum enum_thr_lock_result result= thr_lock(*pos, owner, (*pos)->type); + enum enum_thr_lock_result result= thr_lock(*pos, owner); if (result != THR_LOCK_SUCCESS) { /* Aborted */ thr_multi_unlock(data,(uint) (pos-data), 0); diff --git a/sql/lock.cc b/sql/lock.cc index 3f9b3a9e18b..57ced99417b 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -195,31 +195,33 @@ int mysql_lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, uint flags, bool *need_reopen) { - TABLE *write_lock_used; MYSQL_LOCK *sql_lock; + TABLE *write_lock_used; + int rc; DBUG_ENTER("mysql_lock_tables(tables)"); *need_reopen= FALSE; + if (mysql_lock_tables_check(thd, tables, count, flags)) - DBUG_RETURN(NULL); + DBUG_RETURN (NULL); - if (!(sql_lock= get_lock_data(thd, tables, count, GET_LOCK_STORE_LOCKS, - &write_lock_used)) || - ! sql_lock->table_count) - DBUG_RETURN(sql_lock); - - if (mysql_lock_tables(thd, sql_lock, write_lock_used != 0, flags, - need_reopen)) + for (;;) { - /* Clear the lock type of all lock data to avoid reusage. */ - reset_lock_data(sql_lock, 1); + if (!(sql_lock= get_lock_data(thd, tables, count, GET_LOCK_STORE_LOCKS, + &write_lock_used)) || + !sql_lock->table_count) + break; + rc= mysql_lock_tables(thd, sql_lock, write_lock_used != 0, flags, + need_reopen); + if (!rc) + break; // Got lock my_free(sql_lock, MYF(0)); - sql_lock= 0; + if (rc > 0) + DBUG_RETURN(0); // Failed } DBUG_RETURN(sql_lock); } - /** Lock a table based on a MYSQL_LOCK structure. @@ -232,120 +234,150 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, @param need_reopen Out parameter, TRUE if some tables were altered or deleted and should be reopened by caller. - @return 0 ok - @return 1 error + @return 0 ok + @return 1 fatal error + @return -1 retry */ -bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, - bool write_lock_used, - uint flags, bool *need_reopen) +int mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, + bool write_lock_used, + uint flags, bool *need_reopen) { + int res= 0; int rc; - bool error= 1; DBUG_ENTER("mysql_lock_tables(sql_lock)"); - *need_reopen= FALSE; - for (;;) + + if (write_lock_used && !(flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK)) { - if (write_lock_used && !(flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK)) - { - if (global_read_lock) - { - /* - Someone has issued LOCK ALL TABLES FOR READ and we want a write lock - Wait until the lock is gone - */ - if (wait_if_global_read_lock(thd, 1, 1)) - break; - if (thd->version != refresh_version) - goto retry; - } - - if (opt_readonly && - !(thd->security_ctx->master_access & SUPER_ACL) && - !thd->slave_thread) - { - /* - Someone has issued SET GLOBAL READ_ONLY=1 and we want a write lock. - We do not wait for READ_ONLY=0, and fail. - */ - my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only"); - break; - } - } - - thd_proc_info(thd, "System lock"); - if (lock_external(thd, sql_lock->table, sql_lock->table_count)) - break; - thd_proc_info(thd, "Table lock"); - /* Copy the lock data array. thr_multi_lock() reorders its contens. */ - memcpy(sql_lock->locks + sql_lock->lock_count, sql_lock->locks, - sql_lock->lock_count * sizeof(*sql_lock->locks)); - /* Lock on the copied half of the lock data array. */ - rc= thr_lock_errno_to_mysql[(int) thr_multi_lock(sql_lock->locks + - sql_lock->lock_count, - sql_lock->lock_count, - thd->lock_id)]; - if (rc) /* Locking failed */ - { - VOID(unlock_external(thd, sql_lock->table, sql_lock->table_count)); - if (rc > 1) - { - /* a timeout or a deadlock */ - my_error(rc, MYF(0)); - break; - } - /* We where aborted and should try again from upper level*/ - thd->some_tables_deleted= 1; - } - else + if (global_read_lock) { /* - Lock worked. Now check that nothing happend while we where waiting - to get the lock that would require us to free it. + Someone has issued LOCK ALL TABLES FOR READ and we want a write lock + Wait until the lock is gone */ - error= 0; - if (!thd->some_tables_deleted || (flags & MYSQL_LOCK_IGNORE_FLUSH)) + if (wait_if_global_read_lock(thd, 1, 1)) { - /* - Table was not signaled for deletion or we don't care if it was. - Return with table as locked. - */ - break; + /* Clear the lock type of all lock data to avoid reusage. */ + reset_lock_data(sql_lock, 1); + DBUG_RETURN(1); // Fatal error } - else if (!thd->open_tables && !(flags & MYSQL_LOCK_NOT_TEMPORARY)) + if (thd->version != refresh_version) { - /* - Only using temporary tables, no need to unlock. - We need the flag as open_tables is not enough to distingush if - we are only using temporary tables for tables used trough - the HANDLER interface. - - We reset some_tables_deleted as it doesn't make sense to have this - one when we are only using temporary tables. - */ - thd->some_tables_deleted=0; - break; + /* Clear the lock type of all lock data to avoid reusage. */ + reset_lock_data(sql_lock, 1); + goto retry; } - /* some table was altered or deleted. reopen tables marked deleted */ - error= 1; - mysql_unlock_tables(thd, sql_lock, 0); } -retry: - if (flags & MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN) + if (opt_readonly && + !(thd->security_ctx->master_access & SUPER_ACL) && + !thd->slave_thread) { - *need_reopen= TRUE; - break; + /* + Someone has issued SET GLOBAL READ_ONLY=1 and we want a write lock. + We do not wait for READ_ONLY=0, and fail. + */ + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only"); + reset_lock_data(sql_lock, 1); + DBUG_RETURN(1); // Fatal error } - if (wait_for_tables(thd)) - break; // Couldn't open tables - reset_lock_data(sql_lock, 0); // Set org locks and retry } + thd_proc_info(thd, "System lock"); + if (lock_external(thd, sql_lock->table, sql_lock->table_count)) + { + /* Clear the lock type of all lock data to avoid reusage. */ + res= 1; // Fatal error + goto end; + } + thd_proc_info(thd, "Table lock"); + DBUG_PRINT("info", ("thd->proc_info %s", thd->proc_info)); + /* Copy the lock data array. thr_multi_lock() reorders its contens. */ + memcpy(sql_lock->locks + sql_lock->lock_count, sql_lock->locks, + sql_lock->lock_count * sizeof(*sql_lock->locks)); + /* Lock on the copied half of the lock data array. */ + rc= thr_lock_errno_to_mysql[(int) thr_multi_lock(sql_lock->locks + + sql_lock->lock_count, + sql_lock->lock_count, + thd->lock_id)]; + if (rc) // Locking failed + { + if (sql_lock->table_count) + VOID(unlock_external(thd, sql_lock->table, sql_lock->table_count)); + + /* + reset_lock_data is required here. If thr_multi_lock fails it + resets lock type for tables, which were locked before (and + including) one that caused error. Lock type for other tables + preserved. + */ + reset_lock_data(sql_lock, 0); + + if (rc > 1) + { + my_error(rc, MYF(0)); + DBUG_RETURN(1); + } + DBUG_ASSERT(rc == 1); // Timeout + thd->some_tables_deleted= 1; // Reopen tables + sql_lock->lock_count= 0; // Locks are already freed + /* Retry */ + } + else + { + /* + Lock worked. Now check that nothing happend while we where waiting + to get the lock that would require us to free it. + */ + if (!thd->some_tables_deleted || (flags & MYSQL_LOCK_IGNORE_FLUSH)) + { + res= 0; + goto end; /* Lock was not aborted. Return to upper level */ + } + if (!thd->open_tables && !(flags & MYSQL_LOCK_NOT_TEMPORARY)) + { + /* + Only using temporary tables, no need to unlock. + We need the flag as open_tables is not enough to distingush if + we are only using temporary tables for tables used trough + the HANDLER interface. + + We reset some_tables_deleted as it doesn't make sense to have this + one when we are only using temporary tables. + */ + thd->some_tables_deleted=0; + goto end; + } + /* Free lock and retry */ + } + + /* some table was altered or deleted. reopen tables marked deleted */ + mysql_unlock_tables(thd, sql_lock, 0); + +retry: + res= -1; // Retry + if (flags & MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN) + { + *need_reopen= TRUE; // Upper level will retry + DBUG_RETURN(1); // Fatal error + } + if (wait_for_tables(thd)) + res= 1; // Couldn't open tables + +end: thd_proc_info(thd, 0); + if (thd->killed) + { + thd->send_kill_message(); + if (res == 0) + mysql_unlock_tables(thd,sql_lock,0); + else + reset_lock_data(sql_lock, 1); + res= 1; // Fatal + } thd->set_time_after_lock(); - DBUG_RETURN(error); + DBUG_RETURN(res); } diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index f49b7a3c851..94b06add2bd 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -2347,9 +2347,9 @@ extern struct st_VioSSLFd * ssl_acceptor_fd; MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count, uint flags, bool *need_reopen); -bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, - bool write_lock_used, - uint flags, bool *need_reopen); +int mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, + bool write_lock_used, + uint flags, bool *need_reopen); /* mysql_lock_tables() and open_table() flags bits */ #define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001 diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 11fd5db2020..95a149741de 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -9606,13 +9606,12 @@ open_performance_schema_table(THD *thd, TABLE_LIST *one_table, else { /* - If error in mysql_lock_tables(), open_ltable doesn't close the - table. Thread kill during mysql_lock_tables() is such error. But - open tables cannot be accepted when restoring the open tables - state. + This can happen during a thd->kill or while we are trying to log + data for a stored procedure/trigger and someone causes the table + to be flushed (for example by creating a new trigger for the + table) */ - if (thd->killed) - close_thread_tables(thd); + close_thread_tables(thd); thd->restore_backup_open_tables_state(backup); } diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index d789957ffa4..4f1c63930d6 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -676,7 +676,7 @@ retry: /* save open_tables state */ if (handler->lock->lock_count > 0) { - bool lock_error; + int lock_error; handler->lock->locks[0]->type= handler->lock->locks[0]->org_type; lock_error= mysql_lock_tables(thd, handler->lock, 0, From d395d2514d872bc40374e900979825f81f992890 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 23 Feb 2012 16:51:58 +0200 Subject: [PATCH 42/45] Fixes for make_binary_distribution and mysql_config for OpenSuse 12.1 BUILD/SETUP.sh: By default, build also with innodb-plugin mysql-test/mysql-test-run.pl: Also search in lib64 directory for plugins (This is used at least on OpenSuse 12.1 when using default build scripts) mysql-test/r/lock_multi.result: Allow test to be re-run even if it crashed. mysql-test/t/lock_multi.test: Allow test to be re-run even if it crashed. scripts/make_binary_distribution.sh: Ensure that libexecdir is named libexec (was not on OpenSuse 12.1) scripts/mysql_config.sh: Fixed detection of lib64 was used. --- BUILD/SETUP.sh | 2 +- mysql-test/mysql-test-run.pl | 3 ++- mysql-test/r/lock_multi.result | 1 + mysql-test/t/lock_multi.test | 1 + scripts/make_binary_distribution.sh | 6 +++++- scripts/mysql_config.sh | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/BUILD/SETUP.sh b/BUILD/SETUP.sh index c254304a5a8..c1a05fb1007 100755 --- a/BUILD/SETUP.sh +++ b/BUILD/SETUP.sh @@ -178,7 +178,7 @@ base_configs="--prefix=$prefix --enable-assembler " base_configs="$base_configs --with-extra-charsets=complex " base_configs="$base_configs --enable-thread-safe-client " base_configs="$base_configs --with-big-tables" -base_configs="$base_configs --with-plugin-aria --with-aria-tmp-tables --without-plugin-innodb_plugin" +base_configs="$base_configs --with-plugin-aria --with-aria-tmp-tables" # Compile our client programs with static libraries to allow them to be moved base_configs="$base_configs --with-mysqld-ldflags=-static --with-client-ldflags=-static" diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 4d6269044c1..e6ef03d6ad5 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2518,7 +2518,8 @@ sub setup_vardir() { else { # hm, what paths work for debs and for rpms ? - for (<$bindir/lib/mysql/plugin/*.so>, + for (<$bindir/lib64/mysql/plugin/*.so>, + <$bindir/lib/mysql/plugin/*.so>, <$bindir/lib/plugin/*.dll>) { my $pname=basename($_); diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index 3fc4de3da06..72f4b22b06a 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -1,4 +1,5 @@ drop table if exists t1,t2; +drop DATABASE if exists mysqltest_1; create table t1(n int); insert into t1 values (1); lock tables t1 write; diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index f05821af5a8..044af931489 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -5,6 +5,7 @@ --disable_warnings drop table if exists t1,t2; +drop DATABASE if exists mysqltest_1; --enable_warnings # Test to see if select will get the lock ahead of low priority update diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh index 789f3e3ce2e..070b396a34c 100644 --- a/scripts/make_binary_distribution.sh +++ b/scripts/make_binary_distribution.sh @@ -285,7 +285,8 @@ if [ x"$BASE_SYSTEM" != x"netware" ] ; then pkgplugindir=@pkgplugindir@ \ pkgsuppdir=@pkgsuppdir@ \ mandir=@mandir@ \ - infodir=@infodir@ + infodir=@infodir@ \ + libexecdir=@prefix@/libexec # ---------------------------------------------------------------------- # Rename top directory, and set DEST to the new directory @@ -301,7 +302,10 @@ if [ x"$BASE_SYSTEM" != x"netware" ] ; then if [ -z "$gcclib" ] ; then echo "Warning: Compiler doesn't tell libgcc.a!" elif [ -f "$gcclib" ] ; then + { + mkdir -p $DEST/lib $CP $gcclib $DEST/lib/libmygcc.a + } else echo "Warning: Compiler result '$gcclib' not found / no file!" fi diff --git a/scripts/mysql_config.sh b/scripts/mysql_config.sh index f1d46c0b2c0..ce61c09aa15 100644 --- a/scripts/mysql_config.sh +++ b/scripts/mysql_config.sh @@ -86,7 +86,7 @@ bindir='@bindir@' # If installed, search for the compiled in directory first (might be "lib64") pkglibdir='@pkglibdir@' pkglibdir_rel=`echo $pkglibdir | sed -e "s;^$basedir/;;"` -fix_path pkglibdir $pkglibdir_rel lib/mysql lib +fix_path pkglibdir $pkglibdir_rel lib64/mysql lib64 lib/mysql lib plugindir='@pkgplugindir@' From c068b831aca6334c6dea01fd9ff54b6140a52ef6 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 24 Feb 2012 12:34:47 +0200 Subject: [PATCH 43/45] Removed const declarations to get rid of compiler warnings. The changes are similar to what is done in innobase in MySQL 5.5 --- storage/innodb_plugin/btr/btr0sea.c | 2 +- storage/innodb_plugin/ha/ha0ha.c | 6 +++--- storage/innodb_plugin/include/ha0ha.h | 10 +++++----- storage/innodb_plugin/include/ha0ha.ic | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/storage/innodb_plugin/btr/btr0sea.c b/storage/innodb_plugin/btr/btr0sea.c index 04c273344f3..f10c207b76a 100644 --- a/storage/innodb_plugin/btr/btr0sea.c +++ b/storage/innodb_plugin/btr/btr0sea.c @@ -524,7 +524,7 @@ btr_search_update_hash_ref( { dict_index_t* index; ulint fold; - const rec_t* rec; + rec_t* rec; ut_ad(cursor->flag == BTR_CUR_HASH_FAIL); #ifdef UNIV_SYNC_DEBUG diff --git a/storage/innodb_plugin/ha/ha0ha.c b/storage/innodb_plugin/ha/ha0ha.c index 65046138275..594a10dc431 100644 --- a/storage/innodb_plugin/ha/ha0ha.c +++ b/storage/innodb_plugin/ha/ha0ha.c @@ -106,7 +106,7 @@ ha_insert_for_fold_func( #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* block, /*!< in: buffer block containing the data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* data) /*!< in: data, must not be NULL */ + rec_t* data) /*!< in: data, must not be NULL */ { hash_cell_t* cell; ha_node_t* node; @@ -238,11 +238,11 @@ ha_search_and_update_if_found_func( /*===============================*/ hash_table_t* table, /*!< in/out: hash table */ ulint fold, /*!< in: folded value of the searched data */ - const rec_t* data, /*!< in: pointer to the data */ + rec_t* data, /*!< in: pointer to the data */ #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* new_block,/*!< in: block containing new_data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* new_data)/*!< in: new pointer to the data */ + rec_t* new_data)/*!< in: new pointer to the data */ { ha_node_t* node; diff --git a/storage/innodb_plugin/include/ha0ha.h b/storage/innodb_plugin/include/ha0ha.h index 8bba564d153..83a7394123f 100644 --- a/storage/innodb_plugin/include/ha0ha.h +++ b/storage/innodb_plugin/include/ha0ha.h @@ -38,7 +38,7 @@ Looks for an element in a hash table. @return pointer to the data of the first hash table node in chain having the fold number, NULL if not found */ UNIV_INLINE -const rec_t* +rec_t* ha_search_and_get_data( /*===================*/ hash_table_t* table, /*!< in: hash table */ @@ -52,11 +52,11 @@ ha_search_and_update_if_found_func( /*===============================*/ hash_table_t* table, /*!< in/out: hash table */ ulint fold, /*!< in: folded value of the searched data */ - const rec_t* data, /*!< in: pointer to the data */ + rec_t* data, /*!< in: pointer to the data */ #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* new_block,/*!< in: block containing new_data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* new_data);/*!< in: new pointer to the data */ + rec_t* new_data);/*!< in: new pointer to the data */ #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG /** Looks for an element when we know the pointer to the data and @@ -131,7 +131,7 @@ ha_insert_for_fold_func( #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* block, /*!< in: buffer block containing the data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* data); /*!< in: data, must not be NULL */ + rec_t* data); /*!< in: data, must not be NULL */ #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG /** @@ -210,7 +210,7 @@ struct ha_node_struct { #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* block; /*!< buffer block containing the data, or NULL */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* data; /*!< pointer to the data */ + rec_t* data; /*!< pointer to the data */ ulint fold; /*!< fold value for the data */ }; diff --git a/storage/innodb_plugin/include/ha0ha.ic b/storage/innodb_plugin/include/ha0ha.ic index 5656e9b7eba..aec28398b5d 100644 --- a/storage/innodb_plugin/include/ha0ha.ic +++ b/storage/innodb_plugin/include/ha0ha.ic @@ -58,7 +58,7 @@ ha_node_set_data_func( #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* block, /*!< in: buffer block containing the data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* data) /*!< in: pointer to the data */ + rec_t* data) /*!< in: pointer to the data */ { #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG node->block = block; @@ -111,7 +111,7 @@ Looks for an element in a hash table. @return pointer to the data of the first hash table node in chain having the fold number, NULL if not found */ UNIV_INLINE -const rec_t* +rec_t* ha_search_and_get_data( /*===================*/ hash_table_t* table, /*!< in: hash table */ From 1df16a171bdaebee867a4462448a22e251718503 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sat, 25 Feb 2012 16:13:24 +0100 Subject: [PATCH 44/45] make the test result independent from sizeof(void*) --- mysql-test/r/myisam_mrr.result | 6 +++--- mysql-test/t/myisam_mrr.test | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/myisam_mrr.result b/mysql-test/r/myisam_mrr.result index 0da0f8fd5eb..d4b25f25d40 100644 --- a/mysql-test/r/myisam_mrr.result +++ b/mysql-test/r/myisam_mrr.result @@ -628,9 +628,9 @@ sum(t1.b) 1230 show status like 'handler_mrr%'; Variable_name Value -Handler_mrr_init 2 -Handler_mrr_key_refills 3 -Handler_mrr_rowid_refills 3 +Handler_mrr_init ok +Handler_mrr_key_refills ok +Handler_mrr_rowid_refills ok set join_cache_level= @join_cache_level_save; set join_buffer_size= @join_buffer_size_save; drop table t0, t1; diff --git a/mysql-test/t/myisam_mrr.test b/mysql-test/t/myisam_mrr.test index 0f916299ae7..b15fdf60ce7 100644 --- a/mysql-test/t/myisam_mrr.test +++ b/mysql-test/t/myisam_mrr.test @@ -313,6 +313,8 @@ set join_buffer_size=10; explain select sum(t1.b) from t0,t1 where t0.a=t1.a; flush status; select sum(t1.b) from t0,t1 where t0.a=t1.a; +# the values below depend on sizeof(void*) +--replace_result 1 ok 2 ok 3 ok show status like 'handler_mrr%'; set join_cache_level= @join_cache_level_save; From 3ebb4b883370da9528b7482b8ba4ed9521f07553 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 27 Feb 2012 19:20:18 +0100 Subject: [PATCH 45/45] because of the high cost associated with fake symdir resolution, disable symbolic-links on Windows by default. Real symlinks (Vista+) as well as NTFS junctions (prior to Vista) do not require this parameter --- cmake/ssl.cmake | 2 ++ mysys/my_access.c | 16 +++++----------- sql/mysqld.cc | 4 +++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index 001be69e62f..b5b94310d29 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -69,8 +69,10 @@ MACRO (MYSQL_CHECK_SSL) FIND_LIBRARY(CRYPTO_LIBRARY crypto) MARK_AS_ADVANCED(CRYPTO_LIBRARY) INCLUDE(CheckSymbolExists) + SET(CMAKE_REQUIRED_INCLUDES ${OPENSSL_INCLUDE_DIR}) CHECK_SYMBOL_EXISTS(SHA512_DIGEST_LENGTH "openssl/sha.h" HAVE_SHA512_DIGEST_LENGTH) + SET(CMAKE_REQUIRED_INCLUDES) IF(OPENSSL_FOUND AND CRYPTO_LIBRARY AND HAVE_SHA512_DIGEST_LENGTH) SET(SSL_SOURCES "") SET(SSL_LIBRARIES ${OPENSSL_LIBRARIES} ${CRYPTO_LIBRARY}) diff --git a/mysys/my_access.c b/mysys/my_access.c index 210946d50a8..d7d06f814d6 100644 --- a/mysys/my_access.c +++ b/mysys/my_access.c @@ -26,11 +26,6 @@ path Path to file amode Access method - DESCRIPTION - This function wraps the normal access method because the access - available in MSVCRT> +reports that filenames such as LPT1 and - COM1 are valid (they are but should not be so for us). - RETURN VALUES 0 ok -1 error (We use -1 as my_access is mapped to access on other platforms) @@ -38,12 +33,11 @@ int my_access(const char *path, int amode) { - WIN32_FILE_ATTRIBUTE_DATA fileinfo; - BOOL result; - - result= GetFileAttributesEx(path, GetFileExInfoStandard, &fileinfo); - if (! result || - (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) && (amode & W_OK)) + DWORD attributes; + + attributes = GetFileAttributes(path); + if (attributes == INVALID_FILE_ATTRIBUTES || + (attributes & FILE_ATTRIBUTE_READONLY) && (amode & W_OK)) { my_errno= errno= EACCES; return -1; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6a5de0b82cb..a5b0c462a63 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -6334,8 +6334,10 @@ struct my_option my_long_options[]= The system call realpath() produces warnings under valgrind and purify. These are not suppressed: instead we disable symlinks option if compiled with valgrind support. + Also disable by default on Windows, due to high overhead for checking .sym + files. */ - IF_VALGRIND(0,1), 0, 0, 0, 0, 0}, + IF_VALGRIND(0,IF_WIN(0,1)), 0, 0, 0, 0, 0}, {"debug-no-sync", 0, "Disables system sync calls. Only for running tests or debugging!", &my_disable_sync, &my_disable_sync, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},